I have an automation that sets my thermostat target temperature based on a schedule with different temps for schedule on and off (In the code below, the target temperature is 17/7 in on/off)
alias: livingroom_set_temp_scheduled
description: Set livingroom thermostat to on and off temps
trigger:
- platform: state
entity_id: schedule.thermostat_schedule_livingroom
action:
- service: climate.set_temperature
target:
entity_id: climate.lumi_lumi_airrtc_agl001_thermostat_2
data:
temperature: >-
{{ iif(trigger.to_state.state == 'on', 17, 7) }}
hvac_mode: heat
mode: single
I am trying to edit this so that the target temp for the schedule âonâ periods is read from an input_number (input_number.schedule_target_temp_livingroom
) and that the device target temperature updates when the corresponding input button (input_button.set_schedule_temp_livingroom
) is pressed
I have tried the following:
alias: livingroom_set_temp_scheduled
description: Set livingroom thermostat to on and off temps
trigger:
- platform: state
entity_id: schedule.thermostat_schedule_livingroom
action:
- service: climate.set_temperature
target:
entity_id: climate.lumi_lumi_airrtc_agl001_thermostat_2
data:
temperature: >-
{{ iif(trigger.to_state.state == 'on',
states('input_number.schedule_target_temp_livingroom'), 7) }}
hvac_mode: heat
- if:
- condition: state
entity_id: input_button.set_schedule_temp_livingroom
state: "on"
then:
- service: climate.set_temperature
target:
entity_id: climate.lumi_lumi_airrtc_agl001_thermostat_2
data:
temperature: >-
{{ iif(trigger.to_state.state == 'on',
states('input_number.schedule_target_temp_livingroom'), 7) }}
hvac_mode: heat
mode: single
But this only updates the target temperature at the next schedule switch from off to on.
Any suggestions as to the best way to update the target temperature in this scheduled automation?
From the above I suspect that what you actually want is as follows:
alias: livingroom_set_temp_scheduled
description: Set livingroom thermostat to on and off temps
trigger:
- platform: state
entity_id: schedule.thermostat_schedule_livingroom
variables:
t_state: "{{trigger.to_state.state}}"
- platform: state
entity_id: input_button.set_schedule_temp_livingroom
variables:
t_state: 'on'
action:
- service: climate.set_temperature
target:
entity_id: climate.lumi_lumi_airrtc_agl001_thermostat_2
data:
temperature: >-
{{ iif(t_state == 'on', states('input_number.schedule_target_temp_livingroom'), 7) }}
hvac_mode: heat
mode: single
Thanks @Didgeridrew . I tried what you suggested, but it gave a malformed data error. I changed the second trigger statement from a condition: state
declaration to a platform:state
declaration and this updates the target temperature. However, the behaviour is not quite as I want, because it also updates the target temperature when the schedule is âoffâ.
What I am trying to do is:
- if schedule is off thermostat target temp is fixed at 7.
- if schedule is off, and input_button is pressed, target temp remains at 7 until the next time that schedule is on and then target temp is set at the value of
schedule_target_temp_livingroom
at the time of input_button press
- if schedule is on, and input_button is pressed, update
input_button.set_schedule_temp_livingroom
to the value of schedule_target_temp_livingroom
the time of input_button press
To block the button from doing anything while the schedule is âoffâ, you can add a condition to check that the t_state
variable is the same as the scheduleâs state.
alias: livingroom_set_temp_scheduled
description: Set livingroom thermostat to on and off temps
trigger:
- platform: state
entity_id: schedule.thermostat_schedule_livingroom
variables:
t_state: "{{trigger.to_state.state}}"
- platform: state
entity_id: input_button.set_schedule_temp_livingroom
variables:
t_state: 'on'
condition:
- "{{ is_state('schedule.thermostat_schedule_livingroom', t_state) }}"
action:
- service: climate.set_temperature
target:
entity_id: climate.lumi_lumi_airrtc_agl001_thermostat_2
data:
temperature: >-
{{ iif(t_state == 'on', states('input_number.schedule_target_temp_livingroom'), 7) }}
hvac_mode: heat
mode: single
1 Like