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.


Note: Originally I had refresh_interval=15 at the end of the zwave config in the two items but it was flooding the logs with failed messages to the relay. I took it out for now and it stopped the messages but now the remote doesn't work since it doesn't report back the status. The ADC requires manual polling when not linked to the relay.

This keeps each function separate and allows us to use rules to link everything together however we want. This solution was after a lot of struggling and head banging until I came to the idea of breaking it into components.  The first rule is tracking the ADC value if the remote if On or Off.

 
rule "Update Fireplace remote switch"
when
        Item tempFire_ADC changed
then
        if(tempFire_ADC.state < 100){
                postUpdate(tempFire_Remote,ON)
        }
        else{
                postUpdate(tempFire_Remote,OFF)
        }
end

Now we need to sync the remote and web input with the "real" fireplace switch. The key here that was messing me up before is we can only sync one way. We can sync the remote status to the web switch but obviously not the other way since we have no way to set the remote. But this doesn't really affect much. At least this gives the flexibility to mix the remote with the web. Just because you turn it on with the remote doesn't mean you have to turn it off with the remote. The only catch would be you would have to hit the remote twice to turn the fireplace back on. The other thing is I am not sure of the receiver or remote uses more power when it thinks the fireplace is on. The crazy thing is the receiver has a DC jack but of course I am sure they were too cheap to get the option when it was installed. It's not like there isn't a power outlet under the fireplace already. Which is perfect for powering the MimoLite without having any wires showing. Win for me! Here are the rest of the rules needed for basic On/Off functionality.

 
rule "Update Fireplace based on Remote sync to Web control switches"
when
        Item  tempFire_Remote changed from OFF to ON
then
        sendCommand(tempFire_Switch, ON)
        sendCommand(tempFire_Web, ON)
end

rule "Part2"
when
        Item tempFire_Remote changed from ON to OFF
then
        sendCommand(tempFire_Switch, OFF)
        sendCommand(tempFire_Web, OFF)
end

rule "Update Fireplace based on Web sync to control switch"
when
        Item  tempFire_Web changed from OFF to ON
then
        sendCommand(tempFire_Switch, ON)
end

rule "Part2"
when
        Item tempFire_Web changed from ON to OFF
then
        sendCommand(tempFire_Switch, OFF)
end

 
 

Now we can do some fancy control using a timer function and temperature input from the living room node. Cozy!

No comments:

Post a Comment