Multiply sensor with a number

Hi
I want the watts currently being used be devided by 1000 and multiplied by an inputnumber(The costs per kWh)

The watts are an entity with
state_class: measurement
unit_of_measurement: W
icon: mdi:calculator
friendly_name: TotaalVermogen
and a state that represents the current watts (70.0)

The input_number.stroom_normaaltarief
initial: null
editable: true
min: 0
max: 10
step: 0.001
mode: box
unit_of_measurement: EUR/kWh
icon: mdi:cash-marker
friendly_name: Stroom_Normaaltarief

It looked to me as a very easy thing to do. Create a sensor in confiuguration.yaml and divide and multiply.
Somehow i can’t get it to work

Current code is.

template:
  - sensor:
      - name: HobbyUurprijs
        unit_of_measurement: "Euro"
        state: "{{(state('sensor.TotaalVermogen_Elitedesk_Monitoren')|float(0)/1000) * state(input_number.stroom_normaaltarief)}}"

i’ve not tested it, but just a fast inspection (ie, there may be more issues)…

state should be states
and input_number… needs to be quoted.

you should pop the template in dev-tools → template first to help make sure it does what you want, then put it into the sensor.

thanks. I now have

{{(states('sensor.TotaalVermogen_Elitedesk_Monitoren')|float/1000) * states('input_number.stroom_normaaltarief')}}

i get the error in dev-tools template: TypeError: can’t multiply sequence by non-int of type ‘float’

because you’re multiplying different types. cast the input_number to a float

Or just follow this advice, no template required: Helpers type "Template" - #6 by tom_l It will work for any sensor with the correct state_class attribute.