Dear community,
I’m trying to write the helper script, which is only update the state of the entity, if it is not yet in this state.
(I do that by the way to prevent thermostats turning on the backlight in the night, each time the automation changes the target temperature).
I’ve defined the script like that:
script:
set_heater_target_temperature:
sequence:
- if:
- condition: template
value_template: "{{ not is_state_attr(entity_id, 'temperature', temperature) }}"
then:
- service: climate.set_temperature
target:
entity_id: script.entity_id
data:
temperature: script.temperature
hvac_mode: heat
And call manually for testing it like that:
service: script.set_heater_target_temperature
data:
entity_id: climate.floor_heating_front_thermostat
temperature: 27 | float
The call fails with the console message:
Failed to call service script.set_heater_target_temperature. expected float for dictionary value @ data['temperature']. Got None
Okey, so it want a float. No problem, I convert value to the float like with temperature | float
:
script:
set_heater_target_temperature:
sequence:
- if:
- condition: template
value_template: "{{ not is_state_attr(entity_id, 'temperature', temperature | float) }}"
then:
- service: climate.set_temperature
target:
entity_id: script.entity_id
data:
temperature: script.temperature
hvac_mode: heat
Now the service call passes, but still not work. In Logs I see the following warning:
Error in 'if[0]' evaluation: In 'template' condition: ValueError: Template error: float got invalid input '27 | float' when rendering template '{{ not is_state_attr(entity_id, 'temperature', temperature | float) }}' but no default was specified
What do I wrong?