Trigger light on motion at Sunset only

Hi, I was wondering if someone could help me understand how to get the light to only trigger and Sunset, and stay off during sunrise? I have tried adding Condition, but I’m not sure why it does’t trigger.

I have two seperate automation for On/Off, and I’d prefer if it was possible to condense into a single automation, and be compatibile with the UI.

Light On:

alias: WC On
description: ''
trigger:
  - platform: state
    entity_id: binary_sensor.wc_motion
    to: 'on'
    for:
      hours: 0
      minutes: 0
      seconds: 0
      milliseconds: 0
    from: 'off'
condition: []
action:
  - service: light.turn_on
    target:
      entity_id: light.wc_light
    data:
      brightness: 255
mode: single

Light Off:

alias: WC Off
description: ''
trigger:
  - platform: state
    entity_id: binary_sensor.wc_motion
    to: 'off'
    for:
      hours: 0
      minutes: 0
      seconds: 10
      milliseconds: 0
condition: []
action:
  - service: light.turn_off
    target:
      entity_id: light.wc_light
mode: single

Many thanks.

I have an input_boolean which is “on” at night and “off” during the day. You could use something similar in the condition section of your automations.

The input_boolean could be turned off and on in a number of ways (I use light levels from an outside sensor).

1 Like
alias: WC 
description: ''
trigger:
  - platform: state
    entity_id: binary_sensor.wc_motion
    to: 'on'
    from: 'off'
  - platform: state
    entity_id: binary_sensor.wc_motion
    to: 'off'
    from: 'on'
    for: '00:00:10'
condition:
  - condition: state
    entity_id: sun.sun
    state: 'below_horizon'
action:
  - choose:
      - conditions:
          - "{{ trigger.to_state.state == 'on' }}"
          - "{{ is_state('light.wc_light', 'off') }}"
        sequence:
          - service: light.turn_on
            target:
              entity_id: light.wc_light
            data:
               brightness: 255
      - conditions:
          - "{{ trigger.to_state.state == 'off' }}"
          - "{{ is_state('light.wc_light', 'on') }}"
        sequence:
          - service: light.turn_off
            target:
              entity_id: light.wc_light
mode: single

1 Like

Thanks, works great!

If I wanted to add an offset, should I amend the digits under the same state condition?

Where do you want to add an offset?

Upon Sunset, thanks.