Create sensors for daily production, consumption and net

Hi all,

I’m using a DSMR sensor to track energy usage and consumption. This integration provides 4 sensors:
Which provide total kWh for a day, during the tarif 1 and tarif 2 periods

Additionally two sensors are provided with seem to indicate current usage (doesn’t accumulate)

The official energy dashboard can work with these sensors; nicely adding the values of the tarif’s

I’d like to have access to three values:
-Total Daily energy production
-Total Daily energy consumption
-Total Net energy usage

I’ve started to create a sensor template, but is doesn’t seem to do the trick.

  - platform: template
        friendly_name: Energy Total
        value_template: "{{ (states('sensor.sensor.electricity_meter_energy_consumption_tarif_1') | float) + (states('sensor.electricity_meter_energy_consumption_tarif_1')| float) /1000 | round (2) }}"
        unit_of_measurement: 'kWh'

Any suggestions are welcome!

For a start you should be using the new template sensor format. The old format you used is still supported but will not be getting new features.

You are confusing power and energy in your naming scheme. They are not the same thing. Don’t do this or it will be very confusing later on.

You seem to be doubling up on sensor 1, when you need to add sensor 1 and sensor 2.

You need to supply defaults for your float filers.

You are rounding the number 1000 rather than your template result. You need to watch where you put parentheses.

The option “entity_id” has not been available in old templates for a long time. Don’t use it.

You should use valid device and state classes.

You should provide an availability template so that the sensor is available only when both source sensors are available.

Something like this:


    - sensor:
      name: Energy Total
      device_class: energy
      state_class: total_increasing # or just "total" if your source sensors do not periodically reset. 
      unit_of_measurement: 'kWh'
      state: "{{ ( ( states('sensor.sensor.electricity_meter_energy_consumption_tarif_1') | float(0) + states('sensor.electricity_meter_energy_consumption_tarif_2')| float(0) ) / 1000 ) | round (2) }}"
      availability: "{{ states('sensor.sensor.electricity_meter_energy_consumption_tarif_1') | is_number and states('sensor.electricity_meter_energy_consumption_tarif_2') | is_number }}"