Automation Trigger: Sun

Hi Everyone,

So this is a simple one but I can’t see the tree through the forest here. I used a sun example here:

But I changed it recently to be a trigger instead of condition:

- alias: Home-Lights Auto-On
  trigger:
    - platform: sun
      event: sunset
      offset: '-1:30:00'
  condition:
    condition: or
    conditions:
      - condition: state
        entity_id: input_select.chris_status_dropdown
        state: 'Home'
      - condition: state
        entity_id: input_select.val_status_dropdown
        state: 'Home'
  action:
    - service: scene.turn_on
      entity_id: scene.kitchen_bright, scene.bright

For two days now I’ve been monitoring this automation (close to sunset, I’m home by then) and it no longer activates (no logs, no errors, config passes check) but I can’t figure out why. One recommendation on the help page linked above is to use elevation instead of time-based checks but that means I need to figure that out and time is easier (for me.)

When I had this as a condition it worked fine (platform: state, entity_id: sun.sun, state: ‘below_horizon’) but since I moved to a trigger instead, it no longer fires. Anyone see a problem with the above and why it’s not firing? I’m sure it’s something simple but I can’t see the problem.

Thanks!

My set up is pretty much exactly the same, except I don’t use scenes as the action. I’ve combined multiple scenes in a script and fire up the script.

It’s worth mentioning that when you have that as a trigger it only fires once every 24 hours. So if you get home at 1:29:58 before sunset, the automation won’t fire as the specified time has already passed. I would suggest you go back to your conditions being a trigger, and your trigger being a condition.

I can’t see a problem with the trigger so I would suspect the conditions. So at sunset -90mins is at least 1 of the input_selects set to ‘Home’ ? (check in the dev panel - states)

I don’t know if this matters but I have the states as lowercase

home

not_home

2 Likes

@icaman004 Yeah, I may have to. I’ve been home before the event should fire for the last two days and it hasn’t. Clearly I’m going to have to re-jig this one. In this case, the conditions were met 100% (both my wife and I were home; this would still work if only I or she were home, I use this condition a lot.) In this case, it should only trigger once every 24 hours, specifically 1h30m before sunset. The scene part works as I use it in other automations – weird part is it’s not even logged as executing so I know it’s not firing.

@keithh666 Yup, as noted above, both of us were Home and the input_select was set to ‘Home’ - I use this condition quite a lot with success.

@RobDYI See above :slight_smile: case in this case (heh) is correct.

Thanks for the input folks, guess I’ll re-work this one.

Decided to try by elevation instead as it’s seasonally-aware from what I’ve read of the documentation, see how it goes:

- condition: numeric_state
  entity_id: sun.sun
  value_template: '{{ state.attributes.elevation }}'
  below: 3.5

For those automations using sunrise/sunset as conditions, for those using it for triggers:

  trigger:
    - platform: numeric_state
      entity_id: sun.sun
      value_template: '{{ state.attributes.elevation }}'
      below: 3.5

See how this works out :slight_smile:

1 Like

Just a follow-up here. Elevation works like a champ. Using 0.63.1 – needed to tweak the value for WAF approval but otherwise, works as expected. Considering resolved.