I have these two automations to open lights after sunset till before sunrise with a motion sensor and close them after 7 minutes without movements, but they are not triggered… no opne lights and no close them after 7 minutes… Why?
- alias: Accendi Luce Studio
initial_state: true
trigger:
- platform: sun
event: sunset
offset: '+00:30:00'
- platform: state
entity_id: binary_sensor.motion_sensor_158d0001ddac9e
to: 'on'
condition:
- condition: sun
before: 'sunrise'
action:
- service: homeassistant.turn_on
entity_id: light.philips_studio
data:
scene: 1
transition: 12
- service: homeassistant.turn_on
entity_id: light.yeelight_rgb_7811dcdc133c
data:
brightness: 150
rgb_color:
- 255
- 255
- 194
transition: 600
- alias: Spegni Luce Studio
initial_state: true
trigger:
platform: state
entity_id: binary_sensor.motion_sensor_158d0001ddac9e
to: 'off'
for:
minutes: 7
condition:
- condition: sun
before: 'sunrise'
action:
service: homeassistant.turn_off
entity_id:
- light.philips_studio
- light.yeelight_rgb_7811dcdc133c
I think you need to change at least homeassistant.turn_on to light.turn_on, same for turn_off.
You may also want to look into the trigger/condition, looks to me the first automation triggers only when motion sensor on before sunrise, the trigger sunset and condition sunrise is crossing over midnight would confuse HA.
Your trigger is odd to me. I think this would work better… just my opinion. There are many ways to do this, this is one option:
- alias: Accendi Luce Studio
initial_state: true
trigger:
- platform: state
entity_id: binary_sensor.motion_sensor_158d0001ddac9e
to: 'on'
condition:
condition: or
conditions:
- condition: sun
after: 'sunset'
after_offset: "00:30:00"
- condition: sun
before: 'sunrise'
The problem with your trigger is that it will not trigger at night because of your condition before sunrise. 7 pm is not before sunrise.
So you need to have an ‘or’ condition. saying before sunrise OR after sunset. Time in home assistant resets at midnight, hence why you have to use OR and not AND.
Yes, it’s working but as I wrote in another thread I have my automation.yaml not validated also if it seems all automations are working… I posted my fully automations.yaml so please give a look at it and try to check where is the error also if yamlint.com says it’ valid.