How to send the state of a switch with MQTT?

I’m migrating from MQTT1 to MQTT2 and want to publish the state change of a switch via MQTT.

I can’t seem to find a way to do this easily.
The old item definition was as follows:

Switch NB_S1_O1_lichtWC "WC" <light> (gLichtBeneden) [ "Lighting" ] { nikobus="09B9:1", mqtt=">[synology:openhab/light/wc:state:*:${state}],<[synology:openhab/light/wc/switch:command:default" }

Can someone tell me how I need to define the cahnnel to cover the old MQTT1 part
mqtt=">[synology:openhab/light/wc:state:*:${state}]
of the item definition ?

The objective is to publish the state of the switch item (a light) every time it changes in Openhab

Thanks

You need to define a command topic and stat topic in your new mqtt things. Once that is done it should function I believe.

Defining the topics is not the issue, the issue is MQTT only sends out command changes not state changes.

So not sure how to define the cannel for the >[synology:openhab/light/wc:state:*:${state}]
part in MQTT2 and how to link that to the items.

The topics is easy, that’s done

The convention for any binding is to send/publish Item commands.
MQTT v2 does not offer publish state changes or updates.
Workarounds are used for general "event bus"publishing of state changes.
For a single Item, the easiest way is probably a rule that listens for state changes and uses an Action to publish.

1 Like

Thanks this is extremely helpful !!!