From a7274f605394e6cc0d36d42f9822c923f736d5cd Mon Sep 17 00:00:00 2001 From: rzen Date: Sun, 6 Jul 2025 16:49:44 -0400 Subject: [PATCH] fix an issue with an input template --- fan-cadence.yaml | 50 ++++++++++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/fan-cadence.yaml b/fan-cadence.yaml index 05b9b21..04be358 100644 --- a/fan-cadence.yaml +++ b/fan-cadence.yaml @@ -1,8 +1,7 @@ blueprint: name: Fan Cadence with Light Check description: > - Runs a fan on a cadence every X minutes. - Turns it off after Y seconds unless any of the specified lights are on. + Turns on a fan every X minutes for Y seconds, but keeps it on if any selected lights are on. domain: automation input: fan_entity: @@ -12,8 +11,8 @@ blueprint: domain: fan interval_minutes: - name: Fan Activation Interval (minutes) - description: How often to turn the fan on + name: Interval (minutes) + description: How often to start the fan cycle default: 15 selector: number: @@ -22,8 +21,8 @@ blueprint: unit_of_measurement: minutes duration_seconds: - name: How Long to Keep Fan On (seconds) - description: How long the fan stays on before trying to turn it off + name: Fan On Duration (seconds) + description: How long the fan stays on each cycle default: 60 selector: number: @@ -33,33 +32,42 @@ blueprint: override_lights: name: Override Lights - description: Fan will not be turned off if any of these lights are on + description: Fan will not turn off if any of these lights are on selector: entity: domain: light multiple: true trigger: - - platform: time_pattern - minutes: "/{{ iif(interval_minutes | int > 0, interval_minutes, 15) }}" + - platform: homeassistant + event: start + - platform: time + at: "00:00:00" # ensures automation starts at midnight if HA is already running variables: fan: !input fan_entity lights: !input override_lights + interval: !input interval_minutes + duration: !input duration_seconds condition: [] action: - - service: fan.turn_on - target: - entity_id: "{{ fan }}" - - delay: - seconds: !input duration_seconds - - condition: template - value_template: > - {{ lights | map('states') | select('eq', 'on') | list | length == 0 }} - - service: fan.turn_off - target: - entity_id: "{{ fan }}" + - repeat: + while: [] + sequence: + - service: fan.turn_on + target: + entity_id: "{{ fan }}" + - delay: + seconds: "{{ duration }}" + - condition: template + value_template: > + {{ lights | map('states') | select('eq', 'on') | list | length == 0 }} + - service: fan.turn_off + target: + entity_id: "{{ fan }}" + - delay: + minutes: "{{ interval }}" -mode: parallel +mode: restart