Support with sensor

Hello.

I am using a Shelly 3em to track my solar panel production from my SMA inverter, and using my intergrated sensor for my other installation with my Deye inverter.

However when i connect my 3 phase clamps to the inverter the Shelly shows negative numbers while producing, while the other inverter shows positive numbers when producing, i want to add these together with a template sensor, but they will take each other out because of negative and positive.

I am looking to invert my Shelly 3EM sensor via code. Since turning the clamps around produced other problems in the form of showing false positive readings when the inverter is not producing at night.

This is the code i use to combine the 3 Power channels on my Shelly which i want to show positive numbers when producing instead of negative.

  - sensor:
      - name: "Sol SMA"
        unique_id: SolSma_draw
        state: >-
          {{ 
            [ states('sensor.sma_inverter_3em_channel_a_power'), 
              states('sensor.sma_inverter_3em_channel_b_power'),
              states('sensor.sma_inverter_3em_channel_c_power'),
            ] | map('float') | sum
          }}
        availability: >-
          {{ 
            [ states('sensor.sma_inverter_3em_channel_a_power'), 
              states('sensor.sma_inverter_3em_channel_b_power'),
              states('sensor.sma_inverter_3em_channel_c_power'),
            ] | map('is_number') | min
          }}
        unit_of_measurement: W
        device_class: power

I have seen other forums who want to do this, but i can’t figure out how and where i correct it.

Thanks for answers.

Try following template for state:

{% set a=states('sensor.sma_inverter_3em_channel_a_power') %}
{% set b=states('sensor.sma_inverter_3em_channel_b_power') %}
{% set c=states('sensor.sma_inverter_3em_channel_c_power') %}
{{[a if a > 0 else a*-1,
   b if b > 0 else b*-1,
   c if c > 0 else c*-1 ] | map('float') | sum}}

If the states of your sensors are strings, you have to surround them by float()
e.g. float(states('sensor.sma_inverter_3em_channel_c_power'))
Best you try it in template editor first.

Thank you for the answer.

How and where should i put this code? I am extremely new at coding. All the code i use is basically copied from other forums and replaced with the names of my own sensors.

Do i put that under my combining template shown above, or where does it go? Could you post a complete copy/paste that i can put inside the yaml?

Thanks.

Edit: i want the combined sensor " Sol SMA " to show negative numbers when positive and positive numbers when negative, a reverse. So in any case it can be multiplied by -1 but i do not know where to put the multiply by -1. I tried just writing *-1 after float. But with my limited knowledge i can’t figure out what to do. This 3em sensor is ONLY for the inverter. Not for the grid. I have a separate 3EM for that.

My template suggestion was meant to replace the template in state-field of sensor shown in your first post. But I did get you wrong. I thought you would like your sensor values to be always positive.
If you want to invert the sum, only, just multiply it by -1 e.g.:

        state: >-
          {{ 
            [ states('sensor.sma_inverter_3em_channel_a_power'), 
              states('sensor.sma_inverter_3em_channel_b_power'),
              states('sensor.sma_inverter_3em_channel_c_power'),
            ] | map('float') | sum*-1
          }}

Ahh
So there is where the *-1 is supposed to be placed… As said i have limited knowledge.

In my try i placed the *-1 before sum.

Will try this first thing when i get home. If this works i am thankful, will make sure that i can turn the clamps the right way around and combine my solar production sensors. The clamps seem to show strange power factors etc when turned the opposite way in the Shelly.

It did work.

Thank you for the help!