openHAB and MQTT, Raspberry, ESP8266 and relays question


I just started to understand this fantastic platform.

I’m using Raspberry Pi B+ as openHAB server and using ESP8266 to “play” with IoT.

I started with a simple switch that open/close a relay connected to the ESP.

What I would like to do, apart from switching ON/OFF from openHAB app is to set the switch ON/OFF directly from the program in the ESP.

I’m using MQTT to communicate between openHAB and ESP.

This is the switch defined in the openHAB:
Switch switch2 (All) {mqtt=">[localbroker:localnet/openHAB/devices/led2:command:ON:default],>[localbroker:localnet/openHAB/devices/led2:command:OFF:default]"}

and it’s working great.

If I would like to change the switch status directly from the ESP program what command should I send back to openHAB?


I think all you need to do is add some inbound clauses to the binding string:

Switch switch2 (All) {mqtt=">[localbroker:localnet/openHAB/devices/led2:command:ON:default],>[localbroker:localnet/openHAB/devices/led2:command:OFF:default],<[localbroker:localnet/openHAB/devices/led2:state:default]"}