h4nc
November 12, 2018, 8:06am
1
Hi,
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?)
gpbenton
(Graham)
November 12, 2018, 8:51am
2
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?
gpbenton
(Graham)
November 12, 2018, 12:15pm
4
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
https://www.hivemq.com/blog/how-to-get-started-with-mqtt
h4nc
November 12, 2018, 1:55pm
5
Great advice, thanks.
I use this in my configuration to listen to the lwt topic.
in configuration.yaml
binary_sensor:
- platform: mqtt
name: "Poolsteuerung LWT"
state_topic: "tele/sonoff_poolsteuerung/LWT"
payload_on: 'online'
payload_off: 'offline'
- platform: template
sensors:
sonoff_lwt_group:
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'
trigger:
platform: state
entity_id: binary_sensor.sonoff_lwt_group
to: 'on'
action:
- service: notify.ios_xxxx
data:
message: "Sonoffs offline!"
1 Like
gpbenton
(Graham)
November 12, 2018, 2:14pm
6
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.
trigger:
platform: mqtt
topic: tele/+/LWT
payload: 'offline'
h4nc
November 12, 2018, 3:20pm
8
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.
gpbenton
(Graham)
November 12, 2018, 3:42pm
9
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?
gpbenton
(Graham)
November 12, 2018, 4:46pm
11
No, the message is sent by the broker, when it detects that the sonoff has disconnected unexpectedly.
h4nc
November 12, 2018, 5:04pm
12
gpbenton:
jinja
I don’t know what this is? Could you explain it?
gpbenton
(Graham)
November 12, 2018, 5:06pm
13
Jinja is what is behind the templating engine in HA.