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