MQTT switch state_topic

Hi,

I have an issue with controlling Sonoff Tasmota firmware patch Sonoff POW socket.

The following code based on official example works.

- platform: mqtt
  name: "Stoves Fan"
  state_topic: "stat/stove-fan/POWER"
  command_topic: "cmnd/stove-fan/POWER"
  optimistic: false
  qos: 1
  payload_on: "ON"
  payload_off: "OFF"
  retain: true

But, if Home Assistant reboots when the switch is ON, the rebooted instance sees it as OFF, because state stat/stove-fan/POWER is sent only when the state changes.

Because the POW sends telemetry every 5 minutes. I would like use that telemetry as well.

14:47:55 MQT: stat/stove-fan/RESULT = {"POWER":"OFF"}
14:47:55 MQT: stat/stove-fan/POWER = OFF
14:51:24 MQT: tele/stove-fan/STATE = {"Time":"2017-11-12T14:51:24", "Uptime":3, "Vcc":3.116, "POWER":"OFF", "Wifi":{"AP":2, "SSId":"XXX", "RSSI":60, "APMac":"XXX"}}
14:51:24 MQT: tele/stove-fan/ENERGY = {"Time":"2017-11-12T14:51:24", "Total":1.922, "Yesterday":0.228, "Today":0.176, "Period":1, "Power":0, "Factor":0.00, "Voltage":0, "Current":0.000}

And use tele/stove-fan/STATE with POWER information.

I have tried:

- platform: mqtt
  name: "Stoves Fan"
  state_topic: "tele/stove-fan/STATE"
  value_template: '{{value_json.POWER}}'
  command_topic: "cmnd/stove-fan/POWER"
  optimistic: true #has to be true, otherwise it will not switch ON
  qos: 1
  payload_on: "ON"
  payload_off: "OFF"
  retain: true

Now, I have changes from HA and in maximum 5 min, the initial state… but I loose immediate notifications when I switch it manually of.

Is there any way how to subscribe to multiple state topics?

The normal way to fix that is to set the retain flag when the message is sent from the sonoff. This causes the broker to store the message, and then send it whenever a client subscribes to the topic, such as when HA restarts.

1 Like