I failed Math with templates

hi I’m trying to calculate something :slight_smile:


template:
  - sensor:
      - name: "CurrentCost Power"
        unit_of_measurement: 'W'
        state: '{{ state_attr("sensor.current_cost", "Appliance 0") | float }}'
        device_class: power
        state_class: measurement

  - sensor:
      name: "mypf"
      unit_of_measurement: 'W'
      state_class: measurement
      device_class: power
      state: >
        '{{ (states("sensor.energy03_energy_voltage") | float / 240.0)  | round(3) }}'
  - sensor:
      name: "vawatts"
      unit_of_measurement: 'W'
      state_class: measurement
      device_class: power
      state: '{{ state_attr("sensor.current_cost", "Appliance 0") | float  }}'

sensor current cost measures va but the v in va is wrong
mypf takes a voltage reference and divides by 240 this is a string value of 0.9xx usually

vawatts is the same value as sensor current _cost

What I am trying to do is create a sensor which has a value of vawatts * mypf
but they are both strings and thats not permitted.

how do i create my new sensor with the result ?

Sorry I am very new to this

state: '{{ states("sensor.vawatts") | float * states("sensor.mypf") | float }}'

Hi it’s delivering a result of ‘0.0’ with values of 280 x 0.975 which should be 273
thank you for trying thou.

  - sensor:
      name: "corrected"
      unit_of_measurement: 'W'
      state_class: measurement
      device_class: power
      state: '{{ states("sensor.vawatts") | float * states("sensor.mypf") | float }}'

Nope, it will work fine as long as the entities you are using are correct.

Here is an example:

Notice that both states are strings but when converted to floats and multiplied they return a float.

one of those entities of yours must not be converting to a float or the value contains characters that can’t be converted - like ‘watts’ or some other non-numeric character in the state.