Daikin Heatpumps

OpenHAB controlled heatpumps

Highlights

  • Powered by Daikin
  • Direct injection to Daikin IR Receiver (no IR blaster)
  • Direct feedback
  • OpenHAB controlled to activate for heat when below 11 degrees and room has been marked as in use.
    • Opposite will occur when I code for the opposite in summer time here.
  • Heat pump remote can still be used and OpenHAB syncs to its state

Controlling the heat pump

In this modification, the Daikin heat pump is controlled directly from the Arduino. No IR Transmitter or blaster is used. It’s more technical, less portable, but more truly integrates and establishes the device as internet ready.

The basis of the code comes from the Arduino\Examples\HeatpumpIR\MySensorsNode example which in turn is based heavily on Ken Shirriff’s IRRemote library.

However, because we’re injecting directly into the IR Receiver and not using a transmitter, there are two small minor adjustments required.

  1. As the Arduino output connects directly to the Daikin’s IR receiver output pin, it only needs to transmit the coded signal, not the PWM carrier signal.Within the IRSender.cpp code, identify the setFrequency method. Set the output pin to High, then exit the method so the carrier is not established e.g.
void IRSender::setFrequency(int frequency)
{
  uint8_t pwmval8 = F_CPU / 2000 / (frequency);
  uint16_t pwmval16 = F_CPU / 2000 / (frequency);
  pinMode(_pin, OUTPUT);
//  digitalWrite(_pin, LOW); // When not sending PWM, we want it low
digitalWrite(_pin, HIGH); // Comment out the LOW above and set this to high
return; //Then return out of here so PWM is not activated<br>
  switch (_pin)
  {
  1. To allow the standard IR remote, we must set the Arduino pin back to Input, so it doesn’t interfere with normal operations. In the main MySenors code after the heatpump instruction is send to this
heatpumpIR[model]->send(irSender, power, mode, fan, temp, VDIR_UP, HDIR_AUTO);
pinMode(3, INPUT); //When not sending IR signals, PIN 3 must be in INPUT mode so that the true Daikin remote control can send its IR signal.

Powering the MySensors Node

The node is running on 5V sourced from the Daikin unit’s IR Receiver. Ground is also from this. There’s a couple of pictures on this page describing and showing this connection and describing the pin out. As per further info below, don’t short this else you’ll be pulling the header units board out to replace fuse.

Regarding load on this voltage source and the mentioned fuse, I never had any issues with it, but to reduce potential & ensure no red light shines through the unit, I removed the Pro mini’s power LED (simply carefully crushed and pulled it off with my wire cutters). As I write this now though, I can’t recall if I did the same on the 3.3v regulator for the radio. That has a bright LED too. On one of the earlier builds, I simply covered that with a bit of paint 🙂

Obtaining the heat pump status

The heat pump status is obtained by connecting the heat pump status LED to the Arduino and a simple MySensors binary switch. However, the Daikin status LED has ~16v across it which is too high for the Arduino for a direct wiring. I used a EL4N35 Optocoupler in parallel with the LED to isolate the circuits.

In addition, to stop the Daikin status LED from dimming, a 330ohm resister was places in series with the optocopler.

I was extremely careful right through the prototyping stage to not cross the 5v wires from the heat pump. Unfortunately on the final wiring, they crossed and killed the Daikin board. After researching worst case alternatives & second hand ~$100 USD units from China, I set out to try and fix my board.

Two more nodes

Regarding this video: This is absolutely not a normal thing to to. The board is open and on the kitchen bench because I had to replace the fuse.

It’s connected to 240v and as I turn it on, you see the on-board LED begin to flash. As the camera then shows the laptop screen, after several seconds, the MySensors node which is connected to the board, the establishes communication with the MySensors Gateway and MQTT.

The re-occuring 1s and 0s represents the flashing status LED back within the black plastic. It will be doing this because it’s not happy that it’s not installed properly. In normal operation, the status LED is represented properly as either 1 or 0, On or Off back in OpenHAB.

I really don’t recommend you do this sort of thing yourself. This video is only for interested people and is not a how to guide. You run the risk of either killing yourself or your electronics. I don’t want to hear about either!

OpenHAB & Climate Control

We have a heat pump outlet in each bedroom. Each heat pump has 3 OpenHAB settings. Off, On & Auto. The first two are self explanatory and when using the standard Daikin remote, OpenHAB is synced automatically to the Off/On setting.

When OpenHAB has the heat pump set to Auto, this is when the fun begins. No longer do we control the heat pump, but instead we say that we are “Staying in the room”. This way, the house controls weather to turn on the heat pump or not. When the temperature outside goes below 11 degrees, the heat pump is turned on (and to Heat). When it rises above 12, it turns off again. There’s a 1 degree difference to stop is oscillating around 11 degrees while the night is still cooling.

I’ll configure the opposite controls when it gets to summer time here in New Zealand.

OpenHAB reports the current state of the heat pump.

The OpenHAB rules seem like a lot and they possibly are. However, I spent quite a lot of time getting them stable and to this point. I’m not to worried if there’s an extra line or two of logic in there. Certainly the tracing came in handy!

One day I’ll replace the manual “Staying in the room” selection with some smart presence detection. I’ll also be adding a rule that says around 9am in the morning, that regardless of the temperature outside, this switch will be set to false – basically, you should be out of bed!

OpenHAB Items

Group   gClimate                "Climate"               (All)<br>
Group   gClimateControls        "Climate Controls"      (All)


Number  Temperatures_Chart_Period                               "Chart Period"


Number Shed_Temperature2        "temporary temperature [%.1f C]"        <temperature>   (gClimate)              {mqtt="<[mosquitto:mygateway1-out/45/0/1/0/0:state:default]"}
Number Garage_Temperature       "Garage Temperature [%.1f C]"   <temperature>   (gClimate)              {mqtt="<[mosquitto:mygateway1-out/46/2/1/0/0:state:default]"}
Number Garage_Attic_Temperature "Attic Temperature [%.1f C]"    <temperature>   (gClimate)              {mqtt="<[mosquitto:mygateway1-out/46/0/1/0/0:state:default]"}
Number Outdoor_Temperature      "Outdoor Temperature [%.1f C]"  <temperature>   (gClimate)              {mqtt="<[mosquitto:mygateway1-out/46/1/1/0/0:state:default]"}


Number Climate_Control_Master_Bedroom   "Climate control required in Master bedroom"                    {}
Number Heatpump_Master_Bedroom_Status   "Master Bedroom Heatpump [MAP(on_off.map):%s]"  <light> (gClimateControls)      {mqtt="<[mosquitto:mygateway1-out/55/2/1/0/16:state:default]"}
String Heatpump_Master_Bedroom_Control  "[%s]"                                                                          {mqtt=">[mosquitto:mygateway1-in/55/1/0/0/32:command:*:default]"}
Switch Climate_Staying_Master_Bedroom   "Staying in Master bedroom"                                     {}

Number Climate_Control_xxxxx_Bedroom   "Climate control required in xxxxx bedroom"                    {}
Number Heatpump_xxxxx_Bedroom_Status   "xxxxx Bedroom Heatpump [MAP(on_off.map):%s]"  <light> (gClimateControls)      {mqtt="<[mosquitto:mygateway1-out/56/2/1/0/16:state:default]"}
String Heatpump_xxxxx_Bedroom_Control  "[%s]"                                                                          {mqtt=">[mosquitto:mygateway1-in/56/1/0/0/32:command:*:default]"}
Switch Climate_Staying_xxxxx_Bedroom   "Staying in xxxxx bedroom"                                     {}
Number Heatpump_xxxxx_Temperature      "xxxxxh's Room [%.1f C]"                <temperature>   (gClimate)              {mqtt="<[mosquitto:mygateway1-out/56/0/1/0/0:state:default]"}

OpenHAB Sitemap

  Group label="Climate Control"{
        Frame{
                Text item=Outdoor_Temperature
        }

        Frame label="Master Bedroom"{
                Switch item=Climate_Control_Master_Bedroom mappings=[0="Off", 1="On", 2="Auto"]
                Switch item=Climate_Staying_Master_Bedroom
                Text item=Heatpump_Master_Bedroom_Status
        }

        Frame label="xxxxx Bedroom"{
                Text item=Heatpump_xxxxx_Temperature
                Switch item=Climate_Control_xxxxx_Bedroom mappings=[0="Off", 1="On", 2="Auto"]
                Switch item=Climate_Staying_xxxxx_Bedroom
                Text item=Heatpump_xxxxx_Bedroom_Status
        }                     

        Frame {
                Switch item=Temperatures_Chart_Period label="" mappings=[0="Hour", 1="Day", 2="Week"]
                Chart item=gClimate period=h refresh=30000 visibility=[Temperatures_Chart_Period==0]
                Chart item=gClimate period=D refresh=90000 visibility=[Temperatures_Chart_Period==1]
                Chart item=gClimate period=W refresh=300000 visibility=[Temperatures_Chart_Period==2, Temperatures_Chart_Period=="Uninitialized"]
        }
}

OpenHAB Rules

import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*
import org.java.math.*
import org.joda.time.*



var String heatpump_heat        = "00012112"
var String heatpump_off         = "00002112"

var String heatpump_setting     = ""
var int turn_off                = 0

var int cold_temperature        = 11


var int openhab_controlled_master_bedroom = 0
var DateTime last_set_by_openhab


rule "Climate Control"
when
        Item Outdoor_Temperature changed or
        Item Climate_Control_Master_Bedroom changed or
        Item Climate_Staying_Master_Bedroom changed or
        Item Climate_Control_xxxxx_Bedroom changed or
        Item Climate_Staying_xxxxx_Bedroom changed or
then
        logInfo("Climate Control", "Running Climate Control. Outdoor temperature is [{}]", Outdoor_Temperature.state)

        turn_off = 0

        if((Outdoor_Temperature.state < cold_temperature)
                || (Heatpump_Master_Bedroom_Status.state==1 && Outdoor_Temperature.state < cold_temperature + 1)){
                //the OR bit above ensures if the heatpump is on and the temperature flucuates above the
                //trigger by less than a degree, the pump remains on

                logInfo("Climate Control", "Outdoor temperature is below cold temperature. Heatpumps will be set to Heat if necessary")
                heatpump_setting = heatpump_heat
        }//else todo, outdoor > hot_temperature //I'll do this in the summer time!
        
        
        else{
                logInfo("Climate Control", "Neither hot, nor cold. Heatpumps will be turned off"
                turn_off = 1
        }



//0 = Off, 1=On, 2=Auto

        /* MASTER BEDROOM */
        if(Climate_Control_Master_Bedroom.state==0){
                logInfo("Climate Control", "Master Bedroom state has been selected to be off")
                if(Heatpump_Master_Bedroom_Status.state!=0){
                        logInfo("Climate Control", "Master bedroom is on, so turning it off")
                        last_set_by_openhab = now
                        Heatpump_Master_Bedroom_Control.sendCommand(heatpump_off)
               }

        }else if(Climate_Control_Master_Bedroom.state==1){
                logInfo("Climate Control", "Master Bedroom state has been selected to be On")
                if(Heatpump_Master_Bedroom_Status.state!=1){
                        logInfo("Climate Control", "Master bedroom is off, so turning it on")
                        last_set_by_openhab = now
                        Heatpump_Master_Bedroom_Control.sendCommand(heatpump_setting)
                //      Thread::sleep(1000)
                //      Heatpump_Master_Bedroom_Control.sendCommand(heatpump_setting)
                }

        }else if(Climate_Control_Master_Bedroom.state==2){
                logInfo("Climate Control", "Master Bedroom requries Auto climate control")

                if(Climate_Staying_Master_Bedroom.state==ON){

                        if(turn_off==1){
                                if(Heatpump_Master_Bedroom_Status.state==0){
                                        logInfo("Climate Control", "Master Bedroom presence, but heatpump should be off and it already is")
                                }else{
                                        logInfo("Climate Control", "Master Bedroom presence, but heatpump needs to be turned off. Sending [{}]", heatpump_setting)
                                        last_set_by_openhab = now
                                        Heatpump_Master_Bedroom_Control.sendCommand(heatpump_off)
                                }
                        }else{

                                if(Heatpump_Master_Bedroom_Status.state!=1){
                                        logInfo("Climate Control", "Master Bedroom presence, heatpump needs to be turned on. Sending [{}]", heatpump_setting)
                                        last_set_by_openhab = now
                                        Heatpump_Master_Bedroom_Control.sendCommand(heatpump_setting)
                                }else{
                                        logInfo("Climate Control", "Master Bedroom presence, heatpump is alreay in an on state")
                                }
                        }
                }else{
                        //No presence, turn off if necessary
                        if(Heatpump_Master_Bedroom_Status.state!=1){
                                logInfo("Climate Control", "Master Bedroom no presence, heatpump should be off and it already is")
                        }else{
                                logInfo("Climate Control", "Master Bedroom no presence, heatpump needs to be turned off. Sending [{}]", heatpump_setting)
                                last_set_by_openhab = now
                                Heatpump_Master_Bedroom_Control.sendCommand(heatpump_off)
                        }
                }
        }





/* xxxxx BEDROOM */
        if(Climate_Control_xxxxx_Bedroom.state==0){
                logInfo("Climate Control", "xxxxx Bedroom state has been selected to be off")
                if(Heatpump_xxxxx_Bedroom_Status.state!=0){
                        logInfo("Climate Control", "xxxxx bedroom is on, so turning it off")
                        last_set_by_openhab = now
                        Heatpump_xxxxx_Bedroom_Control.sendCommand(heatpump_off)
               }

        }else if(Climate_Control_xxxxx_Bedroom.state==1){
                logInfo("Climate Control", "xxxxx Bedroom state has been selected to be On")
                if(Heatpump_xxxxx_Bedroom_Status.state!=1){
                        logInfo("Climate Control", "xxxxx bedroom is off, so turning it on")
                        last_set_by_openhab = now
                        Heatpump_xxxxx_Bedroom_Control.sendCommand(heatpump_setting)
                //      Thread::sleep(1000)
                //      Heatpump_xxxxx_Bedroom_Control.sendCommand(heatpump_setting)
                }

        }else if(Climate_Control_xxxxx_Bedroom.state==2){
                logInfo("Climate Control", "xxxxx Bedroom requries Auto climate control")

                if(Climate_Staying_xxxxx_Bedroom.state==ON){

                        if(turn_off==1){
                                if(Heatpump_xxxxx_Bedroom_Status.state==0){
                                        logInfo("Climate Control", "xxxxx Bedroom presence, but heatpump should be off and it already is")
                                }else{
                                        logInfo("Climate Control", "xxxxx Bedroom presence, but heatpump needs to be turned off. Sending [{}]", heatpump_setting)
                                        last_set_by_openhab = now
                                        Heatpump_xxxxx_Bedroom_Control.sendCommand(heatpump_off)
                                }
                        }else{

                                if(Heatpump_xxxxx_Bedroom_Status.state!=1){
                                        logInfo("Climate Control", "xxxxx Bedroom presence, heatpump needs to be turned on. Sending [{}]", heatpump_setting)
                                        last_set_by_openhab = now
                                        Heatpump_xxxxx_Bedroom_Control.sendCommand(heatpump_setting)
                                }else{
                                        logInfo("Climate Control", "xxxxx Bedroom presence, heatpump is alreay in an on state")
                                }
                        }
                }else{
                        //No presence, turn off if necessary
                        if(Heatpump_xxxxx_Bedroom_Status.state!=1){
                                logInfo("Climate Control", "xxxxx Bedroom no presence, heatpump should be off and it already is")
                        }else{
                                logInfo("Climate Control", "xxxxx Bedroom no presence, heatpump needs to be turned off. Sending [{}]", heatpump_setting)
                                last_set_by_openhab = now
                                Heatpump_xxxxx_Bedroom_Control.sendCommand(heatpump_off)
                        }
                }
        }







end




rule "Heatpump_Master_Bedroom_Status changed" when
        Item Heatpump_Master_Bedroom_Status changed
then

        //if someone has set the heatpump and it wasn't openhab recently, then wait a little bit for any lights to stop flashing
        //and sync the state

        if(last_set_by_openhab == null || !last_set_by_openhab.plusSeconds(5).isAfter(now)){

                logInfo("Climate Control", "Heatpump_Master_Bedroom_Status changed and it wasn't by openhab")

                Thread::sleep(1500)

                //if new state is not on (off), set openhab to off
                if(Heatpump_Master_Bedroom_Status.state != 1
                        && Climate_Control_Master_Bedroom.state != 0){
                        logInfo("Climate Control", "Climate_Control_Master_Bedroom.postUpdate(0);"
                        Climate_Control_Master_Bedroom.postUpdate(0);
                }


                //if new state it not off (on), set openhab to on
                if(Heatpump_Master_Bedroom_Status.state != 0
                        && Climate_Control_Master_Bedroom.state != 1 ){

                        logInfo("Climate Control", "Climate_Control_Master_Bedroom.postUpdate(1);"

                        Climate_Control_Master_Bedroom.postUpdate(1);
                 }
        }else{
                logInfo("Climate Control", "Heatpump_Master_Bedroom_Status changed, but OpenHAB had changed it, so not syncing ")
        }

end


rule "Heatpump_xxxxx_Bedroom_Status changed" when
        Item Heatpump_xxxxx_Bedroom_Status changed
then

        //if someone has set the heatpump and it wasn't openhab recently, then wait a little bit for any lights to stop flashing
        //and sync the state

        if(last_set_by_openhab == null || !last_set_by_openhab.plusSeconds(5).isAfter(now)){

                logInfo("Climate Control", "Heatpump_xxxxx_Bedroom_Status changed and it wasn't by openhab")

                Thread::sleep(1500)

                //if new state is not on (off), set openhab to off
                if(Heatpump_xxxxx_Bedroom_Status.state != 1
                        && Climate_Control_xxxxx_Bedroom.state != 0){
                        logInfo("Climate Control", "Climate_Control_xxxxx_Bedroom.postUpdate(0);"
                        Climate_Control_xxxxx_Bedroom.postUpdate(0);
                }


                //if new state it not off (on), set openhab to on
                if(Heatpump_xxxxx_Bedroom_Status.state != 0
                        && Climate_Control_xxxxx_Bedroom.state != 1 ){

                        logInfo("Climate Control", "Climate_Control_xxxxx_Bedroom.postUpdate(1);"

                        Climate_Control_xxxxx_Bedroom.postUpdate(1);
                 }
        }else{
                logInfo("Climate Control", "Heatpump_xxxxx_Bedroom_Status changed, but OpenHAB had changed it, so not syncing ")
        }

end

Software on the MySensors Node

import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*
import org.java.math.*
import org.joda.time.*



var String heatpump_heat        = "00012112"
var String heatpump_off         = "00002112"

var String heatpump_setting     = ""
var int turn_off                = 0

var int cold_temperature        = 11


var int openhab_controlled_master_bedroom = 0
var DateTime last_set_by_openhab


rule "Climate Control"
when
        Item Outdoor_Temperature changed or
        Item Climate_Control_Master_Bedroom changed or
        Item Climate_Staying_Master_Bedroom changed or
        Item Climate_Control_xxxxx_Bedroom changed or
        Item Climate_Staying_xxxxx_Bedroom changed or
then
        logInfo("Climate Control", "Running Climate Control. Outdoor temperature is [{}]", Outdoor_Temperature.state)

        turn_off = 0

        if((Outdoor_Temperature.state < cold_temperature)
                || (Heatpump_Master_Bedroom_Status.state==1 && Outdoor_Temperature.state < cold_temperature + 1)){
                //the OR bit above ensures if the heatpump is on and the temperature flucuates above the
                //trigger by less than a degree, the pump remains on

                logInfo("Climate Control", "Outdoor temperature is below cold temperature. Heatpumps will be set to Heat if necessary")
                heatpump_setting = heatpump_heat
        }//else todo, outdoor > hot_temperature //I'll do this in the summer time!
        
        
        else{
                logInfo("Climate Control", "Neither hot, nor cold. Heatpumps will be turned off"
                turn_off = 1
        }



//0 = Off, 1=On, 2=Auto

        /* MASTER BEDROOM */
        if(Climate_Control_Master_Bedroom.state==0){
                logInfo("Climate Control", "Master Bedroom state has been selected to be off")
                if(Heatpump_Master_Bedroom_Status.state!=0){
                        logInfo("Climate Control", "Master bedroom is on, so turning it off")
                        last_set_by_openhab = now
                        Heatpump_Master_Bedroom_Control.sendCommand(heatpump_off)
               }

        }else if(Climate_Control_Master_Bedroom.state==1){
                logInfo("Climate Control", "Master Bedroom state has been selected to be On")
                if(Heatpump_Master_Bedroom_Status.state!=1){
                        logInfo("Climate Control", "Master bedroom is off, so turning it on")
                        last_set_by_openhab = now
                        Heatpump_Master_Bedroom_Control.sendCommand(heatpump_setting)
                //      Thread::sleep(1000)
                //      Heatpump_Master_Bedroom_Control.sendCommand(heatpump_setting)
                }

        }else if(Climate_Control_Master_Bedroom.state==2){
                logInfo("Climate Control", "Master Bedroom requries Auto climate control")

                if(Climate_Staying_Master_Bedroom.state==ON){

                        if(turn_off==1){
                                if(Heatpump_Master_Bedroom_Status.state==0){
                                        logInfo("Climate Control", "Master Bedroom presence, but heatpump should be off and it already is")
                                }else{
                                        logInfo("Climate Control", "Master Bedroom presence, but heatpump needs to be turned off. Sending [{}]", heatpump_setting)
                                        last_set_by_openhab = now
                                        Heatpump_Master_Bedroom_Control.sendCommand(heatpump_off)
                                }
                        }else{

                                if(Heatpump_Master_Bedroom_Status.state!=1){
                                        logInfo("Climate Control", "Master Bedroom presence, heatpump needs to be turned on. Sending [{}]", heatpump_setting)
                                        last_set_by_openhab = now
                                        Heatpump_Master_Bedroom_Control.sendCommand(heatpump_setting)
                                }else{
                                        logInfo("Climate Control", "Master Bedroom presence, heatpump is alreay in an on state")
                                }
                        }
                }else{
                        //No presence, turn off if necessary
                        if(Heatpump_Master_Bedroom_Status.state!=1){
                                logInfo("Climate Control", "Master Bedroom no presence, heatpump should be off and it already is")
                        }else{
                                logInfo("Climate Control", "Master Bedroom no presence, heatpump needs to be turned off. Sending [{}]", heatpump_setting)
                                last_set_by_openhab = now
                                Heatpump_Master_Bedroom_Control.sendCommand(heatpump_off)
                        }
                }
        }





/* xxxxx BEDROOM */
        if(Climate_Control_xxxxx_Bedroom.state==0){
                logInfo("Climate Control", "xxxxx Bedroom state has been selected to be off")
                if(Heatpump_xxxxx_Bedroom_Status.state!=0){
                        logInfo("Climate Control", "xxxxx bedroom is on, so turning it off")
                        last_set_by_openhab = now
                        Heatpump_xxxxx_Bedroom_Control.sendCommand(heatpump_off)
               }

        }else if(Climate_Control_xxxxx_Bedroom.state==1){
                logInfo("Climate Control", "xxxxx Bedroom state has been selected to be On")
                if(Heatpump_xxxxx_Bedroom_Status.state!=1){
                        logInfo("Climate Control", "xxxxx bedroom is off, so turning it on")
                        last_set_by_openhab = now
                        Heatpump_xxxxx_Bedroom_Control.sendCommand(heatpump_setting)
                //      Thread::sleep(1000)
                //      Heatpump_xxxxx_Bedroom_Control.sendCommand(heatpump_setting)
                }

        }else if(Climate_Control_xxxxx_Bedroom.state==2){
                logInfo("Climate Control", "xxxxx Bedroom requries Auto climate control")

                if(Climate_Staying_xxxxx_Bedroom.state==ON){

                        if(turn_off==1){
                                if(Heatpump_xxxxx_Bedroom_Status.state==0){
                                        logInfo("Climate Control", "xxxxx Bedroom presence, but heatpump should be off and it already is")
                                }else{
                                        logInfo("Climate Control", "xxxxx Bedroom presence, but heatpump needs to be turned off. Sending [{}]", heatpump_setting)
                                        last_set_by_openhab = now
                                        Heatpump_xxxxx_Bedroom_Control.sendCommand(heatpump_off)
                                }
                        }else{

                                if(Heatpump_xxxxx_Bedroom_Status.state!=1){
                                        logInfo("Climate Control", "xxxxx Bedroom presence, heatpump needs to be turned on. Sending [{}]", heatpump_setting)
                                        last_set_by_openhab = now
                                        Heatpump_xxxxx_Bedroom_Control.sendCommand(heatpump_setting)
                                }else{
                                        logInfo("Climate Control", "xxxxx Bedroom presence, heatpump is alreay in an on state")
                                }
                        }
                }else{
                        //No presence, turn off if necessary
                        if(Heatpump_xxxxx_Bedroom_Status.state!=1){
                                logInfo("Climate Control", "xxxxx Bedroom no presence, heatpump should be off and it already is")
                        }else{
                                logInfo("Climate Control", "xxxxx Bedroom no presence, heatpump needs to be turned off. Sending [{}]", heatpump_setting)
                                last_set_by_openhab = now
                                Heatpump_xxxxx_Bedroom_Control.sendCommand(heatpump_off)
                        }
                }
        }







end




rule "Heatpump_Master_Bedroom_Status changed" when
        Item Heatpump_Master_Bedroom_Status changed
then

        //if someone has set the heatpump and it wasn't openhab recently, then wait a little bit for any lights to stop flashing
        //and sync the state

        if(last_set_by_openhab == null || !last_set_by_openhab.plusSeconds(5).isAfter(now)){

                logInfo("Climate Control", "Heatpump_Master_Bedroom_Status changed and it wasn't by openhab")

                Thread::sleep(1500)

                //if new state is not on (off), set openhab to off
                if(Heatpump_Master_Bedroom_Status.state != 1
                        && Climate_Control_Master_Bedroom.state != 0){
                        logInfo("Climate Control", "Climate_Control_Master_Bedroom.postUpdate(0);"
                        Climate_Control_Master_Bedroom.postUpdate(0);
                }


                //if new state it not off (on), set openhab to on
                if(Heatpump_Master_Bedroom_Status.state != 0
                        && Climate_Control_Master_Bedroom.state != 1 ){

                        logInfo("Climate Control", "Climate_Control_Master_Bedroom.postUpdate(1);"

                        Climate_Control_Master_Bedroom.postUpdate(1);
                 }
        }else{
                logInfo("Climate Control", "Heatpump_Master_Bedroom_Status changed, but OpenHAB had changed it, so not syncing ")
        }

end


rule "Heatpump_xxxxx_Bedroom_Status changed" when
        Item Heatpump_xxxxx_Bedroom_Status changed
then

        //if someone has set the heatpump and it wasn't openhab recently, then wait a little bit for any lights to stop flashing
        //and sync the state

        if(last_set_by_openhab == null || !last_set_by_openhab.plusSeconds(5).isAfter(now)){

                logInfo("Climate Control", "Heatpump_xxxxx_Bedroom_Status changed and it wasn't by openhab")

                Thread::sleep(1500)

                //if new state is not on (off), set openhab to off
                if(Heatpump_xxxxx_Bedroom_Status.state != 1
                        && Climate_Control_xxxxx_Bedroom.state != 0){
                        logInfo("Climate Control", "Climate_Control_xxxxx_Bedroom.postUpdate(0);"
                        Climate_Control_xxxxx_Bedroom.postUpdate(0);
                }


                //if new state it not off (on), set openhab to on
                if(Heatpump_xxxxx_Bedroom_Status.state != 0
                        && Climate_Control_xxxxx_Bedroom.state != 1 ){

                        logInfo("Climate Control", "Climate_Control_xxxxx_Bedroom.postUpdate(1);"

                        Climate_Control_xxxxx_Bedroom.postUpdate(1);
                 }
        }else{
                logInfo("Climate Control", "Heatpump_xxxxx_Bedroom_Status changed, but OpenHAB had changed it, so not syncing ")
        }

end
Last modified April 10, 2023: more content (59f5057)