Sensor solargen shown no values

Hello,

my energy board and sensors are running since month but recently I found out that
Power import and
Power consumption
are showing the same values which should not be the case as the solar electricity must be considered at sensor Power import.

I found out that the sensor solargen is showing always zero even at 12:00 when the production of solar electricity is very high.
grafik

My solar panels will be checked with a Shelly em in order to get precise data. The sensor: shelly_em_channel_1_power is showing accurate figues and a nice graph
grafik

But why is solargen showing zero? At yaml I cannot find any issue:

Template sensor for values of energy Solar generation (solar_power > 0)

power_solargen:
friendly_name: “Power Solar Generation”
unit_of_measurement: ‘W’
value_template: >-
{% if (states(‘sensor.shelly_em_channel_1_power’)|float(0)) > 0 %}
{{ (states(‘sensor.shelly_em_channel_1_power’)|float(0)) }}
{% else %}
{{ 0 }}
{% endif %}

Any advice?

Firstly, please format your code correctly:

Your template appears to output the Shelly power figure if it’s above zero, and 0 if it is below zero. Your graph shows the Shelly at -168W, so the template should be outputting zero.

Looks to me like it’s doing what you asked it to…

You are right, found the failure and changed it. Now it works fine!

# Template sensor for values of energy Solar generation (solar_power > 0)
      power_solargen:
        friendly_name: "Power Solar Generation"
        unit_of_measurement: 'W'
        value_template: >-
          {% if (states('sensor.shelly_em_channel_1_power')|float(0)) < 0 %}
            {{ (states('sensor.shelly_em_channel_1_power')|float(0)) * -1 }}
          {% else %}
            {{ 0 }}
          {% endif %}

I simply did not consider that the data from my shelly em are negative. So I have to make them positive for the YAML. Quite simple mistake…