- Platform information: Windows
- Hardware: Intel/16G/2TB
- OS: Windows 10
- Java Runtime Environment: JRE 8
- openHAB version: 2.5
- Issue of the topic:
Greetings!
I’m trying to setup a rule to get a dimmer and switch arranged in a 3-way setup and am running into a problem with what I think is a feedback loop. I’m stuck so I was hoping someone with more experience at this can help get me straightened out.
Here is where I am:
Light is connected to a z-wave switch. A z-wave dimmer in another room controls/triggers the switch with this first rule and it works correctly (both physical dimmer and switch mirrors the other). Please note that dimmer.state is numerical % or binary on/off.
// *****************************Laundry Room 2 Garage Rules ************** */
rule "Garage_Switch_2_Laundry"
when
Item zwave_device_XXXXXX_node51_switch_dimmer changed // Garage 1 Dimmer
then
if(zwave_device_XXXXXX_node61_switch_binary.state != zwave_device_XXXXXX_node51_switch_dimmer.state)
(if (zwave_device_XXXXXX_node51_switch_dimmer.state >=3)
sendCommand(zwave_device_XXXXXX_node61_switch_binary, ON) // Laundry Garage
else
sendCommand(zwave_device_XXXXXX_node61_switch_binary, OFF) // Laundry Garage
)
end
However, I run into a problem when I try to mirror the switch state to the dimmer using a similar rule. I get a feedback loop of the light going on and off repeatedly.
From the log what I think is happening is the dimmer sends an update to openhab and it lags causing the problem.
2021-12-02 15:45:52.816 [ome.event.ItemCommandEvent] - Item 'zwave_device_XXXXXX_node51_switch_dimmer' received command ON
2021-12-02 15:45:52.817 [nt.ItemStatePredictedEvent] - zwave_device_XXXXXX_node51_switch_dimmer predicted to become ON
2021-12-02 15:45:52.821 [vent.ItemStateChangedEvent] - zwave_device_XXXXXX_node51_switch_dimmer changed from 0 to 100
2021-12-02 15:45:53.083 [ome.event.ItemCommandEvent] - Item 'zwave_device_XXXXXX_node61_switch_binary' received command ON
2021-12-02 15:45:53.083 [nt.ItemStatePredictedEvent] - zwave_device_XXXXXX_node61_switch_binary predicted to become ON
2021-12-02 15:45:53.087 [vent.ItemStateChangedEvent] - zwave_device_XXXXXX_node61_switch_binary changed from OFF to ON
2021-12-02 15:45:55.709 [ome.event.ItemCommandEvent] - Item 'zwave_device_XXXXXX_node51_switch_dimmer' received command OFF
2021-12-02 15:45:55.710 [nt.ItemStatePredictedEvent] - zwave_device_XXXXXX_node51_switch_dimmer predicted to become OFF
2021-12-02 15:45:55.713 [vent.ItemStateChangedEvent] - zwave_device_XXXXXX_node51_switch_dimmer changed from 100 to 0
2021-12-02 15:45:55.718 [ome.event.ItemCommandEvent] - Item 'zwave_device_XXXXXX_node61_switch_binary' received command OFF
2021-12-02 15:45:55.719 [nt.ItemStatePredictedEvent] - zwave_device_XXXXXX_node61_switch_binary predicted to become OFF
2021-12-02 15:45:55.722 [vent.ItemStateChangedEvent] - zwave_device_XXXXXX_node61_switch_binary changed from ON to OFF
Item 'zwave_device_XXXXXX_node61_switch_binary' received command ON
2021-12-02 15:47:09.980 [nt.ItemStatePredictedEvent] - zwave_device_XXXXXX_node61_switch_binary predicted to become ON
2021-12-02 15:47:09.983 [vent.ItemStateChangedEvent] - zwave_device_XXXXXX_node61_switch_binary changed from OFF to ON
2021-12-02 15:47:09.993 [vent.ItemStateChangedEvent] - zwave_device_XXXXXX_node51_switch_dimmer changed from 0 to 100
2021-12-02 15:47:11.596 [ome.event.ItemCommandEvent] - Item 'zwave_device_XXXXXX_node61_switch_binary' received command OFF
2021-12-02 15:47:11.597 [nt.ItemStatePredictedEvent] - zwave_device_XXXXXX_node61_switch_binary predicted to become OFF
2021-12-02 15:47:11.601 [vent.ItemStateChangedEvent] - zwave_device_XXXXXX_node61_switch_binary changed from ON to OFF
2021-12-02 15:47:11.608 [vent.ItemStateChangedEvent] - zwave_device_XXXXXX_node51_switch_dimmer changed from 100 to 0
I tried using using postUpdate updates the state, but the physical dimmer itself does not update/mirror the switch and requires turning it on, then off again before it will trigger the switch in the first rule to turn the light on.
The “solution” I’m using is to sleep (wait) for openhab to update the state before checking its state like this:
rule "Laundry_2_Garage_Switch_ON"
when
Item zwave_device_XXXXXX_node61_switch_binary changed // Laundry Garage
then
Thread::sleep(500) // sleep half a second
if(zwave_device_XXXXXX_node61_switch_binary.state != zwave_device_XXXXXX_node51_switch_dimmer.state)
(if (zwave_device_XXXXXX_node61_switch_binary.state === ON)
zwave_device_XXXXXX_node51_switch_dimmer.sendCommand(ON) // Garage 1 Dimmer
else
zwave_device_XXXXXX_node51_switch_dimmer.sendCommand(OFF) // Garage 1 Dimmer
)
end
It kind of works most of the time, but I’m hoping there is perhaps a more elegant and reliable solution to this.
Thank you!
Ben