Calculating real power from apparent doesn't work

I have solar panels and a Shelly 3EM to measure my 3 groups.

Real power is measured in W
Apparent power in VA
And now the Apparent power is what I need in my energy dashboard.
image

Both are available, and also the power factor. Working with the VA values doesn’t seem to work.
So I created a sensor, converting the active power to apparent, with power factor. But the result is 'unavailable.

- sensor:
    - name: Omvormer1_vermogen
      unit_of_measurement: W
      device_class: power
      state: "{{ (states('sensor.zonnepanelen_phase_a_power_factor' | float ) * states('sensor.zonnepanelen_phase_a_active_power' | float ))  | int(default=0) }}"


Any idea what is wrong ? No errors (as far as I can see) in the logs

Your float filters are in the wrong place, they go outside the states() function. You should also add an availability template to prevent odd readings and errors if one or more of the source sensors is unavailable.

template:
  - sensor:
      - name: Omvormer1_vermogen
        unit_of_measurement: W
        device_class: power
        state_class: measurement # <- if you want long term statistics
        state: "{{ states('sensor.zonnepanelen_phase_a_power_factor')|float * states('sensor.zonnepanelen_phase_a_active_power')|float }}"
        availability: "{{ has_value('sensor.zonnepanelen_phase_a_power_factor') and has_value('sensor.zonnepanelen_phase_a_active_power') }}"
1 Like