Store the result of a template in a input_number

Hi,
I want to store the result of a template into an input_number.

How can this be done?

´´´
template:

  • sensor:

    name: “bereken_lopende_piek”

    unit_of_measurement: “W”

    state: >

     {% set begin = states('input_number.total_usage_begin') | float %}
    
     {% set lopend = states('input_number.total_usage_lopend') | float %}
    
     {% set kartierpiek = ((lopend - begin) *3600000) | round(1) %}
    

    value_template: “{{kartierpiek}}”
    ´´´

Or how do I call up the result of this template to view it in my dashbord?

Thx
Kevin

Hi @KevinHA1

When you create a template sensor you can add it to a dashboard like any other entity.

so it would mean that if I type: sensor.bereken_lopende_piek, I would be able to add it??

That’s the problem, when I type sensor.b no suggestion is shown, so I cannot do something with the result.
In developer template, the value is calculated, so the code works…

template values are only accessible within the template area themselves. once you leave the scope where the template is rendered the result goes away.

IOW, you can’t use the result of the template in the “state:” scope in the scope of the value_template.

also the new format sensor doesn’t have a “value_template:” as an option. That’s for the legacy format sensor state. the new format uses “state:” as the equivalent.

I think this should work:

template:
  sensor:
    name: "bereken_lopende_piek"
    unit_of_measurement: "W"
    state: >
      {% set begin = states('input_number.total_usage_begin') | float %}
      {% set lopend = states('input_number.total_usage_lopend') | float %}
      {% set kartierpiek = ((lopend - begin) *3600000) | round(1) %}
      {{kartierpiek}}

Also the topic of the thread and that template don’t match either.

in the topic title you said you wanted to store the result of a template in an input number.

in the sensor you are using an input number to set the state of a template sensor.

am I misunderstanding something?

Hi finity,
Thx for the reply.
I found another way to have my calculation done using a ‘utility meter’ in ‘helpers’.
I was just starting with HA and was converting my flows of Homey to HA, so I just wanted to use my old logical approach to solve my problems.

I do have a new question, but I will post a new question for that