Activate scene after sunset/before sunrise

Hi everyone,
I’ve tried searching and using a few examples i’ve seen, but don’t seem t be having any joy.
I want the scene to activate when the front door is opened after sunset and before sunrise. I can get it to work with one condition, just not the two.

Can anyone see where i’ve gone wrong here?

- id: '1610228555942'
  alias: Front Door
  description: ''
  trigger:
  - type: opened
    platform: device
    device_id: f7cdcce75867ca6eb2f6a003ae9332e7
    entity_id: binary_sensor.front_door_sensor_contact
    domain: binary_sensor
  condition:
  - condition: or
    conditions:
    - condition: sun
      before: sunrise
      after: sunset
  action:
  - scene: scene.door_open
  mode: single

You need to change the condition:

condition:
  - condition: or
    conditions:
    - condition: sun
      before: sunrise
    - condition: sun
      after: sunset

1 Like

Many thanks for that, just adjusted my template and will try that shortly!

Just another quick question, would it be simple to only have the scene activate for 5 minutes and then turn back off?

You can put a delay of 5 minutes in the actions and then turn the scene off…

  - delay: '00:05:00'
  <than turn your scene off of what ever you want>
1 Like

You can also use the condition this way:

condition:
    condition: state 
    entity_id: sun.sun
    state: 'below_horizon'
2 Likes

Thank you for that. Was just having a look and can see the option in the actions to add the delay, however the only other action is to activate a scene. Is is a case of creating a scene where the lights are off and call that?

This is my Front Door Off scene

- id: '1601644599423'
  name: Front Door Open
  entities:
    light.color_temperature_light_1_2:
      friendly_name: Hallway 1
      state: 'off'
    light.color_temperature_light_2_2:
      friendly_name: Hallway 2
      supported_features: 43
      state: 'off'
    light.color_temperature_light_1_3:
      friendly_name: Hallway 3
      state: 'off'
    light.color_temperature_light_2_3:
      friendly_name: Hallway 4
      state: 'off'

and my new altered automation:

- id: '1610228555942'
  alias: Front Door
  description: ''
  trigger:
  - type: opened
    platform: device
    device_id: f7cdcce75867ca6eb2f6a003ae9332e7
    entity_id: binary_sensor.front_door_sensor_contact
    domain: binary_sensor
  condition:
  - condition: or
    conditions:
    - condition: sun
      before: sunrise
    - condition: sun
      after: sunset
  action:
  - scene: scene.door_open
  - delay: 00:05:00
  - scene: scene.front_door_off_delay
  mode: single

Scene can only be turned on… So you have to define two scenes where the state of your elements have to be documented… So why are you adding “friendly name” and “supported features” in your scene ?.. “state” is enought to define the state of the elements/entities after the scene has run…

- id: '1601644599423'
  name: Front Door Open
  entities:
    light.color_temperature_light_1_2:
      state: 'off'
    light.color_temperature_light_2_2:
      state: 'off'
    light.color_temperature_light_1_3:
      state: 'off'
    light.color_temperature_light_2_3:
      state: 'off'

As I read the documentation about scene, you have to use the service “service: scene.turn_on” and then the name of your scene

  action:
    - service: scene.turn_on
      entity_id: scene.door_open
    - delay: '00:05:00'
    - service: scene.turn_on
      entity_id: scene.front_door_off_delay

“door_open” and “front_door_off_delay” are the names of your two scenes…

I used the automation section of HA to create what I had in my previous post. Seems to be working spot on so far!

1 Like