Toggle light from a wall push-button or from a sitemap item

Dear all,

I think the topic’s title is clear, but here are some more details about my need :

Today, what works :

  • A push-button (BP01) sends “ON” and “OFF” via MQTT thru a first Arduino
  • A lamp (L01) receives “ON” and “OFF” via MQTT thru a second Arduino
  • An OH rule toggles L01 state each time I press BP01

Remark : For that, MQTT event bus is configured.


Switch BP01 "Push button 1"
Switch L01 "Lamp 1" <light>


rule "Toggle L01"
    BP01.state changed
    if (BP01.state == ON)
        if (L01.state == ON)
        if (BP01.state == OFF)

This is basic but it works, my lamp turn on and off.

What I want :

  • A switch (SW01) on a sitemap to turn ON and OFF my lamp (L01) too
  • SW01 should reflect L01 status
  • If I toggle L01 with BP01, SW01 is updated

I tried to read topics discussing about “PROXY”, but I have difficulties to adapt this to my need :

@+, Olivier

1 Like

does L01 publish its state to a topic?

If yes: you can setup a SW01 that publishes the command to the proper topic and also subscribes to the status topic.
In this way, it doesn’t matter which action (BP01 or SW01 or another) switched the L01 ON or OFF, since L01 will report its current state and SW01 will be updated accordingly.

…if no: you can still do the same with SW01, but you won’t have a way to synchronize/update the SW01 state with the real state of L01

For troubleshooting purposes, I wouldn’t use the MQTT-Event Bus integration but rather focused MQTT item configs.

For sure, L01 publish its state.

Due to “event-bus”, my MQTT topics look like something like that :

I understand that your proposal is based on “MQTT item configs” not on Event-bus.

Reagarding my need, which kind of problem could I have ?

@+, Olivier

You won’t have any problem using the MQTT-Event Bus integration method. It will work just fine.
I just mentioned that to be able to check easier the situation, I would switch to an item based config first and then you can switch back to the Bus method.

For example, your SW01 would look like:

Switch	SW01	"SW01"	<light>	{mqtt=">[broker_name:Try_04/output/L01/command:command:*:default]", <[broker_name:Try_04/input/L01/state:state:default}

In this example:
L01 should publish its state on topic: Try_04/input/L01/state
L01 should subscribe for commands on topic: Try_04/output/L01/command

When you flick the SW01 switch to ON (or OFF), it will publish the payload ON (or OFF) to the command topic.
SW01 item will also subscribe to status updates on the state topic

Ps: You can name your OH2 switch item “L01” if you want.
Keep in mind that the MQTT Event Bus method will publish and subscribe based on the $item name (so if you use SW01, it will publish on Try_04/output/SW01/command and sub to Try_04/input/SW01/state