Move sensor value to input_number

I’m trying to move a sensor value to an input number with the automation below. I get a zero in the input number when i run the automation, even if there is a value in the sensor. If i put annother input_number in the data_template and run the automation it works fine.
I really dont now what i’m doing wrong.
The sensor is af sensor template


  - platform: template
        friendly_name: 'Watt total taeller for stuehus'
        unit_of_measurement: 'kWh'
        value_template: >-
          "{{ (states('input_number.tag_watt_total_stuehus') | float) | round(2)}}"


- id: 'test_2_automation'
  alias: automations test no 2
  - platform: state
    entity_id: binary_sensor.varmeepumpe_effekt_malepuls
    from:  'off'
    to:  'on'
  condition: []
  - service: input_number.set_value
      entity_id: input_number.test_number
      value: "{{ states('sensor.watt_total_stuehus') | float}}"

I think you’ll need

{{ states('sensor.watt_total_stuehus', 'state') | float}}

You may find it helpful to test your templates in Developer Tools -> Templates, to make sure they return the value you’re expecting before using them in an automation.

Hey EKC, tanks for reply
Good point testing templates under developer tools :slight_smile:
But it didn’t work.
With the

{{ states('sensor.watt_total_stuehus', 'state') | float}}

i get the error:
TypeError: call() takes 2 positional arguments but 3 were given… any thoughts?

I’m sorry, that was my mistake - your original template is correct.

If you go to Developer Tools -> States, what is listed as the state for sensor.watt_total_stuehus?

Remove the double-quotes in your Template Sensor’s value_template:

        value_template: >-
          "{{ (states('input_number.tag_watt_total_stuehus') | float) | round(2)}}"
          ^                                                                       ^
          |                                                                       |

Alternately, leave them but move the template to the same line as the value_template option:

        value_template: "{{ (states('input_number.tag_watt_total_stuehus') | float) | round(2)}}"

When you use the line-continuation character >- you don’t need to quote the template. You need them only if the template is on the same line as the value_template option.

1 Like

Tank you wery much booth of you, it is working :grinning:

1 Like