So I got the idea of automating my ceiling fan to turn on when:
Immediately if the bedtime scene is called and temp is above a threshold
10 minutes If the temp climbs above a threshold for X minute. This is to prevent power cycling if the thermostat (ecobee via homekit) jumps for just a minute or two.
What I came up with is:
- alias: 'Fan Control On'
initial_state: false
trigger:
- platform: numeric_state
entity_id: climate.bedroom_local
value_template: "{{ state.attributes.current_temperature }}"
above: 68 # Don't forget to change this in the condition below as well
for: # Duplicated so we can condition with a for: clause
hours: 0
minutes: 10
seconds: 0
- platform: event
event_type: call_service
event_data:
service_data:
entity_id: [ scene.get_ready_for_bed]
domain: scene
condition:
condition: numeric_state
entity_id: climate.bedroom_local
above: 68 # A second time for when the scene vent is called
value_template: "{{ state.attributes.current_temperature }}"
action:
service: fan.set_speed
entity_id: fan.bedroom_fan
data:
speed: low
This only partially works. If I comment out the condition it will work when the scene is called. So I suspect my problems are with the condition to check the temperature, most likely something to do with value_template however I’m stumped as to what syntax is off here.
Curious if anyone else looking at this sees a potential issue or has an idea why this condition is causing it to fail.
If I comment out condition the service call trigger works, so the common denominator seems to be:
- platform: numeric_state
entity_id: climate.bedroom_local
value_template: "{{ state.attributes.current_temperature | int }}"
above: 68 # Don't forget to change this in the condition below as well
platform/condition obviously depending on where it’s used.
NOTE
The screenshot above indicates current_temperature is 67 so that’s too low to satisfy the condition. For testing purposes, don’t overlook to reduce the value in the template.
In hopes that this thread could help someone else, here’s roughly what I ended up with:
scene:
- name: "Get Ready For Bed"
icon: "mdi:Bed"
entities:
automation.fan_control_on:
state: on
automation.fan_control_off:
state: on
- name: "Good Morning"
icon: "mdi:sun"
entities:
automation.fan_control_on:
state: off
automation.fan_control_off:
state: off
fan.bedroom_fan:
state: off
automation:
# Turn on as it gets warm
- alias: 'Fan Control On'
initial_state: false
trigger:
- platform: template
value_template: "{{ state_attr('climate.bedroom_local', 'current_temperature') | int > 68 }}"
for:
minutes: 0
- platform: event
event_type: call_service
event_data:
service_data:
entity_id: [ scene.get_ready_for_bed]
domain: scene
condition:
condition: template
value_template: "{{ state_attr('climate.bedroom_local', 'current_temperature') | int > 68 }}"
action:
service: fan.set_speed
entity_id: fan.bedroom_fan
data:
speed: low
# Turn off if it cools down
- alias: 'Fan Control Off'
initial_state: false
trigger:
platform: template
value_template: "{{ state_attr('climate.bedroom_local', 'current_temperature') | int < 67 }}"
for:
hours: 0
minutes: 10
seconds: 0
action:
service: fan.set_speed
entity_id: fan.bedroom_fan
data:
speed: off
# If the fan is manually turned off, don't touch it (trust the human).
- alias: 'Fan Control Override'
initial_state: true
trigger:
platform: state
entity_id: fan.bedroom_fan
from: "on"
to: "off"
action:
- service: automation.turn_off
entity_id: automation.fan_control_off
- service: automation.turn_off
entity_id: automation.fan_control_on
Brief explanation:
The scene (get ready for bed) turns on these automations. If the temperature is above the threshold when the scene is set or at some point overnight the fan will turn on. If it drops the fan will turn off.
If the fan is manually turned off, the automations will be disabled until the get ready for bed scene is re-run. The good morning automation will disable the whole thing.
If the template I suggested resolved your original question, please mark my post (above) with the Solution tag. It will automatically place a check-mark next to the topic’s title and signal to others that this topic has an accepted solution. In addition, a link will appear below your first post that leads to the solution. All of this helps others find answers to similar questions.