steilerDev / homebridge-openhab2-complete

A homebridge plugin for openHAB, that has the expectation to fully support all Services offered by Apple's Homekit Accessory Protocol (HAP)
GNU General Public License v3.0
52 stars 16 forks source link

Dimmer save last state by OFF #37

Closed grzegorz914 closed 4 years ago

grzegorz914 commented 4 years ago

Hi, Every time if we turn OFF dimmer the value is set to 0% and after turn ON to 99%. Can U add option to save last value before switch OFF and use it as start value after switch ON?

klaudiusz223 commented 4 years ago

My workaround for this issue is configuration in OpenHAB. I have 2 Items connected to light dimmer and one virtual proxy item My hardware remembers last value and has 2 channels. One for state, reacting on "ON" and "OFF" and 2nd for brightness.

Dimmer      GF_SmallBathroom_Dimmer     "Small Bathroom Ceiling Dimmer"   {...}
Switch      GF_SmallBathroom_DimmerStatus   "Small Bathroom Ceiling Dimmer Status"   {..}

Dimmer      V_GF_SmallBathroom_DimmerHelper     "Small Bathroom Ceiling Dimmer Helper" 

Then i configured 2 rules

rule "V_GF_SmallBathroom_DimmerHelper received command"
when
    Item V_GF_SmallBathroom_DimmerHelper received command
then
    if (receivedCommand == 99 && GF_SmallBathroom_DimmerStatus.state == OFF ) {
        GF_SmallBathroom_DimmerStatus.sendCommand(ON)
    } 
    else if (receivedCommand == OFF  ) { 
        GF_SmallBathroom_DimmerStatus.sendCommand(OFF)
    } 
   else {
        GF_SmallBathroom_Dimmer.sendCommand(receivedCommand)
    }
end

rule "GF_SmallBathroom_Dimmer state changed"
when
    Item GF_SmallBathroom_Dimmer received update
then
    V_GF_SmallBathroom_DimmerHelper.postUpdate(GF_SmallBathroom_Dimmer.state)
end

Homebridge config

{
"name": "Small Bathroom Ceiling Dimmer",
"type": "light",
 "item": "V_GF_SmallBathroom_DimmerHelper"
}
grzegorz914 commented 4 years ago

Thanks,

I have create other rules which’s solved my problem. This worked with connection Homebridge>>OH>>PLC S7, updated state and brightness level from all sites. Uses as items:

Dimmer KuchniaBlatDimmer
Dimmer PLC_KuchniaBlatDimmer
Switch  PLC_KuchniaBlatSwiatlo
Switch PLC_KuchniaBlatTaster
rule "Oświetlenie kuchnia meble dimmer on/off i zmiana poziomu"
when
    Item KuchniaMebleDimmer received command
then
     if (receivedCommand == 99 && PLC_KuchniaMebleSwiatlo.state == OFF)  {
         PLC_KuchniaMebleTaster.sendCommand(ON)
         PLC_KuchniaMebleTaster.sendCommand(OFF)
        } else if (receivedCommand == OFF && PLC_KuchniaMebleSwiatlo.state == ON) {
                   PLC_KuchniaMebleTaster.sendCommand(ON)
                   PLC_KuchniaMebleTaster.sendCommand(OFF)
        } else if (PLC_KuchniaMebleSwiatlo.state == ON && (receivedCommand != 0 && receivedCommand != 99)) {
                   PLC_KuchniaMebleDimmer.sendCommand(receivedCommand)
        }  
end

rule "Oświetlenie kuchnia meble"
when
    Item PLC_KuchniaMebleSwiatlo received command
then
         PLC_KuchniaMebleTaster.sendCommand(ON)
         PLC_KuchniaMebleTaster.sendCommand(OFF)
end

rule "Oświetlenie kuchnia meble ustawienie poziomu po załączeniu"
when
    Item PLC_KuchniaMebleSwiatlo changed
then
      if (PLC_KuchniaMebleSwiatlo.state == ON) {
          KuchniaMebleDimmer.postUpdate(PLC_KuchniaMebleDimmer.state)
        } else if (PLC_KuchniaMebleSwiatlo.state == OFF) {
                   KuchniaMebleDimmer.postUpdate(OFF)
        }       
end

rule "Oświetlenie kuchnia meble dimmer aktualizacja poziomu"
when
    Item PLC_KuchniaMebleDimmer changed
then
      var Number poziom1 = PLC_KuchniaMebleDimmer.state
      if (PLC_KuchniaMebleSwiatlo.state == ON && (KuchniaMebleDimmer.state != PLC_KuchniaMebleDimmer.state)) {
          KuchniaMebleDimmer.postUpdate(poziom1)
        } 
end
steilerDev commented 4 years ago

Unfortunately homebridge does not keep the states cached. But your workaround looks very good!