Calculate the power of Solar Edge inverter

Dear ha friends,

I´m totally new to ha and trying to realize following:

Modbus read power_readout value of Solar Edge inverter - done, works.
Modbus read power_factor value out of Solard Edge inverter - also done and works.

Now I need to calculate the real power value, with following formula:

power_value = power_readout * {10^ powerfactor }

In the configuration.yaml it looks like that, I get the modbus values power_readout and power_factor, but I don´t get any calculated value in power_value at the end.
Any ideas? Your help is appreciated!

modbus:
  - name: SolarEdge
    type: tcp
    host: 192.168.2.22
    port: 1502

    delay: 0
    message_wait_milliseconds: 300
    timeout: 5       
    sensors:
      - name: "power_readout"
        unique_id: power_readout
        unit_of_measurement: "W"
        address: 40083
        slave: 1
        data_type: "int16"   

      - name: "power_factor"
        unique_id: power_factor
        unit_of_measurement: ""
        address: 40084
        slave: 1
        data_type: "int16"   

sensor:
  - platform: template
    sensors:
        power_value:
            unique_id: power_value
            unit_of_measurement: "W"
            value_template: "{{ (states('sensor.power_readout') | int * (10 ** (states('sensor.power_factor') | int))) | round(2) }}"

I really got stuck guys.

Think my code is right, but my “problem” is the powerfactor coming from SolarEdge inverter. The powerfactor is a num between 0 and -3.
At the moment it is standing at -1 an I can see it in sensor status display:
But the code doesn´t let me calculate with that sensor.
When I put a number instead, it works:

Doesn´t work:

state: >- 
        {{  ((float(states('sensor.PV_Dach_raw'))) * (10 ** (float(states('sensor.Powerfaktor'))))) }}

Does work:

state: >- 
        {{ ((float(states('sensor.PV_Dach_raw'))) * (10 ** -1 )) }}

Then I also tried to use if/else to calculate, but I end with result 0, even if sensor powerfaktor is -1 .
Any suggestions?

modbus:
  - name: SolarEdge
    type: tcp
    host: 192.168.2.22
    port: 1502
    delay: 0
    message_wait_milliseconds: 300
    timeout: 5       
    sensors:
      - name: "PV_Dach_raw"
        unique_id: pv_dach_raw
        unit_of_measurement: ""
        address: 40083         # Registeradresse
        slave: 1
        data_type: "int16"       # Datentyp (z.B. int, uint, float)    

      - name: "Powerfaktor"
        unique_id: power_faktor
        unit_of_measurement: ""
        address: 40084         # Registeradresse
        slave: 1
        data_type: "int16"       # Datentyp (z.B. int, uint, float)     

template:
    sensor:
      - name: "PV_Dach"
        unique_id: pv_dach_berechnet
        state: >-
           {% if is_state('sensor.Powerfaktor', '0') %}
             {{states.sensor.PV_Dach_raw.state | float / 1}}
           {% elif is_state('sensor.Powerfaktor', '-1') %}
             {{states.sensor.PV_Dach_raw.state | float / 10}}
           {% elif is_state('sensor.Powerfaktor', '-2') %}
             {{states.sensor.PV_Dach_raw.state | float / 100}}
           {% elif is_state('sensor.Powerfaktor', '-3') %}
             {{states.sensor.PV_Dach_raw.state | float / 1000}}
           {% else %}
             0
           {% endif %}

Screenshot 2024-10-26 110933

Sensor entity ids no not have capitals, so this is not the right entity id. Try all lowercase (check the developer tools for the real entity id).

Edwin, thank you! That‘s it!
I have to use the unique_id to calculate, now it works :ok_hand:

Technically not the unique id either, but in this case it is the same. Glad it works.