Custom Power Sensor not showing in Energy Dashboard

Hi,

I am using a Shelly 3EM to my house power usage. I have 3 single phase supplies being monitored:
1, Solar In (Channel A)
2. Grid In (Channel B)
3. Electric Car Charger (Channel C)

Each of these Channel have sensors for:

  • Current
  • Energy
  • Energy Returned
  • Power Factor
  • Power
  • Voltage.

When I set up the energy tab to show grid in and solar in, I used the Power sensor for the solar and grid channels which worked great. However, I noticed that the grid in goes to negative when there is excess solar. I wanted to set this up as a seperate sensor so that solar return could be tracked. I tried to create 2 new sensors using this code block:

template:
  - sensor:
      - name: "Grid Return"
        unique_id: "grid_return"
        state_class: measurement
        unit_of_measurement: W
        device_class: power
        state: >
          {% if states('sensor.house_power_meter_channel_b_power') | float < 0 %}
            {{ states('sensor.house_power_meter_channel_b_power') | float | abs }}
          {% else %}
            0
          {% endif %}

      - name: "Positive Grid Usage"
        unique_id: "positive_grid_usage"
        state_class: measurement
        unit_of_measurement: W
        device_class: power
        state: >
          {% if states('sensor.house_power_meter_channel_b_power') | float > 0 %}
            {{ states('sensor.house_power_meter_channel_b_power') | float }}
          {% else %}
            0
          {% endif %}

This works well until I go to add them into the energy dashboard where they aren’t made available. The data looks the same and I copied the state attributes from the Channel B power sensor:

state_class: measurement
unit_of_measurement: W
device_class: power
friendly_name: Grid

I did some searching and found some forum posts about creating integrations and whatnot but when I followed them, they were reporting inaccurate data (or wrong data I am not sure).

Can I please get some help for this?

For starters, the energy dashboard only supports sensors that report energy values, such as Wh or kWh. These sensors are totals of power over time.

The sensors you have created are power sensors, which are a measurement in a moment in time and are reporting in W or KW. You can’t use these on the energy dashboard. You could use a Riemann sum integral to convert.