I think the YAML gui editor automatically removes all comments (which might be a bug or a conscious decision, I don’t known)
Here is a slightly different take on the automation:
alias: Office Fan
description: ''
trigger:
# Run on any temp change
- platform: state
entity_id: sensor.office_temperature
# Run after off time to turn off fan
- platform: time
at: '18:00:01'
# Run at the start of the window to turn on fan if temp over temp
- platform: time
at: '08:00:01'
action:
# Check if we are in the running time window
- choose:
# If we are w/in the running time window
- conditions:
- condition: time
after: '08:00:00'
before: '18:00:00'
weekday:
- mon
- tue
- wed
- thu
- fri
sequence:
# Check the temperature
- choose:
# If we are over our min temp
- conditions:
- condition: numeric_state
entity_id: sensor.office_temperature
above: '75'
sequence:
# Turn on fan to desired level based on temp
- service: fan.set_percentage
entity_id: fan.office_fan_fan
data:
percentage: >
{% if states('sensor.office_temperature') | float >= 78
%} 100 {% elif states('sensor.office_temperature') |
float > 76 %} 77 {% elif
states('sensor.office_temperature') | float > 76 %} 50
{% else %} 25 {% endif %}
default: # Turn off fan if we are under temp
service: fan.turn_off
entity_id: fan.office_fan_fan
default: # Turn off fan if we are outside of the time window
service: fan.turn_off
entity_id: fan.office_fan_fan
mode: single
initial_state: true
It is the first complicated automation I’ve written, but I believe it should do the following.
Turn the fan on/off when it’s inside/outside of the time window (w/o waiting for a temp change)
Set the temp during the time window based on the temp, via the template from above.
If I am interpreting the examples above that include the time correctly, they include a condition on the time, so they won’t turn the fan off at the end of the day, just leave it at the current setting.