Automation help please ? Twilight hours

I have this “new” improved automation which isn’t working at all.
I had a previous working version (below) but was trying to refine it so that the lights would come on in the hours of darkness, rather than just up to midnight which is what appeared to be happening…

Any hints gratefully received.
Krispii

  alias: Front Door
  trigger:
  - entity_id: binary_sensor.0x00158d00031dfcac_contact
    from: 'off'
    platform: state
    to: 'on'  
conditions:
  conditions and: # 'twilight' condition: dusk and dawn, in typical locations
  - condition: state
    entity_id: sun.sun
    state: 'below_horizon'
  - condition: state
    entity_id: light.tristate_08000a_10
    state: 'off'
  action:
  - data:
      entity_id: group.front_door
    service: homeassistant.turn_on
  - delay: '300'
  - data:
      entity_id: group.front_door
    service: homeassistant.turn_off

I changed this from:

  alias: Front Door
  trigger:
  - entity_id: binary_sensor.0x00158d00031dfcac_contact
    from: 'off'
    platform: state
    to: 'on'
  condition:
  - after: sunset
    after_offset: -01:00:00
    condition: sun
  - condition: state
    entity_id: light.tristate_08000a_10
    state: 'off'
  action:
  - data:
      entity_id: group.front_door
    service: homeassistant.turn_on
  - delay: '300'
  - data:
      entity_id: group.front_door
    service: homeassistant.turn_off

The conditions went wrong

  condition: 
    condition: and
    conditions:
    - condition: state
      entity_id: sun.sun
      state: 'below_horizon'
    - condition: state
      entity_id: light.tristate_08000a_10
      state: 'off'

Thank you - thank you!!

For future reference, the default for multiple conditions is and, so this would also work:

  condition:
  - condition: state
    entity_id: sun.sun
    state: 'below_horizon'
  - condition: state
    entity_id: light.tristate_08000a_10
    state: 'off'

Thank you - much appreciated.

Sometimes I can’t see the wood for the trees.

All good! They both work, just figured I’d share. Saves some typing and potential nesting confusion.

Also, “can’t see the wood for the trees” is an expression I haven’t heard before. Had to look it up. So you also shared something, albeit unintentionally.

1 Like