Create a badge to show if net is consumed or returned on dashboard

Hi,

I love the Energy dashboard, but I mostly use my main dashboard. On my main dashboard I’d like to show a badge that indicates the total returned or consumed kWh, basically like this information:

I already tried to setup sensors to read out my other sensors:

sensor:
  - platform: integration
    source: sensor.power_consumed
    name: energy_consumed_total
    unit: kWh
    round: 2
    method: trapezoidal
  - platform: integration
    source: sensor.power_produced
    name: energy_produced_total
    unit: kWh
    round: 2
    method: trapezoidal

In configuration.yaml:

utility_meter:
  energy_consumed_today:
    source: sensor.energy_consumed_total
    cycle: daily
  energy_produced_today:
    source: sensor.energy_produced_total
    cycle: daily

But this keeps giving me back 0. How does the energy dashboard create the net consumed etc? What sensors are being used?

Update: I use the following entities for my Energy Electricity Grid settings:

Energy Consumed Tariff 1 (sensor.energy_consumed_tariff_1)
Energy Consumed Tariff 2 (sensor.energy_consumed_tariff_2)
Energy Produced Tariff 1 (sensor.energy_produced_tariff_1)
Energy Produced Tariff 2 (sensor.energy_produced_tariff_2)

I also have the option to use my ESPHome P1 reader:

sensor.power_produced and sensor.power_consumed.

First you can create and edit the sensors under Devices and Helpers.
Then what sensor are you using in your energy dashboard config? Use these with utility meters to get a daily value

I updated my post with the entities that I currently use. My sensor.power_produced and sensor.power_consumed. are almost realtime (change every second) but I simply need to calculate the total they did within one day. How do I do this?

Which unit of measurement are the sensor.power_produced and consumed?

state_class: measurement
unit_of_measurement: W
device_class: power
friendly_name: Power Produced
state_class: measurement
unit_of_measurement: W
device_class: power
friendly_name: Power Consumed

Basically what I try to replicate is the ‘Grid total’ function.

Ah ok I dont know P1 meters and I thought they provide summed entities.
For the sake of simplicity I would sum the Tariffs in a template sensor like

{{states('sensor.energy_consumed_tariff_1') | float + states('sensor.energy_consumed_tariff_2') | float}}

The problem is these entities have a total lifetime instead of total today. I’m looking for a way to get state of 0:00 untill now.

Then put the sum in an utility meter with a daily reset