Home Assistant not knowing the states of switches/plugs after startup

I’m having an issue where Home Assistant doesn’t know about the state of some of my tasmota plugs or switches when it reboots. I’ve tried several things I’ve found in searching the forums and elsewhere. Is there something wrong with my configuration?

Here’s one of the plugs that I’m having trouble with. It is supposed to turn off and back on power to the cable modem if the Internet goes down, so it should pretty much always be on.

  - platform: mqtt
    name: "Cable Modem"
    command_topic: "cmnd/TeckinModem/POWER"
    state_topic: "stat/TeckinModem/POWER"
    qos: 1
    payload_on: "ON"
    payload_off: "OFF"
    retain: false

I also ran PowerRetain 1 in the plug console

Here is the automation that I’ve added that is supposed to sync the states of my tasmota devices at startup.

- id: 'sync tasmota'
  alias: Tasmota Restore State at Startup
  trigger:
    platform: homeassistant
    event: start
  action:
  - service: mqtt.publish
    data:
      payload: ''
      topic: cmnd/sonoffs/state

When it does run, I do see the plug respond in its console, but it’s state doesn’t update in HA.

14:29:43 MQT: stat/TeckinModem/RESULT = {"Time":"2020-10-04T14:29:43","Uptime":"15T09:39:19","UptimeSec":1330759,"Vcc":3.447,"Heap":30,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":30,"MqttCount":5,"POWER":"ON","Wifi":{"AP":1,"SSId":"5m@77-273","BSSId":"F2:9F:C2:71:14:30","Channel":6,"RSSI":100,"Signal":-28,"LinkCount":3,"Downtime":"0T00:02:07"}}

Is there anything I’m doing wrong? I’m running hassio with HA 0.114.0, and the tasmota version of that particular plug is 8.1.0

i had te same problem. in my configuration. yaml i put

retain: false 

and on the sonoffs i did:

switchretain off
buttonretain on
buttonretain off
powerretain on

and it seems ok now, i had the info from here: https://www.youtube.com/watch?v=31IyfM1gygo&t=472s

2 Likes

the /RESULT topic response is in JSON. You need to extract just the POWER setting from the list, and use the /RESULT topic (ie - not /POWER topic which is just for the command, not the state ):

    name: "Cable Modem"
    command_topic: "cmnd/TeckinModem/POWER"
    state_topic: "stat/TeckinModem/RESULT"
    state_value_template: "{{value_json.POWER}}"

Awesome! I think that did it. I had to change it to

value_template: "{{value_json.POWER}}"

Thanks!

ah of course, my mistake. state_value_template is for mqtt lights, value_template is for switches