Sunset offset

Quick question, I want a condition that is true one hour before sunset until one hour after sunrise.

Not sure if I used the offsets right

  condition:    
    - condition: or
      conditions:
        - condition: sun
          after: sunset
          after_offset: "-01:00:00"          
        - condition: sun
          before: sunrise
          before_offset: "01:00:00"

Looks right to me.

1 Like

Sorry for waking up this old thread but can someone tell me why this automation is newer triggered?

- alias: Turn auto lights on early
  trigger:
    platform: numeric_state
    entity_id: sensor.dark_sky_cloud_coverage
    above: 70
  condition:
    condition: and
    conditions:
    - condition: state
      entity_id: input_boolean.auto_lights
      state: 'off'
    - condition: or
      conditions:
      - condition: sun
        after: sunset
        after_offset: '-2:00:00'
      - condition: sun
        before: sunrise
        before_offset: '+1:00:00'
  action:
  - service: input_boolean.turn_on
    data:
      entity_id: input_boolean.auto_lights
  - service: notify.pushbullet
    data:
      message: Det verkar vara molnigt, så jag slår på den rörelsestyrda belysningen
        tidigt!
      title: Hass.io

It will only trigger when sensor.dark_sky_cloud_coverage changes. Most triggers only respond when the entity, or one of the entities, referenced changes state.

Also in the case of the numeric state trigger, once it has triggered, it won’t trigger again until the entity’s numeric value does not meet the condition (in this case changes to a value of 70 or below), and then changes again to a value that does meet the condition (above 70.)

How would you do a automation like this? A time pattern trigger?

Depends what you want. Think about what events should cause the actions to run. Do you want them to run when some entity changes state? When some time rolls around? When HA restarts? …? Triggers are event based, so you have to think about what events should cause the actions to run. I.e., they control when the actions should run. The conditions control if the actions should run (when one of the trigger events occurs.)

I’ll add, although sometimes it makes sense to use a time pattern trigger, in almost all cases that is the wrong way to do it.

I know.

I have two automations, one that turns lights at sunset and one that should turn lights on two hours before sunset if it is cloudy.