fix an issue where fan never gets turned off

This commit is contained in:
2025-07-05 13:57:39 +00:00
parent 99220e5db5
commit 28a69cd3d2

View File

@ -61,7 +61,6 @@ trigger:
- platform: state - platform: state
entity_id: !input bathroom_lights entity_id: !input bathroom_lights
to: 'off' to: 'off'
for: !input time_fan_stays_on_after_lights_off
- platform: time_pattern - platform: time_pattern
minutes: "/5" minutes: "/5"
@ -69,22 +68,22 @@ condition: []
action: action:
- choose: - choose:
# Turn fan on when any light turns on
- conditions: - conditions:
- condition: template - condition: template
value_template: > value_template: >
{{ trigger.platform == 'state' and {{ trigger.platform == 'state' and trigger.to_state.state == 'on' }}
trigger.to_state.state == 'on' }}
sequence: sequence:
- delay: !input delay_after_light_on - delay: !input delay_after_light_on
- service: fan.turn_on - service: fan.turn_on
target: target:
entity_id: !input fan_entity entity_id: !input fan_entity
# Turn fan off after all lights have been off for a duration
- conditions: - conditions:
- condition: template - condition: template
value_template: > value_template: >
{{ trigger.platform == 'state' and {{ trigger.platform == 'state' and
trigger.to_state.state == 'off' and
expand(inputs.bathroom_lights) | selectattr('state','eq','on') | list | count == 0 }} expand(inputs.bathroom_lights) | selectattr('state','eq','on') | list | count == 0 }}
sequence: sequence:
- delay: !input time_fan_stays_on_after_lights_off - delay: !input time_fan_stays_on_after_lights_off
@ -92,6 +91,7 @@ action:
target: target:
entity_id: !input fan_entity entity_id: !input fan_entity
# Periodic cadence run
- conditions: - conditions:
- condition: template - condition: template
value_template: > value_template: >
@ -104,4 +104,3 @@ action:
- service: fan.turn_off - service: fan.turn_off
target: target:
entity_id: !input fan_entity entity_id: !input fan_entity