OpenHab Wall Switch

So recently I started thinking about my HA system when I have guests.  I have a small house (not a tiny house) just a small house.  When my parents visit they setup camp in the living room.

vYtvpWpWorking on getting PIR motion sensors to turn things on and off.  But with guests, I need a guest mode to disable the motion sensor…. and not because I tend to dance in front of the motion sensors.

 

 

89b1c00006954836a703dfc0457c8626But with the motion sensors disabled.  There still needs to be a way for the folks to control the lights.  So I started thinking.

What I came up with was physical buttons, pass something to mqtt, then to openhab.  Openhab rule to control “group” of lights aka living room.

So time to start proto typing some things.  First I wanted to see if I could somehow make it work without putting holes in the wall.   WAF = 10 on that one.

2016-06-12 17.31.52So I started by 3d printing a light switch blank panel.  It’s a rough print, but needed to see if I could make it deep enough to put some triple A batteries to run it.

Once I tested some depth I was happy.

Frank-GrimesNext to build build some electronics.

 

So I broke out the good old arduino uno.  This is my go to for initial builds even though I usually end up with a pro mini in the end.  The uno is a great test bed.

So it started out with Uno + Ethernet Sheild + 2 buttons.

2016-06-12 12.53.39-2

 

I ended up adding just a notifcation LED just so I know once it’s connected to MQTT since I am not watching via serial monitor now.   2016-06-12 17.34.42So what does this get us now?  Well.  It boots up.  You press one button, all the lights in the living room turn on.  Press the other and they turn off.  I know what you’re thinking.  So what?

One of the lights is a phillip hue light.  The other is controlled via z-wave.  So how did I do this.  Lets start with the item definitions in openhab.

//Group Definition
Group gLivingRoomLights

//Items
Switch Switch_LivingRoomStandingLight "Living Room Light"     <light> (gLivingRoomLights,gDashboard) { zwave="2:command=switch_binary" }
Switch LivingRoomTableLight   "Living bulb" (gLivingRoomLights,Switching) {hue="1"}

//Dummy ITEM that is set via mqtt
Switch LivingRoomLights "Living Room Lights" {mqtt="<[mqtt:switches/livingroomlights:state:default]"}

So in my items file, I have the 2 light items and a dummy switch.  Notice the 2 light items are in the “gLivingRoomLights” group.  This is important.

Now for the rules.


rule "Living Room Lights"

when
Item LivingRoomLights changed
then
if(LivingRoomLights.state==ON)
{
gLivingRoomLights.sendCommand(ON)
logInfo("All Living Room Lights","ON")
}
else
{
logInfo("All Living Room Lights","OFF")
gLivingRoomLights.sendCommand(OFF)
//off
}
end

So this rule is triggered when the Dummy Switch (LivingRoomLights) changes.  If the state was changed to ON then i send the “ON” command to the entire group.  Same for when I turn it off.  So to test it I used mqtt-spy and manually did it.  All is working.

k16232506

What’s next is I am going to work on shrinking said project down to using an arduino pro mini, 2 AAA batteries.  For the network transmission I am back and forth between 2 options.

  1.  esp8266 – using the esp is great, but it’s not very forgiving on power.   I know there are deep sleep modes, but they aren’t really good for what I need with multiple buttons.
  2. nrf24l01 – RF modules.  These little suckers are really easy on the power.  If I use these I have to build a rf->ethernet bridge.  But with these I think the power consumption is much simpler.

Either option I go with, I can use a pro mini and have 2 interrupts I can attach to buttons.

Down the road if I need more buttons, I can use a pro micro and get something like 14 interrupts and still be able to use deep sleep.

iphone-battery-iconIf I wanted to cut holes in the wall and run cable I wouldn’t be as concerned with the battery levels.

 

 

 

Want to see it being tested?

 

 

Find my Sh*T!!! – The lost iphone saga

Ok, we have all done it.  Where the hell is my phone?  Where’s the ipad?   Home alone trying to find it and you have no way of calling it because, well, no land line.

 

A week or so ago I finally replaced my Jurassic period thermostat with something a little newer.  I know, weird right.  I do all this stuff and I had a thermostat that was 1 step above this

old_honeywell_t87

So I got a 2gig CT100 with z-wave.
61cUaIUZOLL._SL1024_

 

 

55553046So as any self respecting geek would do.  As soon as I got it hooked up, I tied it in to my home automation system.

 

So I have basic items configured, mainly so I can see the temps ect.  But there is another thing we can do with this.  Got the idea from the thread

https://community.openhab.org/t/find-my-iphone-from-my-nest/5663

If you look you will see I have contributed and written a simple php service for finding an iphone 🙂

Here is the github for that simple php service https://github.com/brunkj/FindMyIphonePHPService
So I have my PHP service setup.  I have my home automation system.  I have my z-wave thermostat.  I have rythm.  I have style..  $%^& what’s wrong with me…..

So I created a simple rule


rule "Find iPhone via thermostat"
  when
    Item HVAC_CoolSetPoint changed to 69
  then
    sendHttpGetRequest("http://xx.xx.xx.xx/findmyiphone/?phone=jason")
    sendCommand(HVAC_CoolSetPoint, 75)
  end

 

Simple description.  Set the thermostat to 69.. hehe hehe 69….  {giggle} 61832143

 

 

 

 

 

 

 

 

Ok, I’m better.  Set to 69.  Openhab sees it’s now set to 69, realizes that’s way out of character and runs the rule “Find iPhone via thermostat” which sends the call to my php service, then sets the temp back to our standard 75.

I am implementing 1 additional rule for 68 degrees for the wife’s phone.

Whole Home Audio Rig

So a while back (let’s not talk about how long ago) I found the site of HazyMat

Multi-zone audio: a discussion of the options

He seemed to have found a great solution for doing some work on whole home audio.  This is something I have been trying to find a good solution for myself.

I decided to test this out myself using the XAP 800.  xap800_l

 

 

 

maxresdefaultI picked this thing up on ebay for $24 bucks.  So I did some testing and was able to do some audio routing via serial port which means I can use Openhab to control the audio matrix.  Not the same matrix.  But as I have shown before, the connectors might be a pain in the butt to try to wire everything up.

ClearOne XAP-800 Professional Audio Conferencing System Pic 4

Screw down terminals are great but not convenient if you have it mounted in a rack.  Which is what I wanted to do with mine.

So how do we make this better?  A patch panel!!!
19-inch_rackmount_Ethernet_switches_and_patch_panels

So I started looking around.  I could do a keystone jack patch panel.  But then doing rca keystone jacks were going to be way more expensive than I wanted to spend.  $24 bucks for the audio rig and Im looking at $100 bucks for the patch panel….. NOPE!

So here is what I decided to do.  Use a 2u blank rack plate.  Like this one.  72621Buddy 069of mine had one laying around.  So far $0.  I know what you are thinking.  “Hey genius you don’t have any holes…..”

 

I know.  I got it.  Relax.  I busted out the blue painters tape and made some markings for the holes.  IMG_0678

 

Now off to the drill press.  Few drillings later we have swiss cheese!!

IMG_0679Had a super cheap pack of RCA jacks show up.

81DOZmuhh9L._SL1500_
Initially I was planning on doing all my cable management through the middle, so I had red on top and black on the bottom.  But then because I had the top and IMG_0687bottom row offset from each other it didn’t make sense.  So I ended up swapping them around.  I then soldered speaker wire to the back of each jack.  It took a while, but it was worth it.  Wired up to the screw terminals I now had a nice pretty panel.

IMG_0937

 

So I wanted to get things labelled up.  But my label maker is junk.  The sticky tape just falls off.  So I could paint.  But then it looks messy.  So then it hit me.  Vinyl!!!

I was able to pick up a craft cutter for super cheap (<$35) and designed up some labels, ordered some white vinyl.

CUT!!!

IMG_0939A little transfer paper and a crooked eye and I now have some much nicer labels.

IMG_0943

 

Now it’s all mounted up in my rack nice and pretty.  I have my main computer in my office routed through the device as an input source, and then my main speakers as an output.  Then a media center raspberry pi routed as another input.  It’s now mixed with the audio from my main computer.  Both computers using the same speakers.

 

Is it hot in here? Home Automation AC addition

So my Super Villain lair is super secretly located in my converted garage… shhhh.

So we found out that Florida is a rough place to be a super villain.  It’s hot here.  So I needed a way to help keep my lair cool.  So many full moons ago my minions held a Staples store for ransom till they gave me an AC unit.
lx_140_set

 

This thing is huge.  It’s a 14000 BTU unit.  I have an exhaust vent that goes up through the ceiling and vents outside.  It is actually pretty good at cooling down my lair.  But it is another AC unit that can use up some power.  Since the Super-Wife is not a fan of paying giant power bills, I have to turn it off when I am not in the office.  This was one reason thy the remote was very handy.  But.  It’s 2016.  Hello!  Just a remote?  That’s it?  HA! Right!

I have worked on trying to automate this thing for awhile.  A while back I used the Arduino Infrared Library to read codes from the remote, and then blast them back out.  But it didn’t work… I thought maybe it was using revolving codes.  Nope.

As it turns out, HVAC units have a tendency with their remotes to not send simple codes like “On”, “Heat”, “Fan-High”, “Temp-Up”  as you might think.  TV’s and even some small wall mounts use basic NEC hex codes.  Not this monstrosity.  No no.  After working on this thing for weeks I found an article that spoke about maybe my buffer size for reading the code wasn’t large enough.  The current RecvBuff was set to 100.  I was filling up all 100 locations.

So I changed it in the IRRemoteInt.h file.  Set it WAY higher.  Turns out my remote was sending 228 pulses.

client-pulse

 

So I decided to try to decode some stuff.  Lets try changing the temp.  228 pulses and most of them are the same.  Turns out my HVAC remote sends FULL state code every time you push a button.  To test this theory.  I set my HVAC to 72 degrees.  Went into a different room with the remote, pressed temp up until I was at 74 degrees.  Back in the office, the display still says 72, remote says 74.  I press up, the HVAC screen jumps straight to 75.  Full state!!  So that’s good to know, but a pain in the ass as I would have to do some SERIOUS work to decode the blocks and find out what changes to what.  But I never really need to do anything other than turn it on and off.  So lets find something simple.

I now have the following arrays of values


unsigned int powerOn[227] = {3400,1700, 450,1250, 450,1300, 450,450, 400,450, 450,450, 450,1250, 450,450, 450,450, 400,1300, 450,1250, 450,450, 450,1250, 450,450, 450,450, 400,1300, 450,1250, 450,450, 450,1250, 450,1300, 450,450, 400,450, 450,1300, 400,450, 450,450, 450,1250, 450,450, 450,450, 400,450, 450,450, 450,450, 400,450, 450,450, 450,450, 450,450, 400,450, 450,450, 450,450, 400,450, 450,450, 450,450, 400,450, 450,450, 450,1250, 450,450, 450,450, 450,1250, 450,450, 450,450, 400,1300, 450,1250, 500,400, 450,450, 400,450, 450,450, 450,450, 450,400, 450,1300, 450,1250, 450,450, 450,1250, 450,450, 450,450, 400,450, 450,1300, 400,450, 450,450, 450,450, 450,1250, 450,1250, 450,1300, 400,500, 400,450, 450,450, 450,450, 400,450, 450,450, 450,450, 400,450, 450,450, 450,450, 450,400, 450,450, 450,450, 400,500, 400,450, 450,450, 450,450, 400,450, 450,450, 450,450, 450,400, 450,450, 450,450, 450,450, 400,450, 450,450, 450,450, 400,450, 450,450, 450,450, 400,450, 450,450, 450,450, 500,400, 400,1300, 450,1250, 450,1300, 400,1300, 450,1250, 450,1300, 400,1300, 450,1250, 500}; // UNKNOWN 3659AD56
unsigned int powerOff[227] = {3400,1700, 450,1250, 450,1300, 400,450, 450,450, 500,400, 450,1250, 450,450, 500,400, 400,1300, 450,1250, 450,450, 450,1250, 450,450, 450,450, 500,1200, 450,1250, 450,450, 450,1250, 450,1300, 400,450, 450,450, 450,1250, 450,450, 500,400, 500,1200, 450,450, 400,450, 450,450, 450,450, 450,450, 450,400, 450,450, 450,450, 400,450, 450,450, 450,450, 400,450, 450,450, 450,450, 400,450, 450,450, 450,450, 450,450, 400,450, 450,450, 450,1250, 450,450, 450,450, 400,1300, 450,1250, 450,450, 450,450, 450,400, 450,450, 450,450, 400,450, 450,1300, 450,1250, 450,450, 450,1250, 450,450, 450,450, 400,450, 450,1300, 400,450, 450,450, 450,450, 400,1300, 450,1250, 450,1300, 400,450, 450,450, 450,450, 450,450, 400,450, 450,450, 450,450, 400,450, 450,450, 450,450, 400,450, 450,450, 450,450, 400,500, 400,450, 450,450, 450,450, 400,450, 450,450, 450,450, 400,450, 450,450, 450,450, 400,450, 450,450, 450,450, 450,400, 450,500, 400,450, 450,450, 400,450, 450,450, 450,450, 400,450, 450,1300, 400,1300, 450,450, 450,1250, 450,1250, 450,1300, 400,1300, 450,1250, 450}; // UNKNOWN 6BF20402

243448-Don-t-Judge-Me.-I-Was-Born-To-Be-Awesome.-Not-PerfectWith those values set in my arduino code I can now turn my AC ON and OFF in my office.  Cool haha, get it?  cool?  Shut up.  Don’t judge me.

 

 

 

 

So I did that work, and that was the end of it.  I didn’t really do anything more with it.  I wanted to figure out a good way of interfacing to it.  Earlier this week I found the following article on the OpenHab community.

MQTT IR transmiter/receiver

This turned out to be just what I needed.   I didn’t even realize I needed this, but it made perfect sense.  In short, use a tiny esp8266 chip with an IR LED and MQTT.

You can get them even cheaper from China.

AliExpress.com Product – 2015 New version 1PCS ESP8266 serial WIFI model ESP-01 Authenticity Guaranteed,Internet of things $1.79 Each.

arduino_dust_sensor_ESP8266-1I had one already laying around…. but where the hell is that tiny bastard!?!?!?!

Like finding a needle in an electronic haystack.  But I found it.

 

 

Threw in the code, built a programming jig for it.  Programmed it and BOOM!!! MQTT messages turning on my AC.  Nice!!!

069But that’s not home automation genius!

I know!

I’m getting there.  Geeze!!! Some freaking people am I right?

So time to hook this up in OpenHab.  I already have an MQTT broker configure in OpenHab for my OwnTracks setup.  So we need an Item created first.  So I setup a new Items file called “HVAC.items”


Switch Office_ac "Office AC" {mqtt="&gt;[mqtt-home:esp8266/02/sender/RAW:command:ON:ON],&gt;[mqtt-home:esp8266/02/sender/RAW:command:OFF:OFF]"}

Next let’s add to the sitemap.


Switch item=Office_ac

f1afa6d8e96b6f69bb5c73776177af24Try to keep up, I know it’s crazy difficult with all those configs and what not..  I need a drink.

Sweet.  Now I have a simple on/off switch for my AC.

……still just a remote jackass.

Really..

 

Really…..

1234931504682 (1)

 

 

 

 

C’mon.  Can’t we be friends?

I mean, you can be pinkie pie.

FANMADE_Pinkie_Pie_and_Rarity_friends_forever

Ok cool.

So for the AUTOMATION part, (I’m not bitter), we create a new rules file.  HVAC.rules


rule "Turn On AC"
when
Time cron "0 17 15 * * ?"
then
Office_ac.sendCommand(ON)
end
rule "Turn off AC"
when
Time cron "0 30 22 * * ?"
then
Office_ac.sendCommand(OFF)
end

So now, each evening around the time I start my crazy battle with traffic home (see here), my AC in my office will turn on then turn off each evening at 10:30.

So where do I go from here?  Well, the next step is to use my previously mentioned OwnTracks setup to see precisely when I leave from work and if I pass through a location which indicates my trip home, it will turn on the AC.  This way, it doesn’t matter if I leave work early or late, my AC will know and have an hour to cool down the Lair before I get home.

 

baby-its-cold-outside-14192655214ng8k

 

 

 

 

 

 

 

 

Traffic (actual cars) Woes

So in the last 2 weeks I have been put to the test of patience and road rage.

giphy

Last week there was a guy that decided to take his dog for a walk on the over pass and decided to stop and contemplate jumping.  This closed down a 3 lane highway and the 2 joining lanes completely in morning rush hour.  Diverted traffic was diverted to a 1 lane exit.  I sat in traffic for 3.5 hours!!!! At that point I called the office and said “i’m working from home, it will take me hours to get there and 30 minutes to get home.”

That was pretty rough.

This past week was obviously not as bad.  But 4 out of 5 days this week my normally 45-50 minute commute was 90 minutes.

So normally I spend 4hrs 10min on the road commuting in the morning and roughly 5 hours in the evenings (traffic gets worse)

But this week was almost 7 hours in the morning and 5 in the evening.

12 hours……

I don’t think you heard…. 12 HOURS!!!!! Just driving!!! It’s stupid.

traffic-zzz

 

Man I could get a lot of work done driving a tesla!

 

 

 

So I had this dream this week, very strange I know, and some of the details I am omitting here because well… some of it was quite sexy…. but that’s not the part I am hiding.  There was another device in my dream that I have thought about making before and in my dream I had it done.  But it had a new feature…. it told me if my drive to work was going to be longer than usual……

I know I know.  “Just watch the news you jackass!”  I can hear you all saying that.  However I cut the cable many many many moons ago.  I don’t get the news.  Two.  Well, my past brain problems have led me to a life where I don’t watch the news often because the news is generally bad and I find myself a much happier well adjusted member of society if I don’t watch the news in the morning.  But I got side tracked.

So after the wife telling me
Untitled

I decided to look into this thing that my brain was hinting at.  So I spent some time looking for mapping/navigation api’s.  I found out that TomTom has one.  Pretty good to, you can tell it what kind of vehicle you have, and if you want traffic to be taken in to account and all kinds of stuff.  So I got an api key and started coding against it.  Pretty neat.  68747470733a2f2f646c2e64726f70626f7875736572636f6e74656e742e636f6d2f752f343034323534372f746f6d746f6d2e706e67

But then I found this.  This turned out to be pretty interesting by itself since I currently use a dashing dashboard for a few things internally.

I set it up for myself in dashing and it works nicely.  So we are close, but not quite what I am looking for.

So I decided to keep working, and thinking, and eating chips.

Wait.  No chips.  Just working and thinking.

I decided what I needed was 2 fold.

  1.  Traffic time must be in my Home Automation system so I can create rules based on the time.
  2. The times must be stored somewhere so I can get a new idea of “average” drive time.

I got it.  Create an item in Openhab.  Update said item periodically.  I already have openhab mysql persistance enabled.  This will work.  I will be able to run data reports based on time of day (aka MORNING during the week) and see what the average/no accident drive time is and over time even see how much time an accident add’s to my trip on average.

So now in my openhab I have the following ITEM configured in my home.items file.

Number WorkDriveTime "Drive Time [%s minutes]"

and in my home.sitemap file

 Text item=WorkDriveTime

I have a cronjob that runs every 5 minutes that just fires off a php file to get the tomtom info, convert seconds to minutes, round it off and update openhab.

My simple php file is here.


<?php
$string = file_get_contents("https://api.tomtom.com/routing/1/calculateRoute/28.3852,-81.5639:33.8121,-117.9190/json?routeType=fastest&traffic=true&travelMode=car&key=YOURAPIKEY");
$json = json_decode($string, true);


$DriveTime = round($json["routes"][0]["summary"]["travelTimeInSeconds"]/60);

if ($DriveTime != 0) {
sendOpenHabUpdate("WorkDriveTime",$DriveTime);
}


function sendOpenHabUpdate($item, $data) {
 $openhabserver = "http://192.168.2.90:8080/rest/items/" . $item;
$options = array(
'http' => array(
'header' => "Content-type: text/plain\r\n",
'method' => 'POST',
'content' => (string)$data,
),
);

$context = stream_context_create($options);
$result = file_get_contents($openhabserver, false, $context);

return $result;
}


So with this now running in my crontab I have my database slowly updating with drive times.

Oh. If you want to get a key for TomTom yourself just go to http://developer.tomtom.com/

So what do I have in store for this. Well, there is another value that comes back in this specifically related to “delay from traffic” so I may add this in as another number item to track. But the plan is to know before I leave the house if I should take a regular coffee or a giant coffee to get me through the morning commute. download

OpenHab crashing with Z-Wave FIX IT FIX IT FIX IT FIX IT!!

So,  my openhab system periodically decides to leave the building.  Appears there is a problem from time to time when the z-wave binding loses communication to the z-wave stick it gets upset and tells openhab to take a hike.

This is bad.  Once because it exposed something I missed in my fault tolerance.   I had compensated for network issues and full machine failover.  But the actual process going belly up…. ooops.  My Bad.

Soooo I see it crash while at the gym today and the only thing in my head….

gSHIj

So I appear to have done that.

Let me bring you up to speed on the current state of my home automation.  After the great NAS failing of 2015 I was forced to reduce some of my virtual environment.   I have not brought my secondary HA controller back online yet.  However, it appears that still using keepalived I am able to help address this random problem.

I have added in a new option in my keepalived.conf

 


vrrp_script chk_hahealth {
    script "/usr/local/sbin/healthcheck.sh"
    interval 10 # check every 10 seconds
    fall 2 # require 2 failures for KO
    rise 2 # require 2 successes for OK
}

vrrp_instance VI_1 {
   state MASTER
   interface eth0
   virtual_router_id 220
   priority 150
   notify /usr/local/sbin/notify-keepalived.sh
   advert_int 1
   authentication {
        auth_type PASS
        auth_pass fakepass
   }

   virtual_ipaddress {
      192.168.2.90
   }
   track_script {
     chk_hahealth
   }
}

So what this does is add a keepalived health check.   Every 10 seconds keepalived runs the script /usr/local/sbin/healthcheck.sh and gets an exit code of 0 or 1.  0 if all is good.  1 if the world fell apart.

Environmental concept. Some images in montage provided by NASA (http://visibleearth.nasa.gov/)

The code for this script is


#!/bin/sh
SERVICE=openhab;

if ps ax | grep -v grep | grep $SERVICE &amp;gt; /dev/null
then
 echo "$SERVICE service running, everything is fine"
 /usr/bin/logger "$SERVICE service running, everything is fine"
 exit 0
else
 echo "$SERVICE is not running"
 /usr/bin/logger "$SERVICE is not running"
 /etc/init.d/openhab restart
 exit 1
fi


Explanation:

So this script just checks to see if the openhab process is running.  If its good, exit 0.  If its not, exit 1 but go ahead and try to restart openhab.  When keepalived gets the exit 1 code it keeps track of it.  You will see in the config that there is a fall 2 line.  That means that if there are 2 exit 1 status’s keepalived will go into a failed state.  When the second HA box is back online this will force openhab to move over to the other one.  However, I have not seen this happen so far as openhab loads pretty quick so since there is 10 seconds between the checks the second check comes back with an exit 0 and resets the fall count.

 

 

 

 

Home Automation Quick Update

o since I made the home automation system failover its been great!…. except I kind of would like to know which box its running on it.  So I made a quick change.  A new Item on my dash board

String  Server "Server [%s]" {exec="&lt;[/bin/cat@@/etc/hostname:60000:]"}

I have that in my items file.  Then in my sitemap I added

Text label="Currently Running on [%s]" item=Server

I have that at the bottom of my sitemap.

image

Home Automation Move (part 2)

So, with a friday and a saturday worth of work on my home automation move here is what is complete.

  1. install server os on vm
  2. install openhab and all bindings currently in use
  3. move openhab configs over to new vm
  4. shutdown old openhab-pi
  5. configure raspberry pi with virtualhere server to share usb
  6. configure new vm server to connect to raspberry pi to communicate with z-wave stick
  7. install keepalived on new server
  8. configure virtual ip as my new primary ip for openhab access
  9. configure scripts to run to start openhab and connect to shared usb
  10. clone server to secondary vm for failover
  11. reconfigure keepalived to make second box slave
  12. test failover

So let me show you my keepalived settings and my scripts.

/etc/keepalived/keepalived.conf

vrrp_instance VI_1 {
     state MASTER
     interface eth0
     virtual_router_id 220
     priority 150
     notify /usr/local/sbin/notify-keepalived.sh
     advert_int 1
     authentication {
           auth_type PASS
           auth_pass fakepass
     }
     virtual_ipaddress {
         192.168.2.90
     }
}

 

See the “notify” line?    That script is pretty simple.

#!/bin/bash
TYPE=$1
NAME=$2
STATE=$3
case $STATE in
        "MASTER") sleep 30
                  /usr/local/sbin/usb-connect.sh
                  /usr/sbin/service openhab start;;
        "BACKUP") /usr/sbin/service openhab stop
                  /usr/local/sbin/usb-disconnect.sh;;
        "FAULT")  /usr/sbin/service openhab stop
                  /usr/local/sbin/usb-disconnect.sh
                  exit 0
                  ;;
        *)        /sbin/logger "unknown state"
                  exit 1
                  ;;
esac

 

So what that does it every time there is a keepalived state change it notifies that script.   That script then runs additional scripts based on the state.   So when it goes to “MASTER” or at boot time (which is why i have to put that sleep statement in there) it runs usb-connect.sh.  Which just has a couple commands

/sbin/vhclient &
sleep 10
/sbin/vhclient -t "USE,4294967409"

I’ll walk you through this one.

  1. runs the virtualhere usb client.
  2. waits a few seconds so the client can detect shared usb on the network
  3. sends a command to the running client “-t = command” specifying to “USE” the device with the id “4294967409”

The usb-disconnect.sh is a single line!

pkill vhclient

Thats it.  Just shutdown the client.   So now when the box boots up openhab1 becomes “MASTER” for openhab.  It then executes the scripts to connect to the shared USB.  Then starts openhab.

Once the second box is in place, all the same scripts and all will be put in place with 1 single change.

 

vrrp_instance VI_1 {
     state MASTER
     interface eth0
     virtual_router_id 220
     priority 200
     notify /usr/local/sbin/notify-keepalived.sh
     advert_int 1
     authentication {
           auth_type PASS
           auth_pass fakepass
     }
     virtual_ipaddress {
         192.168.2.90
     }
}

Notice line 5, the priority is a higher number than in openhab1.  This means that when the boxes communicate they will negotiate who gets to be master.   Then either box can start openhab and whoever is running openhab gets the USB z-wave stick.

Home Automation Move (part 1)

I have been running openhab for over a year now on a raspberry pi. I also run mosquitto mqtt broker with a great piece of software called mqttwarn.   On my phone I run owntracks.

FullSizeRender

So lets do a brief summary of what these pieces of software do for me and what I currently have configured.

Openhab – “a vendor and technology agnostic open source automation software for your home.”   That is what the site says openhab is and they are right.   Openhab is a core home automation system that has been designed to work with MANY different vendors and systems to make your home smart.   I have friends that got stuck with z-wave because they spent a bunch of money on z-wave and don’t want to replace it.  But there is also belkin stuff, wifi modules, home built devices (this is a BIG problem for third party controllers.)   Later on in this post you will see that I have used this agnostic approach to home automation to my benefit.

Mosquitto – “is an open source (BSD licensed) message broker that implements the MQ Telemetry Transport protocol versions 3.1 and 3.1.1.”  Okay, not quite as cut and dry as openhab.  So I’ll see if I can help.   MQTT (MQ Telemetry Transport) is a system in which devices and services can connect to a central system and communicate via very small, very efficient messages back and forth.  This efficiency helps in speed and bandwidth.  A device can connect and just wait for commands, a service can send a message to the mqtt server which in turn immediately passes it to the device connected.  MQTT is EXTREMELY more robust, but that is a simple paraphrase description of it.

MQTTWarn – “a pluggable MQTT notifier.”   Hmm, not as helpful, but now that you know what mqtt is you probably understand this a little better.   Jan-Piet Mens, the creator of mqttwarn and a very nice guy (I have personally had experience working with him in trying to accomplish various things) created this wonderful middleman piece of software.  Its almost like grand central station, or your telephone switch board, or the traffic cop.   Its a beautiful thing, I use this personally to do the following.

  • update dashboards in my office with current battery power on a couple devices using owntracks to get the battery data and pushing info to dashing dashboard. 2015-11-13 16_53_22-My super sweet dashboard
  • Show current bandwidth usage from my router (python service I wrote to query snmp data from my router and publish via mqtt and then pushing info to dashing)
    bandwidth
  • Pushing various alerts to prowl/growl
  • Push notices of events to my kodi installations

OwnTracks – “Your location companion.”   OwnTracks is an application that can run on android and IOS devices that uses the internal GPS info and reports back to your mqtt server.  This allows for a little better sense of privacy about our tracking info, but lets be honest if you have your phone on you, you are probably being tracked.  But it doesn’t mean we have to give our info to everyone, so we use our own systems to track us.  This also reports battery info with the location data it sends back to the system.  Why would you want this?  Well I use it to detect when I am home for presence detection.  I also use it to have my home automation system know when I am leaving the office each day.

 

For devices I have integrated, I have..

  • a couple z-wave devices
  • 2 phillips hue lights
  • 2 belkin wemo switches
  • Logitech Media Server (squeezebox server) for media
  • 2 Max2Play raspberry pi setups.
  • 3 Kodi installs
  • 2 mobile devices via owntracks

 

So what am I doing moving this?!?!   Well, this is a good question.  The system does work in its current setup.  However, as every project must, there has to be a very high WAF (Wife Acceptance Factor) if the project should ever be allowed to leave your workspace…  Since I am pushing very hard to start putting some bigger pieces in the rest of the house (home built IR blasters, wall panels, in-ceiling speakers for voice notifications) I needed to increase the WAF.  So, I have found that there are 2 things that make this much easier.

  1. Must be easy to use.  UI is key here, if others in the house can’t use it, its junk.
  2. Must work.   If the wife can’t turn on a light because something is down, its junk.

Those 2 key pieces of info really fit and help.  So UI I believe I already have covered with a nice easy touch interface available on EVERY device in this house including some tangible remotes.   So number 2 is the obstacle to tackle.  It must work.  So redundancy/fault tolerant is key.  I have 2 seperate esxi environments in my setup here at home so I am going to place 2 openhab systems in virtual environment with heartbeat, failover and a virtual IP.  To share the physical z-wave stick I am taking the raspberry pi and using virtualhere to share the 1 USB device with both controllers.  This does still present a single point of failure for z-wave stuff.  But it is not all the system so its better.  If anyone has any thoughts on how to add redundancy to that Im all ears.

So here is what my goal is for my controller setup.

Openhab Layout - New Page (1)