How to calculate daily power consumption from DSMR sensors?

If your sensor is in w, using that is pointless because it expects a wh or kwh sensor. Do you understand the difference between w and wh?

Hi @petro,
Are you talking about utility_meter integration?

Indeed, my sensor is in W so I guess I won’t be using utility_meter. Even though it looked very useful.

Regarding this part, if today, let’s say, I have only been using 1000W at 12:31pm, my new kWh sensor will indicate at 12:32pm, I used 1kWh. At 12:33pm, it will indicate the same value, and this for the next hour. Isn’t it?
So if I want to compare this device power consumption with my home electricity meter, it should say I used 1kWh only today but it might show 1kWh * how often the new sensor is published.
Is it correct?

Yep

at 12:33 the range is 11:33 to 12:33 in which you only used 1000w at 12:31, so your value would be 1000wh. When the time changes to 12:34, the range changes from 11:33-12:33 to 11:34-12:34. Again you only used 1000w at 12:31 so the value stays at 1000wh.

If you want to compare a momentary W device with your power companies Wh, you want to use the integration sensor with the following configuration.

sensor:
  - platform: integration
    source: sensor.current_power
    name: Energy Spent
    unit_prefix: k
    method: left

And then implement that sensor into utility meter.

Wooow THAT is what I was looking for! Let me try! Thank you :slight_smile:

It works great, thank you @petro!

Hi all!

Since a few weeks I am trying to get my smartmeter readings in Home Assistant. The ‘out of the box’ dsmr configuration as described here works like a charm.

But when I try to add the Utility Meter Component, all the DSMR entities disappear which results in no readings at all: the new entities do appear, but they all have a value of zero. As soon as I remove the additional configuration, the original entities reappear again. Does someone know what I am doing wrong?

Thanks in advance for your assistance!

Hi @Haggyman, please post your (relevant) config!

Hi Gerben,

My relevant config is very basic. I have ser2net running on a rPi in my Utilitycloset. Home Assistant is running in Docker on my Ubuntu server. So My DSMR config in the configuration.yaml is as follows:

sensor:
 - platform: dsmr
   host: <IP address rPi>
   port: <TCP port configured in ser2net on rPi>
   dsmr_version: 5

With only the above config, the following entities appear in Home Assistant and everything works peachy:

  • sensor.current_phase_l1
  • sensor.current_phase_l2
  • sensor.current_phase_l3
  • sensor.energy_consumption_tarif_1
  • sensor.energy_consumption_tarif_2
  • sensor.energy_consumption_total (which does not seem to work btw)
  • sensor.energy_production_tarif_1
  • sensor.energy_production_tarif_2
  • sensor.gas_consumption
  • sensor.hourly_gas_consumption
  • sensor.long_power_failure_count
  • sensor.power_consumption_phase_l1
  • sensor.power_consumption_phase_l2
  • sensor.power_consumption_phase_l3
  • sensor.power_production
  • sensor.power_production_phase_l1
  • sensor.power_production_phase_l2
  • sensor.power_production_phase_l3
  • sensor.power_tariff
  • sensor.voltage_phase_l1
  • sensor.voltage_phase_l2
  • sensor.voltage_phase_l3
  • sensor.voltage_sags_phase_l1
  • sensor.voltage_sags_phase_l2
  • sensor.voltage_sags_phase_l3
  • sensor.voltage_swells_phase_l1
  • sensor.voltage_swells_phase_l2
  • sensor.voltage_swells_phase_l3

As soon as I add the following code to the configuration.yaml (taken from here), all of the above entities disappear:

utility_meter:
  daily_power_offpeak:
    source: sensor.energy_consumption_tarif_1
    cycle: daily
  daily_power_peak:
    source: sensor.energy_consumption_tarif_2
    cycle: daily
  daily_gas:
    source: sensor.gas_consumption
    cycle: daily
  monthly_power_offpeak:
    source: sensor.energy_consumption_tarif_1
    cycle: monthly
  monthly_power_peak:
    source: sensor.energy_consumption_tarif_2
    cycle: monthly
  monthly_gas:
    source: sensor.gas_consumption
    cycle: monthly
sensor:
  - platform: template
    sensors:
      daily_power:
        friendly_name: Daily Power
        unit_of_measurement: kWh
        value_template: "{{ states('sensor.daily_power_offpeak')|float + states('sensor.daily_power_peak')|float }}"
      monthly_power:
        friendly_name: Monthly Power
        unit_of_measurement: kWh
        value_template: "{{ states('sensor.monthly_power_offpeak')|float + states('sensor.monthly_power_peak')|float }}"

From this point on, every original entity regarding DSMR is gone and the newly made sensors all have a value of zero.

My config is nearly the same as yours, and I cannot find anything wrong in it. Is there anything in your logging? Perhaps you can enable debug logging for dsmr?

Hi Gerben,

Thank you very much for pointing me in the right direction!
I made a rookie mistake, which I figured out by looking at the logfiles. If you look at the code I posted, I configured it in that exact order resulting in two ‘sensor’ instances. HASS does not like that :slight_smile: .
So as soon as I merged the two ‘sensor’ entries into one, it was fixed.

Thanks again Gerben!

1 Like

Hello, I tried several times to set the input_number with this automation

  • id: ‘1608311346538’
    alias: Energieverbrauch um Mitternacht
    description: ’ ’
    trigger:
    • platform: time
      at: 00:00:00
      condition: []
      action:
    • service: input_number.set_value
      data_template:
      entity_id: input_number.energieverbrauch_mitternacht
      value: “{{ states.sensor.energy_consumption_tarif_1.state }}”
      mode: single

with no effect. When I run the input_number.set_value in the developer tools I get the error message “… input_number/set_value extra keys not allowed @data[value_template]”. Did I miss any syntax details?

Just have a look at https://www.home-assistant.io/integrations/input_number/
the example:

automation:
  - alias: Set temp slider
    trigger:
      platform: mqtt
      topic: 'setTemperature'
    action:
      service: input_number.set_value
      data:
        entity_id: input_number.target_temp
        value: "{{ trigger.payload }}"

So you must remove the “mode: single” line I think…
Does that help?

Dear Gerben,

i just copied the automation, modified it and nwo it works. Thanks!

Regards,

Volker

1 Like

Just copied your configuration from 2018 into home assistant, changed the entity names to reflect mine and boom: working.

Thanks for this!

1 Like