Tasmota’s power state is not published as a retained message on mqtt by default.
As a result, if say a light bulb was on and openhab is (re)started, openhab won’t know that the light is on.
My current solution is to add a state
channel + item on my tasmota .things / .items file as such:
Thing mqtt:topic:mosquitto:front_porch_light "Front Porch Light" (mqtt:broker:mosquitto) {
Channels:
Type switch : power "Power" [ stateTopic="stat/front_porch_light/RESULT", transformationPattern="JSONPATH:$.POWER", commandTopic="cmnd/front_porch_light/POWER" ]
Type dimmer : dimmer "Dimmer" [ stateTopic="stat/front_porch_light/RESULT", transformationPattern="JSONPATH:$.Dimmer", commandTopic="cmnd/front_porch_light/Dimmer" ]
Type string : reachable "Reachable" [ stateTopic="tele/front_porch_light/LWT" ]
Type number : rssi "Wifi Signal Strength" [ stateTopic="tele/front_porch_light/STATE", transformationPattern="JSONPATH:$.Wifi.RSSI" ]
Type string : state "State" [ stateTopic="tele/front_porch_light/STATE", commandTopic="cmnd/front_porch_light/STATE" ]
}
Group gTasmota
Switch Front_Porch_Light_Power "Porch Light Power" <switch> (gTasmota) ["Switchable"] { autoupdate="false", channel="mqtt:topic:mosquitto:front_porch_light:power" }
Dimmer Front_Porch_Light_Dimmer "Porch Light Dimmer" <dimmer> ["Lighting"] { channel="mqtt:topic:mosquitto:front_porch_light:dimmer" }
String Front_Porch_Light_Reachable "Reachable: [%s]" <contactable> { channel="mqtt:topic:mosquitto:front_porch_light:reachable" }
Number Front_Porch_Light_RSSI "WiFi Signal Strength [%d %%]" <wifi> { channel="mqtt:topic:mosquitto:front_porch_light:rssi" }
String Front_Porch_Light_State "State" { channel="mqtt:topic:mosquitto:front_porch_light:state" }
And created a rule:
import org.eclipse.smarthome.model.script.ScriptServiceUtil
rule "Poll Tasmota device status on startup"
when
System started
then
gTasmota.allMembers.forEach[ item |
val baseName = item.name.split("_Power").get(0)
val stateItem = ScriptServiceUtil.getItemRegistry.getItem(baseName + "_State")
stateItem.sendCommand("")
]
end
This will send an MQTT message cmnd/xxxx/STATE
thus getting Tasmota to respond with stat/xxxx/RESULT
, which will get picked up by the corresponding _Power and _Dimmer items.
Once the MQTT Action bug has been fixed (hoping it will be in 2.5M2), I will change this to using MQTT Action rather than having a separate channel / item.
Does anyone have a better solution?