I want to change an entity value in a state trigger automation. The automation works as expected when the new value is supplied as a hard-coded number. But I want to use an input_number for the new value instead. So this is the automation I created:
alias: Increase PW reserve
description: Increase backup reserve to upper threshold during IO slots
trigger:
- platform: state
entity_id:
- binary_sensor.octopus_intelligent_slot
to: "on"
condition: []
action:
- service: number.set_value
data:
value:
{{ states('input_number.pw_upper_reserve') | float }}
target:
entity_id: number.poplar_house_backup_reserve
mode: single
But the automation fails, the trace showing:
Stopped because an error was encountered at 6 November 2023 at 23:30:01 (runtime: 0.01 seconds)
expected float for dictionary value @ data['value']
I had tested my value template in developer tools and it does return the value I want.
Now when I go to look at the automation again, it reads as follows:
alias: Increase PW reserve
description: Increase backup reserve to upper threshold during IO slots
trigger:
- platform: state
entity_id:
- binary_sensor.octopus_intelligent_slot
to: "on"
condition: []
action:
- service: number.set_value
data:
value:
"[object Object]": null
target:
entity_id: number.poplar_house_backup_reserve
mode: single
The new value in my template has been silently changed from a template to a null object. Saving the automation produced no error message, but I think it should have.
I since found some forum posts where it’s stated that you can’t use a template in a state trigger automation. Obviously I didn’t realise this and still can’t see it stated anywhere in the documentation. I don’t understand why this restriction exists but I don’t want to go into that. I just want to know: is there a correct way - or indeed any way - to achieve my objective of using an input number in a state trigger automation?