Sonoff tasmota online state


is there a way to follow the state of the tasmota. I have several tasmota and some of them go offline sometimes and need a manual restart.

I’d like to make an automation that notifies my when a sonoff goes offline.
What is the best way to do this? (Do I need to make a new sensor for every sonoff?)

Strangely enough, I am going through this with someone else in another thread.

I think you should be able to use the LWT message to run a script. Does your tasmota set a LWT message, and which broker are you using?

What does LWT mean?

It stands for Last Will and Testament.

When the client connects it sends a will message to the broker. If the client disconnects unexpectedly, the broker sends the message to all clients subscribed to that topic.

You can get HA to listen for the topic in an automation, and send a notification.

There is a brief description about LWT in this introduction to MQTT

Great advice, thanks.

I use this in my configuration to listen to the lwt topic.

in configuration.yaml

  - platform: mqtt
    name: "Poolsteuerung LWT"
    state_topic: "tele/sonoff_poolsteuerung/LWT"
    payload_on: 'online'
    payload_off: 'offline'

  - platform: template
        value_template: >-
          {{ is_state('binary_sensor.tasmota1_lwt', 'off') 
              or is_state('binary_sensor.tasmota2_lwt', 'off')                  
              or is_state('binary_sensor.tasmota3_lwt', 'off') }}

And this in automation.yaml

- alias: Sonoff - Offline Warnung
  initial_state: 'on'
    platform: state
    entity_id: binary_sensor.sonoff_lwt_group
    to: 'on'
    - service: notify.ios_xxxx
        message: "Sonoffs offline!"
1 Like

I can trigger an automation directly from the MQTT message, there is no need for the sensor if you do not need it elsewhere.

This, I think, would trigger off all the Sonoff LWT messages.

    platform: mqtt
    topic: tele/+/LWT
    payload: 'offline'

This is better, thanks!

Also for some reason this

 value_template: >-
          {{ is_state('binary_sensor.tasmota1_lwt', 'off') 
              or is_state('binary_sensor.tasmota2_lwt', 'off')                  
              or is_state('binary_sensor.tasmota3_lwt', 'off') }}

does not work when I set all my sonoffs.

Would be nice to have one status field that indicates whether all devices are on or offline.

I think I would just put all the binary sensors in a group, and then look at the state of the group. I avoid jinja as much as possible.

1 Like

Hello. I’m testing this but have one question. I understand that the LWT will be send by the tasmota if it disconnects from the WIFI right?

No, the message is sent by the broker, when it detects that the sonoff has disconnected unexpectedly.

I don’t know what this is? Could you explain it?

Jinja is what is behind the templating engine in HA.