Is there a way to send a notification when any sensor (15+ sensors, mostly Xiaomi) goes ‘unavailable’ or ‘unknown’, that is for whichever reason it goes offline, without writing automations for each individual sensor?
I searched the forum and tried to find a solution with for loops in template sensor, but I didn’t really get anywhere.
Thanks for the link, that looks good, I now understand I would probably need only a couple of automations.
I think Xiaomi sensors go ‘unavailable’, but my MQTT sensors go ‘unknown’ for example.
And do binary sensors also have an ‘unavailable’ state?
It would still be good to have a general way to do it, so when I add a new sensor I don’t need to remember to add it to the automation list.
Something like this pseudocode:
for sensor in sensors:
if sensor.state == 'unavailable' or sensor.state == 'unknown':
notify sensor.name 'is' sensor.state
I’ve just noticed that one of my two xiaomi hubs has been offline for a day.
I’m using the nmap device tracker to track various devices, but the downside with that is it only checks every 10 minutes. And I can’t find a state for the actual hub integration itself…
This appears as binary_sensor.xiaomi_gateway in Home Assistant and you can create automations to check if they’re online or not (state is either ‘on’ or ‘off’). Or just check the UI periodically.
For anyone using appdaemon, I made this script for the same purpose:
I haven’t had any devices run out of power yet, but I tested it with a light, and it seems to work as intended.
All the self.battery_levels are template sensors (search for “# Sensor Batteries” in my sensors.yaml file if you want to copy those) getting the battery state of the corresponding entity in self.battery_powered_devices.
I have it create a sensor (sensor.unavailable_devices) where the state shows if any on that list are unavailable/unknown, and puts a list of all in the attribute “devices” (if there’re a lot, it’s probably some other issue; they are unlikely to all run dry at the same time). You could use that sensor in the frontend if you want. I also have it send a notification.