I built out two (it was three or four) automations for my desired light behavior that seemed to be working properly but today there were on mid-day indicating they’re not working as I’d hoped.
Goal: I’d like my exterior front lights to come on 25% at sunset and then off at 2:00am. I would also like them to increase brightness to 100% when motion is detected for 3min and then go back to the 25% if no other motion is detected.
My first attempt was an automation to have them turn off and then another one to have them turn off. I then combined them into one single automation that worked. All positive steps in creating my first automations w/HAOS. Here’s the code for the automation I created to turn lights on/off:
alias: Front Lights On @ Sunset & Off @ 2:00am
description: ""
triggers:
- trigger: sun
event: sunset
offset: 0
id: When the sun sets
- trigger: time
at: "02:00:00"
id: When the time is equal to 2:00am
conditions: []
actions:
- choose:
- conditions:
- condition: trigger
id:
- When the sun sets
sequence:
- action: light.turn_on
metadata: {}
data:
brightness_pct: 25
target:
device_id: 1b497669b9bcf217c8292530c38c558f
- conditions:
- condition: trigger
id:
- When the time is equal to 2:00am
sequence:
- action: light.turn_off
metadata: {}
data: {}
target:
device_id: 1b497669b9bcf217c8292530c38c558f
mode: single
Note: the above was taken from the yaml file but I used only the UI to create the automation. I’m only just now getting into yaml editing in my dashboard edits but figured this was the best way to share it with others.
I then created a 2nd automation for the motion part I described above. Here’s the code from that:
alias: Front Lights 100% for 3min on Motion
description: ""
triggers:
- trigger: state
entity_id:
- binary_sensor.porch_g4_bullet_person_detected
to: "on"
id: motion_on
- trigger: state
entity_id:
- binary_sensor.porch_g4_bullet_person_detected
to: "off"
for:
hours: 0
minutes: 3
seconds: 0
id: motion_off
conditions:
- condition: device
type: is_on
device_id: 1b497669b9bcf217c8292530c38c558f
entity_id: 20ea4b702db0471a4b5a0d0379b08fc4
domain: light
actions:
- choose:
- conditions:
- condition: trigger
id:
- motion_on
sequence:
- type: turn_on
device_id: 1b497669b9bcf217c8292530c38c558f
entity_id: 20ea4b702db0471a4b5a0d0379b08fc4
domain: light
brightness_pct: 100
- conditions:
- condition: trigger
id:
- motion_off
sequence:
- type: turn_on
device_id: 1b497669b9bcf217c8292530c38c558f
entity_id: 20ea4b702db0471a4b5a0d0379b08fc4
domain: light
brightness_pct: 25
mode: single
I guess I’m looking for either 1) some assistance to make a small tweak to my code to correct whatever was causing it to come on outside of the designated time window or not allowing it to turn off at the end of said window or 2) a cleaner set of code that would all of this more efficiently in a single automation that I could replace both of these with.
Thanks!