Sonoff 6.4 firmware and status

Hi. I just updated to v6.40 of Tasmota firmware on my Sonoff.

I normally use an automation:

- id: 'sonoff_firmware_installed'
  alias: Sonoff Firmware Installed
  initial_state: 'on'
  trigger:
    - platform: time
      at: '00:00:00'
    - platform: time
      at: '12:00:00'
    - platform: homeassistant
      event: start
  action:
  - service: mqtt.publish
    data:
      topic: cmnd/sonoff1/status
      payload: "2"
  - service: mqtt.publish
    data:
      topic: cmnd/sonoff2/status
      payload: "2"
  - service: mqtt.publish
    data:
      topic: cmnd/sonoff5/status
      payload: "2"

that returns the firmware version and in config yaml, I define sensors like this:

  - platform: mqtt
    name: "Coffee Maker Firmware"
    state_topic: "stat/sonoff1/STATUS2"
    value_template: "v{{ value_json.StatusFWR.Version }}"
  - platform: mqtt
    name: "Toothbrush Firmware"
    state_topic: "stat/sonoff2/STATUS2"
    value_template: "v{{ value_json.StatusFWR.Version }}"
  - platform: mqtt
    name: "Garage Door Firmware"
    state_topic: "stat/sonoff5/STATUS2"
    value_template: "v{{ value_json.StatusFWR.Version }}"

But all my sensors are coming up as unknown now…

I also added these automations as per sonoff website:

- id: 'SonoffMQTTAuto'
  alias: "Enable MQTT discovery for all devices"
  trigger:
    platform: homeassistant
    event: start
  action:
    - service: mqtt.publish
      data:
        topic: "cmnd/sonoffs/SetOption19"
        payload: "1"
    - service: mqtt.publish
      data:
        topic: "cmnd/sonoffs/SetOption55"
        payload: "1"
- id: 'SonoffPowerState'
  alias: "Power state on HA start-up"
  trigger:
    platform: homeassistant
    event: start
  action:
    - service: mqtt.publish
      data:
        topic: "cmnd/sonoffs/state"
        payload: ""

Weird thing also is that my switches do not show up in the MQTT integration - I resetup the integration and MQTT broker (hass.io) but nothing under integrations.

what the console of the sonoff saying

Not much lol!!

Well it’s as chatty as buggery but nothing useful.

Seems they made some changes. https://github.com/arendst/Sonoff-Tasmota/wiki/Home-Assistant
I am using discovery and I changed the abovestat/sonoff1/STATUS2 to sonoff1/stat/STATUS2 and cmnd/sonoff1/status to sonoff1/cmnd/status

I also see for discovery they say you need SetOption19 and SetOption55 On which I have done, as well as adding their suggested automations on that page…

So the switches are working fine. My only problem is that if I restart Home Assistant, the switch on the lovelace card is showing as OFF even though it is ON and TasmoAdmin says it it on.

Tried the usual of:
switchretain off
buttonretain off
poweronstate 3
powerretain on
But still does it.

I have these settings now:

  - platform: mqtt
    name: "Coffee Maker Firmware"
    state_topic: "sonoff1/stat/STATUS2"
    value_template: 'v{{ value_json.StatusFWR.Version | replace("(sonoff)", "") }}'
  - platform: mqtt
    name: "Toothbrush Firmware"
    state_topic: "sonoff2/stat/STATUS2"
    value_template: 'v{{ value_json.StatusFWR.Version | replace("(sonoff)", "") }}'
  - platform: mqtt
    name: "Garage Door Firmware"
    state_topic: "sonoff5/stat/STATUS2"
    value_template: 'v{{ value_json.StatusFWR.Version | replace("(sonoff)", "") }}'
binary_sensor:
  - platform: template
    sensors:
      sonoff_update_available:
        value_template: >-
          {{ (states.sensor.sonoff_firmware_version_available.state > states.sensor.toothbrush_firmware.state) or (states.sensor.sonoff_firmware_version_available.state > states.sensor.coffee_maker_firmware.state) or (states.sensor.sonoff_firmware_version_available.state > states.sensor.garage_door_firmware.state)
              }}

and automations:

- id: 'sonoff_firmware_installed'
  alias: "Sonoff Firmware Installed"
  initial_state: 'on'
  trigger:
    - platform: time
      at: '00:00:00'
    - platform: time
      at: '12:00:00'
    - platform: homeassistant
      event: start
  action:
  - service: mqtt.publish
    data:
      topic: sonoff1/cmnd/status
      payload: "2"
  - service: mqtt.publish
    data:
      topic: sonoff2/cmnd/status
      payload: "2"
  - service: mqtt.publish
    data:
      topic: sonoff5/cmnd/status
      payload: "2"
- id: 'Poweronstate'
  alias: "Power State Sonoff on HA Start-Up"
  initial_state: 'on'
  trigger:
    - platform: homeassistant
      event: start
  action:
  - service: mqtt.publish
    data:
      topic: "cmnd/sonoffs/power1"
      payload: ""
  - service: mqtt.publish
    data:
      topic: "cmnd/sonoffs/power2"
      payload: ""
  - service: mqtt.publish
    data:
      topic: "cmnd/sonoffs/Power3"
      payload: "" 
  - service: mqtt.publish
    data:
      topic: "cmnd/sonoffs/power4"
      payload: ""
  - service: mqtt.publish
    data:
      topic: "cmnd/sonoffs/state"
      payload: ""
- id: 'SonoffMQTTAuto'
  alias: "Enable MQTT discovery for all devices"
  initial_state: 'on'
  trigger:
    - platform: homeassistant
      event: start
  action:
  - service: mqtt.publish
    data:
      topic: "cmnd/sonoffs/SetOption19"
      payload: "1"
  - service: mqtt.publish
    data:
      topic: "cmnd/sonoffs/SetOption55"
      payload: "1"
  - service: mqtt.publish
    data:
      topic: "cmnd/sonoffs/SwitchRetain"
      payload: "0"
  - service: mqtt.publish
    data:
      topic: "cmnd/sonoffs/ButtonRetain"
      payload: "0"
  - service: mqtt.publish
    data:
      topic: "cmnd/sonoffs/PowerOnState"
      payload: "3"
  - service: mqtt.publish
    data:
      topic: "cmnd/sonoffs/PowerRetain"
      payload: "1"

also tried this in the MQTT in dev-tools:

cmnd/sonoffs/state

with no payload and it did nothing… still showing off after a restart. Going to leave it for 5 mins now to see if it resyncs or not…

EDIT: It came on after a minute or so… maybe I need to be more patient - but it never had this with <6.30 firmware.

I think that “powerretain on” does not work with discovery.

However you can setup an automation ss mentioned in the tasmota wiki and here to force the device to publish the state:

You can setup an automation for every device to get the state back on restart.

You can also wait a few minutes because the tasmota devices will send the status every X minutes.

I also tried to switch to discovery yesterday but I think I will go back.

Yeah so I did follow this doc here https://github.com/arendst/Sonoff-Tasmota/wiki/Home-Assistant which is up-to-date and as per above I did create the automations.

I have had no issues with PowerRetain at all with 6.30 and discovery.

So a few more things I discovered…

NOTE: These comments relate to firmware 6.4x

When you switch on discovery, Tasmota automatically changes the Topic to %topic%/%prefix%/

It was also suggested to me to try:
NOTE: Turn OFF Discovery before resetting otherwise you will end up with duplicate switches probably!

reset 5

Which retains SSID but not much else and so I did that and reconfigured the switches with the following commands:

reset 5

Setup MQTT Settings, Config->MQTT

MQTT
Set Host ip
User entered HA user I made for MQTT
Password for HA MQTT user
Topic sonoffX

Set the Friendly Name in Config->Other
Friendly Name 1
sonoffX-XXXX

Set TimeZone

TimeZone 99
TimeDST 1,1,10,1,1,660
TimeSTD 1,1,4,1,2,600

Fix Switches turning on/off randomly

switchretain off
buttonretain on
buttonretain off
poweronstate 3
powerretain on

Switches on MQTT Discovery

SetOption19 On
SetOption55 On

Set Dry Contact Relay 2" turnoff for my Sonoff SV Garage Opener

PulseTime 20

If you didn’t turn off discovery before resetting, you can fix the duplicates by deleting the MQTT broker and removing the integration, restarting HA and adding them back again.

Still it seems that no matter what I do, the switch takes a couple of minutes to sync it’s state with HA when it restarts even though I have the suggested automations.

I am hoping the reset will stop the WiFi dropping in and out all the time and causing the switches to flash for a few seconds.