Sonoff Tasmota latest firmware sensor?

I note on the Tasmota github that:

Bonus - Update Notification: @smadds also publishes the latest released version number to a publicly available MQTT server which may be subscribed to at sonoff.maddox.co.uk:1883 with the topic sonoff-version. No authentication needed.

I’m at a bit of a loss as to how to add this as a sensor to my configuration.yaml?

1 Like

mosquitto_sub -h sonoff.maddox.co.uk -t ‘#’
gives v5.14.0

Maybe as a command-line sensor.

will that command work on hassio?

I’m on hassbian, not sure how command-line sensor works on hassio, sorry.

Ok from SSH this works:

mosquitto_sub -h sonoff.maddox.co.uk -t sonoff-version

I’ll try and setup a command line sensor

Tried this:

# Sonoff Firmware Version
  - platform: command_line
    command: "mosquitto_sub -h sonoff.maddox.co.uk -t sonoff-version"
    name: Sonoff Firmware Version
#    scan_interval: 86400
    value_template: '{{ value }}'

I’m only getting a -
same as when I didn’t use a value template.
I am seeing a sensor.sonoff_firmware_version but it’s showing as unknown

Checked the log:
Command failed: mosquitto_sub -h sonoff.maddox.co.uk -t sonoff-version

For what it’s worth, this works for me:

  - platform: command_line
    name: tasmota_version
    command: "mosquitto_sub -h sonoff.maddox.co.uk -t '#' -C 1"

image

I had added the C1 - I’m just trying that now. It didn’t like the # before but it works from ssh so I’ll try now.

Command failed: mosquitto_sub -h sonoff.maddox.co.uk -t ‘#’ -C 1

Then probably that narrowed down to the difference between hassbian vs hassio in handling the command in command-line sensor which is beyond me.

Thanks. It’s just weird it works from the command line and also in the terminal

Does anyone on the day shift have any idea about this?

mosquitto_sub is not available in the hass.io docker container.
When you ssh to hassio, you’re in a terminal of the host, not the container.

So is there any other way I can do this?

Played a little with curl and cut.
This works in hassio on a ubuntu 16.04 server.

  - platform: command_line
    name: "Latest Tasmota"
    command: "curl -s https://github.com/arendst/Sonoff-Tasmota/releases/latest | cut -d'\"' -f2 | rev | cut -d'/' -f1 | rev"
    scan_interval: 600

Don’t know if this works in the future.

Wow! Well that works for now anyway. Thanks. Hopefully they don’t change the URL.

Tried this on my Pi just running stretch to try and understand the command (also so if the path changes or something like that I can try and fix it myself if I understand it - I’m a linux noob for the most part) and it does not like the cut -d’"’ - says the cut -d can only have 1 character. cut -d’"’ works though.

Also tried it from ssh on resinos (hassio) Pi and same error.

Just curious why it works when I put it in the command as you show it here?

So I found out that Hassio strips the \ out.

Not sure, was trial and error. :slightly_smiling_face:
The backslash in the command_line sensor was because of the doublequotes at the beginning and the end.

Yeah all good. I ended up putting it in a script and was able to take out the . When I ran the command from SSH it didn’t like it (invalid for cut) but it worked in HomeAssistant as it apparently strips out the \ according to @Tinkerer and @Syssi