Hi, I have a simple use case but struggling to get it right:
- one room with a temperature sensor
- one space heater on a smart plug
I want to keep the room at a configurable temperature, I use an input number helper for the target temperature: input_number.bedroom_target_temperature
.
then I have automation to turn on the heater whenever the room temperature is below the target(which works fine):
alias: turn on heater
description: ""
trigger:
- platform: numeric_state
entity_id: sensor.mi_temp_1_temperature
below: input_number.bedroom_target_temperature
action:
- type: turn_on
device_id: xxx
entity_id: switch.plug_1_outlet
domain: switch
mode: single
I don’t want the heater to turn on/off too frequently so I’d like it to turn off whenever the temperature reached target+0.2
:
alias: turn off heater
description: ""
trigger:
- platform: template
value_template: >-
{{states('sensor.mi_temp_1_temperature') | float(0) -
states('input_number.bedroom_target_temperature') | float(0) > 0.2 }}
action:
- type: turn_off
device_id: xxx
entity_id: switch.plug_1_outlet
domain: switch
mode: single
I tried this template in the dev UI, it’s been giving me the correct boolean.
But this turn off automation always give me errors like:
2022-10-09 23:08:59.532 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'homeassistant.util.read_only_dict.ReadOnlyDict object' has no attribute 'state' when rendering '{{ state.attributes.state.value }}'
2022-10-09 23:08:59.535 WARNING (MainThread) [homeassistant.components.homeassistant.triggers.numeric_state] Error in 'websocket_api' trigger: In 'numeric_state' condition: template error: UndefinedError: 'homeassistant.util.read_only_dict.ReadOnlyDict object' has no attribute 'state'
I’ve also tried Numeric state trigger with value_template and not working out, since I’m using the state number not a attribution number.
This should be a pretty common use case I assume. Let me know where went wrong, thanks!