Thank you, but I have tons of yeelight and shelly devices and I have to do an automation for each of them. Is here any other way to check unavailability of all the devices in one automation? Like ping every 5 minutes and then notify if a specific device doesn’t reply (the ping it’s just an example )
I personally do not detect when devices go offline, as it happens far to often, but that is do to poor WIFI which will soon be replaced with a better Access Point.
I have now Netgear Orbi RBR50 with 2 satellites and in fact I have more stable WiFi connections compared with old Asus AP. Till now I got no device offline, but just in case I would like to be prepared. Anyway, thank you for your search, I’ll try to implement an unavailable sensor
Hey there. That unavailable sensor gist is mine. I put out an updated version recently and it didn’t work well. Just wanted to make sure you try the right one - the group version. It is the one linked above. I forgot to update the gist until I saw this thread.
Anyway, you should be able to just drop the package in and go! Let me know if you have any issues.
I created a more generic method. Not perfect, but better than adding each device to an automation:
Create a python script “config/python_scripts/device_offline_notification.py” with the following content:
# add here device ids you wan't to ignore
ignore_entities=[
"media_player.821378bb_0f1e4b8e",
"light.821378bb_0f1e4b8e"
]
states=hass.states.all()
offline_devices=[]
for state in states:
if not state.entity_id in ignore_entities:
if state.state == "unavailable":
offline_devices.append(state.entity_id);
if len(offline_devices) > 0:
message = "\n".join(offline_devices)
logger.warn(message)
# in my example, i send a notification via telegram bot
hass.services.call("notify", "max", {
"title": "Devices offline",
"message": message.replace("_", "\_")
})
Create an automation that executes the script:
alias: Notify Device offline
description: ''
trigger:
- platform: time
at: '18:00'
condition: []
action:
- service: python_script.device_offline_notification
mode: single
That’s not really an alternative in my opinion, because it only runs once a day, so it would be possible that your device could in the worst case be offline for almost 24 hours before you get notified. And running it every 5 minutes with a time pattern trigger would be inefficient.
For a more generic approach you can take a look at the gist posted in one of the first posts.
Depending on your needs. For me, its good enough. Some unavailable entites, like my yeelights, which currently stops working randomly (i dont know why…), are a few minutes later available again. I personally don’t want to get notified every minute … But the gist above is definitly worth looking at.
I have tried adapting this to my setup but I’m not receiving the notification.
If I type my own message, eg device offline, then it works. But not working when I use the message body in the example. Can anyone see what’s wrong?
Edit: I was getting the message when using run actions command but not when the device was actually unavailable. I realised it was due to having the state as Unavailable with uppercase U. I changed it to lowercase and it is working now.
if len(offline_devices) > 0:
message = "Devices offline: " + "\n".join(offline_devices)
logger.warn(message)
names = ", ".join([str(hass.states.get(e).attributes.get("friendly_name",e)) for e in offline_devices])
# in my example, i send a notification via telegram bot
hass.services.call("notify", "mobile_app", {
"title": "📵 Devices offline",
"message": names
})