Automation to check lights if they got turned on else send an iOS notification

- id: Outdoor light ON when sunset
  alias: Outdoor Sunset
  trigger:
    platform: numeric_state
    entity_id: sun.sun
    value_template: '{{ state.attributes.elevation }}'
    below: -4.0
  condition:
    platform: state
    entity_id: group.group_lights # CHANGE THIS WITH YOUR GROUP
    state: off
  action:
    service: notify.notify # CHANGE THIS WITH YOUR NOTIFY SERVICE. ARE YOU INCLUDING THE NOTIFICATION SERVICE OF YOUR DEVICE?
    data:
      ...

Would you show the trigger part of the automation? What you do to trigger the iOS notification actions?

If I understand the situation, you want notification if some lights did not turn on for some reason, right?

First, a simple state trigger to off using group.group1_lights will not work, because if any of group1 light is on, group1 has state=on, even if one or more lights in group1 is off.
Second, even if the state trigger is based on individual light, not group, if the light never turn on, the state to off trigger will never fires, because the light state never changed.

You may want to try instead a time trigger like every 15 minutes within an hour after sunset, and use condition to see if any light is off.

Alternatively, you can use the group’s state changing from: off to: on as a trigger and use the sunset as a condition. This might suit you better perhaps.

But then I am sure if I am understanding your problem correctly.

Edit: No, this wouldn’t work because you wanted to be notified when the lights did NOT turn on. So refer to my first example. That might work?

With this I will have to create an automation for each Outdoor Light Group right?

Yes, or create another group consisting of all the lights in all groups. You can also list more than one group separated by commas ,

Well, I was wondering, maybe I should just ask all the bulbs at once and then if just one bulb is off, then I should get the notification with an action to run the sunset automation again.
I’ve only come across this a few times, and every time I fire the sunset rule manually, the last bulbs turns on.

I just don’t know how to cycle all the bulbs through in a good way?

Did you intentionally remove the service: notify section in the code? Because, as far as I know, without you mentioning the service, HA won’t know what to notify.

Yeah I removed that. I’ve other notifications running, so I’m pretty confident with that part - but we’ll spotted :slight_smile:

You can use a time trigger to check every X minutes.
Use the sun as condition.
And then fire your notify action(s)? This should do the trick?

Yes, but how do I go through all the bulbs. In your example I only look for the state of the group of the bulbs. Otherwise I should use the same example and the just list all bulbs with comma separation right?

You can use the or condition?

condition:
  condition: or
  conditions:
    - condition: state
      entity_id: 'light.light_1'
      state: off
    - condition: state
      entity_id: 'light.light_2'
      state: off

You can either go through the bulbs individually as shown above, or add them to a group and check the group’s state. Choice is up to you.

More info here.

Lovely, I’m glad I only have 20 GU10’s at the moment :slight_smile:.

Would it be possible to throw the light name of the ones that are not turned on in the message that gets pushed?

Hmm, I am pretty sure it is possible but I don’t know how to populate the notification message dynamically. My HA knowledge is intermediate at best :slight_smile:

You can however create 20 separate automations (one for each light) and fire a notification as soon as they go off after sunset.

By the way, just to be clear on the trigger, what is your trigger exactly?

  • Notify me if lights are not on after sunset?
  • Notify me if lights are not on after sunset OR they switch off after sunset?

I will just trigger when the sun is below - 5.

I was thinking I might would be able to get the names somehow, like when an alarm gets triggered and it provides the sensor names:

{{ states[states.alarm_control_panel.house.attributes.changed_by.split(".")[0]][ states.alarm_control_panel.house.attributes.changed_by.split(".")[1]].name }}'

I’m just not smart enough to figure out how to do something similar to get the names of the Bulbs.

Look at the end of this post… @petro is definitely awesome at this kind of stuff…

Exactly! I will try to see if I can figure it out. Thanks!

All you have to do is create a group called ‘all_doors’ and that template automation will work without doctoring it. You just need to make sure all items in the group either have one of the 4 following states: ‘on’, ‘off’,‘open’,‘closed’.

Well, I was only showing the alarm thing with door sensors as an example. I still want to check whether the light bulbs are ‘off’ and then list them in a notification. Because if the automation detecs any lights that still are on, then I want to press a button that will be shown along with the notification and fire back my sunset automation, so that the light will be turned on again.

Brilliant!
Pedro - worked like a charm!