i want to switch two lights (connected via a gpio relay card) with different methods:
-two switches (lamp1, lamp2) on the sitemap to control each lamp individually: already working
-mqtt binding to switch both lamps: kinda works
-one switch to switch on and off both lamps: i have a virtual switch but no rule
Problem: when the lamps are switched on or off via the mqtt binding, die states of the lamp1, lamp2 switches on the sitemap don’t change. How can i achieve that?
Which rule should i use for the virtual switch to control both lamps?
my rule for the mqtt binding:
when
Item esp_sw1 changed from OFF to ON
then
logInfo(“myLog”, “received ESPswitch ON”)
sendCommand(lamp1, ON)
sendCommand(lamp2, ON)
end
[…]
What do you mean the mqtt binding works so far?
None of the items has an mqtt binding.
Where is your physical switch? And how do you receive the value in OH? Is it esp_sw1?
What is esp_sw1 item definition?
rule "Both Lamps"
when
Item esp_sw1 received command
then
logInfo(“myLog”, “received command from esp_sw1:” + receivedCommand.toString)
gLamps.sendCommand(receivedCommand)
lamp_both.postUpdate(receivedCommand)
end
rule "Virtual switch"
when
Item lamp_both received command
then
esp_sw1.sendCommand(receivedCommand)
end
Thanks for your very fast and helpful answer. After fixing some quotation mark errors, it works.
But i’m still not really satisfied by how i works: If i switch on the lights using my mqtt device or the virtual switch, the switches for ‘lamp1’ und ‘lamp2’ still seem to be OFF.
Isn’t it possible to let the UI show the actual state of the switch?