Sunday, December 20, 2015

openHAB Proximity Update

Just a quick update to the proximity tracking. The original post was just using Bluetooth which tends to not be completely reliable. So we need a backup such as WiFi. OpenHAB has a binding that can check for network devices. Between this and the device scan script for BT, we are set.

Just need to add an item for each device you want to track on the network. This can be used to see if a laptop is on or even check to make sure a sensor or something it alive.

Install the NetworkHealth binding - sudo apt-get install openhab-addon-binding-networkhealth

There isn't much in openhab.cfg to figure. I just setup the cache period to 60. Just restart openHAB if you make a change and load it to the new binding.

Items
 
Switch  wifi_Will               "Will Wifi"            (gNetwork)      {nh="Note5"}
Switch  wifi_Jenn               "Jenn Wifi"            (gNetwork)      {nh="Jenn-iPhone"}
 

The devices in the items config can be an IP address or host name. Using the hostname allows you to not have to set a static IP or reservation in DHCP. I already had reservations so these host names are set in the router. It looks like in iOS you can't change the host name but setting it in my router allowed me to control it. Android uses the device name you set in settings.

Sitemap
 
 Group item=gNetwork icon="present"
  

I put both devices in a group and just used that to add it to the sitemap. Then you can easily add more devices to track.

Then just update the occupied rule to take the other items into account.

Rule:
 
rule "Update Presence to home"
when
        Item wifi_Will changed from OFF to ON or
        Item wifi_Jenn changed from OFF to ON or
        Item device_WillPhone changed from OFF to ON or
        Item device_WillPhone changed from OFF to ON
then
        occupiedState.postUpdate(ON)
end


rule "Update Presence to away"
when
        Item wifi_Will changed from ON to OFF or
        Item wifi_Jenn changed from ON to OFF or
        Item device_WillPhone changed from ON to OFF or
        Item device_WillPhone changed from ON to OFF
then
        if(wifi_Will.state==OFF && wifi_Jenn.state==OFF && device_WillPhone.state==OFF && device_JennPhone.state==OFF){
                occupiedState.postUpdate(OFF)
        }
end

 

There is a bug in the rule though, the occuipedState isn't quite working. Everyone leaves and it's still on. So I will need to troubleshoot that a bit more. (Hmm... I noticed I am using postUpdate vs sendCommand...)

References:
https://github.com/openhab/openhab/wiki/Network-Health-Binding
https://github.com/openhab/openhab/wiki/Samples-Tricks#check-presence-by-detecting-wifi-phonestablets


openHAB and Fireplace Rules Part 5

Now that everything is humming along we can make some fancy rules. This includes creating a flexible timer and auto mode based on room temperature. I went through a lot of iterations but ended up with some nice rules that work well. I will post the current version here but any updates will be maintained on Github.




Monday, December 14, 2015

openHAB the Fireplace and Rules Part 4

If you haven't read part 1, part 2, and part 3. Start there and I will wait for you here. Welcome back! Now we get to do all of the fun stuff now that we have software control of the fireplace. We can have some real fun adding features. The original remote does have a set point and scheduling options but we never used that and of course you couldn't trigger remotely or based on other triggers. The features I had in mind are listed below.
  • On/Off
  • Keep original remote functionality
  • Timer
  • Temperature set point
  • Remote turn on/auto when temp is under a certain value and we are coming home
    • This would be instead of setting up scheduling
Part of this comes from that fact that the fireplace heats better than the wall heater we have at least for that part of the apartment, which we spend a lot of time in. The hardest part was getting openHAB control vs the physical remote to play nicely together. Finally the solution was to abstract the openHAB web input versus the remote. This uses four switch items.

 
Switch  tempFire_Switch "Fireplace Manual"        (gHeating)      {zwave="4:command=SWITCH_BINARY"}
Switch  tempFire_Web    "Fireplace"       (gHeating,gLeave)
Number  tempFire_ADC    "Fireplace ADC [%d]"      (gHeating)      {zwave="4:command=SENSOR_MULTILEVEL"}
Switch  tempFire_Remote "Fireplace Remote [%s]"   (gHeating)
 

The first one, tempFire_Switch is the one that controls the relay and therefore the fireplace directly. This one will not be in the sitemap and only controlled via rules. The tempFire_Web is the input from a user using openHAB and tempFire_Remote is the physical remote. The tempFire_ADC number item is the input from the ADC relay that lets us update the remote status without interfering with the actual fireplace.

openHAB the Fireplace and Wiring Part 3

Now that the relay works we can do the final wiring. Read part 1 and part 2 to see how we got here. It's been a rabbit hole for sure, but don't fret, we are on our way out!  Compared to everything else, the wiring is the easiest part. The fireplace uses a simple switch to control it as it is a millivolt system which generates its own power (from the heat of the pilot) to trigger the gas valve. Ripe for hacking. In the end for safety (and for long term vacancies), I decided to wire the local override switch as a hard disable. That way if we are gone for the weekend or during the Summer months, I can disable it. Just in case there is a network glitch or something the fireplace can't turn on even if the relay does. Turns out this is also useful during testing of the rules so the fireplace isn't turning on and off consistently.




Basically the connections are one side of the fireplace switch connection goes parallel with the side switch then to the relay negative. Then the positive of the relay is direct to the fireplace. Then the original receiver is wired to the relay ADC input.


Simple. I used some electrical tape just so I can easily remove it, this being an apartment and all. Now we can close oFf the fireplace and play with openHAB.

Monday, December 7, 2015

openHAB and our Fireplace Part 2 and OpenZWave

Finally, the MimoLite replay has arrived. Even though it was Amazon Prime, it look about five days to land in my eager hands. At least it was free shipping! In Part 1 we looked at a solution to control the fireplace via our openHAB network. Now the fun part of actually installing it. I set aside an evening after work for the installation. Of course when projects seem simple, they end up taking a lot longer.

MimoLite Relay


Sunday, December 6, 2015

openHAB and Our Fireplace Part 1

When moving into our place nearly six years ago, my hacker eye noticed the gas fireplace and my attention was drawn to the fact that it has a remote that has manual/auto and scheduling. It's the first place I've lived in with a gas fireplace, so my first thought was the RF signal was prime for hacking. I never got around to trying anything and it is probably more difficult than the outdoor temperature sensor I did earlier this year. Recently, with the adventures in openHAB and with all of my Z-Wave research it dawned on me: I probably can just bypass the remote and interface directly. One simple test would answer my question. I took a jumper and followed the receivers two wires to the gas controller. Sure enough jumping them turns it on. The local manual switch and the remote receiver are in parallel. My question was then, where is the power coming from to detect the closed circuit? I measured about 500mV. I didn't know much about fireplaces/heaters before I started this adventure. A little research later...

Wednesday, November 25, 2015

OpenHAB and Proximity

A big part of being able to automate with rules is the ability to know who is home. Proximity is one of the items that needs to be transferred from DomotiGA to openHAB. There are two main ways of doing this. OpenHAB supports a Bluetooth binding which requires a bit of working to get setup. Not wanting to mess with that, I decided to just adapt my original shell script to openHAB as well as incorporating some changes from https://code.google.com/p/openhab-samples/wiki/Tricks#Use_cheap_bluetooth_dongles_on_remote_PCs_to_detect_your_phone/w. This example page also has some good rules on using not only phones but laptops and such on the network to track who is home.  You can have all kinds of fun with that!


OpenHAB and Zigbee Philips Hue

Now that openHAB and Z-Wave are working, it's time to get Zigbee setup so I can use the cheaper light bulbs. As of this post, the GE and Cree Zigbee bulbs are $15 at your local Home Depot or on Amazon in comparison to $30 for the Z-Wave ones. I have tested the Cree bulbs and they have a nice even glow compared to GE. The GE bulbs look cool since they have a clear dome but deathly to look at when on.

My co-worker originally bought the bulbs but realized replacing the wall switches was the way to go, so now I have them, ;).  Since I didn't go the Wink route, I had to figure out the best way to get Zigbee support. Zigbee seems a bit harder as I couldn't find a nice USB solution like Z-Wave. There are some USB solutions like the Ti Zigbee development board which is supported by openHAB2, which isn't ready for prime time.

After many hours researching I decided on the Philips Hue Hub. It's not the best solution as far as flexibility but it works with openHAB without root, using the native REST API and works locally without a cloud service. You can join it to the cloud if you want for remote access, but openHAB takes are of that for me and doesn't rely on someone else's server but my own. Plus it supports scenes and the new version of the hardware is Apple Homekit certified (if you are into that). It seems that the new hardware version just came out so it was a bit hard to find but of all places, Best Buy had it in stock. Most places sell it with a kit with a few RGB bulbs vs standalone.  I didn't want to spend that much and honestly, using the cheaper Cree bulbs is a great start. Eventually, I would like to try the color bulbs. Maybe Philips can send me some to review...