ESP8266 Switch status not updating

Hello, I’m relatively new to OpenHAB2

I’ve configured an Item as follows:

Switch Light_Bedroom “Bedroom Light” (R_Bedroom, Lights) {mqtt=">[broker:cmnd/BSwitch/1/LIGHT/state:command:ON:on],>[broker:cmnd/BSwitch/1/LIGHT/state:command:OFF:off],<[broker:stat/BSwitch/1/LIGHT/state:state:default]"}

Am I correct in assuming that this should allow me to send a command using MQTT to turn on/off the light and the last subscription command to update the status. Switching the light works using the OpenHAB2 interface, however, if I switch the light using a different source, OpenHAB2 receives the status update but does not change the GUI to reflect this.

The OpenHAB2 log shows the following:
[ItemCommandEvent ] - Item ‘Light_Bedroom’ received command OFF
[ItemStateChangedEvent ] - Light_Bedroom changed from ON to OFF

So OpenHAB2 is receiving the update but this is not reflected in the GUI. What am I missing? Do I have to define a rule?

Thanks in advance

Which UI?

There is currently a known issue in BasicUI where it is not refreshing and showing updates. I don’t know if this is also the case with ClassicUI.

The phone Apps tend to be pretty reliable these days.

Both actually. I’ve done another test since posting, It looks like the log entries I posted were for the ones I instigated through the interface. I checked again after doing it from the other source, i.e. the built-in button and nothing registered in the log.

Using the MQTT client software I subscribed to the switch topic and I get the following:

mosquitto_sub -u user -P pass -t stat/BSwitch/1/LIGHT/
On
Off
On
Off

<[broker:stat/BSwitch/1/LIGHT/state:state:default]

Could something be wrong with the syntax in the line above?

The only thing that stands out is in mosquitto_sub you subscribed to stat/BSwitch/1/LIGHT/ but in the binding config you subscribe to stat/BSwitch/1/LIGHT/state.

I removed the /state and now the openhab.log file shows
[b.core.events.EventPublisherDelegate] - given new state is NULL, couldn’t post update for ‘Light_Bedroom’

Progress. OH is reading the messages now.

You might need to use “ON” and “OFF” in all caps or use a MAP transform to map “On” to “ON” and “Off” to “OFF”.

You are absolutely right. I created a simple MAP file, installed the MAP extension, modified the mqtt command from

<[broker:stat/BSwitch/1/LIGHT/state:state:default]
to
<[broker:stat/BSwitch/1/LIGHT/state:state:MAP(BSwitch.map)]

and now it’s working perfectly even in the new interface :smile:

Thank you very much indeed

But i think there is an issue with the Basic UI, i would like someone to confirm.

i am using proper mapping, i am using the read state as well in case the command did not reach the node (i.e if the node receives the command and turns on the light, it sends a feedback on a different topic path).

i was able to generate a radio comm loss (i.e command did not reach node), logically, after the i hit the switch, it turns on momentarily and should jump back to OFF since it did not receive the ON value on the feed back topic.

this works on a mobile app (android), but i needed to refresh the page on Basic UI in order to get the correct status of the switch

Hi did you solve this problem?