kaws
March 8, 2024, 2:41pm
1
based on my location and time the following condition does not pass. however the automation still works when I test it by physically opening and closing the door.
alias: Downstairs Hallway Closet Light Control
description: ""
trigger:
- platform: state
entity_id:
- binary_sensor.downstairs_hallway_closet_door_sensor_contact
from: "off"
to: "on"
id: DoorOpen
- platform: state
entity_id:
- binary_sensor.downstairs_hallway_closet_door_sensor_contact
to: "off"
id: DoorClosed
from: "on"
condition:
- condition: sun
after: sunset
before: sunrise
after_offset: "-00:30:00"
action:
- choose:
- conditions:
- condition: trigger
id:
- DoorOpen
sequence:
- service: light.turn_on
target:
entity_id: light.downstairs_hallway_light_4
data: {}
- conditions:
- condition: trigger
id:
- DoorClosed
sequence:
- service: light.turn_off
target:
entity_id: light.downstairs_hallway_light_4
data: {}
mode: single
itnassol
(Andrew)
March 8, 2024, 3:10pm
2
Not sure if this will help, but I have a couple of these and I noticed the sunset/sunrise is the other way round, yours is…
from: "on"
condition:
- condition: sun
after: sunset
before: sunrise
after_offset: "-00:30:00"
action:
Mine are…
from: "on"
condition:
- condition: sun
before: sunrise
after: sunset
after_offset: "-00:30:00"
action:
Worth a try?
kaws
March 8, 2024, 3:14pm
3
Still runs
Based on the trace it shouldn’t?
stevemann
(Stephen Mann (YAML-challenged))
March 8, 2024, 3:15pm
4
Make two automations. One for open, one for closed.
Complex, multitrigger, multicondition automations are difficult to write and difficult to diagnose.
1 Like
123
(Taras)
March 8, 2024, 3:37pm
5
The trace shows the automation was triggered, evaluated its condition, and did not execute its actions (because the condition evaluated to false
). It is working nominally, exactly like you designed it to work.
A trace is produced when an automation is triggered and processes its conditions (if any). Your automation is working properly because it didn’t execute its actions (because the current time isn’t between sunset and sunrise).
I’m not sure what you mean by “Still runs” but it obviously has to “run” to process its trigger and condition.
Troon
(Troon)
March 8, 2024, 3:50pm
6
Your original automation can be significantly simplified / shortened:
alias: Downstairs Hallway Closet Light Control
trigger:
- platform: state
entity_id: binary_sensor.downstairs_hallway_closet_door_sensor_contact
condition:
- condition: sun
after: sunset
before: sunrise
after_offset: "-00:30:00"
action:
- service: light.turn_{{ trigger.to_state.state }}
target:
entity_id: light.downstairs_hallway_light_4
1 Like
kaws
March 8, 2024, 4:36pm
7
I’m new to HA. Your code reads what the current state of the device is and will perform the opposite of the current state?
For example, the light is off. Once the automation is triggered HA will read the off state and perform the opposite of that state?
Is using the trigger better than calling a service? I just learned I should call a service for entity actions I want performed in automations.
Troon
(Troon)
March 8, 2024, 5:41pm
8
The automation is triggered by a change to the binary sensor.
The trigger
variable contains both the prior and new state objects of the entity that caused the trigger.
In this case, {{ trigger.to_state.state }}
will be on
or off
, matching the new state of the binary sensor.
So the service call will be light.turn_on
or light.turn_off
.
123
(Taras)
March 8, 2024, 6:42pm
9
When you say “still works” do you mean:
The automation turned on the light when you opened the door even though the sun had not set yet?
The automation did not turn on the light when you opened the door but still created a trace file.
#1 would be abnormal whereas #2 is normal.