MQTT Sensor to return installed firmware version in Sonoff

I am trying to make a sensor that returns the current installed firmware in my Sonoff that is flashed with Tasmota.

I am using this:

  - platform: mqtt
    name: "Coffee Maker Firmware"
    state_topic: "stat/sonoff2/STATUS2"
    value_template: "{{ value_json.StatusFWR.Version }}"

It creates the sensor but it comes up as unknown. What am I doing wrong?

The code is perfectly fine to read out the firmware version. But how do you plan to get your Sonoff to post information to that topic? As fas as I remember Sonoff does not publish that information without someone requesting it.

If I go to the console in the web interface it seems to be constantly going through the statuses… In any case, if I need to make a request then how do I do that?

You could publish a message to cmnd/sonoff2/status with the payload 2.

So would that be included in the sensor above or in the switch I have configured or it it seperate altogether?

It’s separate. It may be the best to include that in an automation to request that information on a regular base. Please try it manually first to make sure the topic I suggested is correct.

May I ask why it is important to know the firmware version?

Just so I know if I am running the latest version.

Are you able to give me an automation to do this? I really only need it to check once a day and display it in a sensor as per the above sensor.

I’m just a bit lost with MQTT - it’s a dark art to me. Lol. I got the switches working just by following guides. I also followed a guide for the sensor above but don’t really know how to make the sonoff publish to it.

OK! I went into the Developer Tools MQTT and executed your suggested topic above and the payload of 2 and the sensor is now showing the version!

You can use the below automation to get the currently installed version:

- alias: Query Tasmota version
  id: 'query_tasmota:version'
  trigger:
    platform: time
    at: '00:30:00'
  action:
    - service: mqtt.publish
       data:
         topic: 'cmnd/sonoff2/status'
         payload: '2'

If you have multiple sonoff devices just add multiple service blocks in that automation and just change the topic, e.g.:

- alias: Query Tasmota version
  id: 'query_tasmota:version'
  trigger:
    platform: time
    at: '00:30:00'
  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/sonoff3/status'
         payload: '2'

PS: You need multiple mqtt sensors to display the results if you query multiple device versions…

1 Like

Thanks for that!

Also chatted with Tinkerer on Discord. His suggestion was slightly different for the automation. Here’s what I am using:

- id: 'sonoff_firmware_installed'
  alias: Sonoff Firmware Installed
  trigger:
    - platform: time
      at: '00: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"

I already had the 2 sensors defined.

Thanks again.

Tinkerer is right, it should be data, not data_template. I copied the code from one of my automation and did not notice I hadn’t removed it. It’s fixed now. Glad you’ve found what you needed :slight_smile:

1 Like

Man this is annoying I spent a few hours getting this right myself a few weeks back. It your fault for posting how to get the current firmware release which gave me inspiration. I have now done for ha, podcast and my mikrotik routers about to do for my ubnt next.

1 Like