Help: lights turn on after sunset

Currently with this automation, the front light turn on when I arrive home via a motion sensor. I also want the lights in the living room to turn on, but only after sunset.

- alias: 'motion genkan light on'
  trigger:
    platform: state
    entity_id: binary_sensor.motion_genkan_occupancy
    to: 'on'
  condition:
  - condition: or
    conditions:
      - condition: state
        entity_id: input_boolean.eri_home
        state: 'on'
      - condition: state
        entity_id: input_boolean.duc_home
        state: 'on'
  action:
    - service: script.welcome_notify   
    - condition: state
      entity_id: light.h_1
      state: 'off'
    - service: light.turn_on
      entity_id: light.h_1
      data:
        brightness: 200
  action:
    - service: script.turn_on  # doing it this way the script runs in parallel and thus the next actions don't have to wait for the script to complete. Could seem a bit faster depending on your script length.
      entity_id: script.welcome_notify   
    - service: light.turn_on  # no need for the light off condition before this. Turning the light on if it is already on does nothing
      entity_id: light.h_1
      data:
        brightness: 200
    - condition: state # turn the living room lights on if after sunset. If you add this in the condition block instead it would also apply to the outside lights. Why do you want the outside light on in the day time?
      entity_id: sun.sun
      state: below_horizon
    - service: light turn_on
      entity_id: light.your_living_room_lights

See here for an explanation about waiting for scripts to complete: https://www.home-assistant.io/integrations/script/#waiting-for-script-to-complete

Thank you for polishing up the script. It’s not actually an outside light but a light right after you enter the house. There is no window and it is quite dark during the day. Japanese call it a genkan.

1 Like