Automations with Entity values

Trying to set the value of a number entity, in my case: number.radiator_mette_bedroom_eco_temperature

The value should be retrieved from a input_number:

input_number.mette_radiator_dag_temp

Here is my yaml:

service: number.set_value

data:

value:'{{ (states('input_number.mette_radiator_dag_temp'))|int }}'

target:

entity_id: number.radiator_mette_bedroom_eco_temperature

It doesnt seem to work

If I replace ‘{{ (states(‘input_number.mette_radiator_dag_temp’))|int }}’ with a string like ‘5’, everything works fine and number.radiator_mette_bedroom_eco_temperature will change to the value 5

Using Developer tools Templates, it seems like '{{ (states(‘input_number.mette_radiator_dag_temp’)) }} returns ‘5’

That is not indented correctly. It should be:

- service: number.set_value
  data:
    value:"{{ states('input_number.mette_radiator_dag_temp')|int(0) }}"
  target:
    entity_id: number.radiator_mette_bedroom_eco_temperature

Also be careful with quotes. You need to use two kinds (double and single, like my example above) or you end up with opening and closing quotes like this:

value:'{{ (states('

Also I added a default value for the |int filter (this will be mandatory soon) and removed some extraneous brackets.

1 Like

Thank you very much for your comments.
This solved my problem, I didn’t realize the quote issue about opening and closing, thanks for bringing this to my attention (it seems like I forgot to use my brain here).
The quote issue was actually everything I needed, the spacing was actually already correct.

Not in your post it want. Spacing is very important in yaml. If you want us to be able to help you, you need to preserve the spacing in your pasted code.

Also do not overlook this:

In the very near future your templates will not be loaded if you do not do this and the int filter fails to convert a state to a number.

1 Like

A post was split to a new topic: Template concatenation error