Updating a MQTT Thing

Okay, I have a H801 LED Light strip Controller flashed with Tasmota. I am using it to control a CW/WW LED light strip.

I have the MQTT thing setup as:

Thing mqtt:topic:sonoff-vanity "Sonoff Xmas Front Bed" (mqtt:broker:Mosquitto) @ "MQTT"  {
      Type switch : PowerSwitch "Switch"        [ stateTopic="stat/sonoff-vanity/POWER",
                                                  commandTopic="cmnd/sonoff-vanity/POWER", on="ON", off="OFF" ]
      Type number : CT "Color Temperature"      [ stateTopic="tele/sonoff-vanity/STATE", transformationPattern="JSONPATH:$.CT",
                                                  commandTopic="cmnd/sonoff-vanity/CT", min=153, max=500]
Number vanity_CT "Shanna Vanity CT" (sonoff-vanity) {channel="mqtt:topic:sonoff-vanity:CT"}

Now here’s the issue. It’s the stateTopic. With stateTopic of tele/sonoff-vanity/STATE that means when the H801 first gets power, after a few minutes–and every 5 or so minutes there after–it will public a tele topic with various information in the message and vanity_CT will get updated. So after reboot and a few minutes, openhab knows the state of the H801 color temperature.

Now let’s suppose someone updates the color temperature outside of openhab. Either via the H801’s web interface, it’s api, or whatever. In that case the H801 publishes a stat/sonoff-vanity/RESULT message that containts the current color temperature.

Can I code the “thing” so that it listens to multiple MQTT topics for the same value? Is there another way to do this?

Because if I listen for the tele update, that will guarantee that after update, it will after a few minutes get the current state. But has the side effect that if the current state is updated outside of openhab, it will always take a few minutes for openhab to be aware of the updated state.

But if I listen for the stat topic, then I will get immediate updates when the color temp is updated outside of openhab, but on reboot of the H801 I will not learn it’s current status until it has been updated via openhab or a different mechanism.


No, but you can use persistence and restoreOnStartup

No but you could create onr channel for stat one channel for tele and have the item linked to both channels

1 Like

Persistence and restoreOnStartup works for if openhab reboots, yes? It wouldn’t help if the H801 reboots.

How do you link two channels into one item? Can you give an example?

If I have to choose, I’m leaning towards listening for the tele/sonoff-vanity/STATE. This is because there will be an attached momentary switch that will power the lights on or off. But those give a stat/sonoff-vanity/POWER ON response. Which has it’s own mqtt thing and item. So it will get updated immediately when someone uses the switch.

Other than that, I don’t plan on implementing any “outside of openhab” controls for this device. So adjusting the dimmer or color temp will be done by openhab, so there will be no need to update those items.

Now if I setup some outside controls (using my own outside script, and the http API of tasmota, then I might look for stat/sonoff-vanity/RESULT instead (of course using the proper transformationPattern=“JSONPATH:$.CT”, to parse the returned JSON result string).

Switch MyItem { channel="xxxxxxxx", channel="xxxxxx" }
1 Like