Hi all! I have a bit of a problem that I can’t seem to figure out. I have a bunch of notifications setup to push to the HA app that work well, but one thing I can’t make with is having HA send me a notification when one of my Hue lights goes into an ‘unavailable’ state. I want to do this to monitor power loss to the house (my modem/router/HA is on a UPS, so provided I still have internet it will still give me push notifications).
I’ve tried going through the Automations section in HA, and here is what I think should work, but it doesn’t:
- id: '1579549722854'
alias: Power Loss
description: ''
trigger:
- entity_id: light.hue_color_lamp_1
platform: state
to: unavailable
condition: []
action:
- data:
message: Power Loss
service: notify.mobile_app_sm_n960u
I know the Hue lights go into a state called ‘unavailable’ (without apostrophe) when there is power cut by unscrewing the bulb. Normally, they are either ON or OFF otherwise, more or less remaining accessible by the hub. Does anyone have any ideas on why it isn’t working, ideas on how to get it to work, or anything else? I think this would be the simplest way to monitoring my house mains power while remote, but I just can’t seem to get it.
Find the automation on the STATES tab of the Developer Tools page. It should be called automation.power_loss. Click the “more info” button to the left of it (it will look like an “i” in a circle.) Is the automation turned on? If not, click the toggle button to turn it on. Also, try clicking the EXECUTE button. That should make the action run (and you should see the notification.)
If you get the notification when you click the EXECUTE button, and the automation is turned on, it should work. You can test it by clicking on light.hue_color_lamp_1 in the list on the STATES page, then at the top of the page, change the state to unavailable, then click SET STATE. That should cause the automation to trigger.
For ultimate hardware simplicity, a mains down sensor can be made with just a 3V wall wart and gpio. Alternatively if you don’t have GPIO (ie venv/pc), you can add a small arduino in between and use the serial sensor platform (that’s what I did but on a pi, because I needed to measure ac doorbell current as well with a hall sensor). So many ways to skin this cat…
Thanks for the replies, all. I did a little tweaking, and one of the smallest things is what bit me in the rear (a time for how long it should be out before notifying me). Here is the YAML of what I used that I found works:
- id: '1579549722854'
alias: Power Loss
description: ''
trigger:
- entity_id: light.hue_color_lamp_1
for: 00:02:00
platform: state
to: unavailable
condition: []
action:
- data:
message: Power Loss
service: notify.mobile_app_sm_n960u
Turns out this was the easiest way to do it with my setup without adding additional code or peripherals, since it just uses the stock Automation options with my lights I currently have. The time delay to notify me also helps because, as it turns out, the Hue hub device appears do to a ‘soft’ reboot on itself occasionally, which throws all the lights into an ‘unavailable’ state which could lead to some confusion (the soft reboot appears to be less than a minute). Either that, or my hub is bad, but I have a few more to play with. At the very least, hopefully my YAML will help other Hue owners who want to use their lights as an indicator for power loss as well. Obviously if you want to use the code, you’ll have to use your own device ID, entity ID, and device for notifications.