Switch from day and night tariff to single tariff

Who wants and can help me?

I switched from energy supplier and opted for one tariff, my old situation was a day and night tariff.

My DSMR integration still shows the day and night tariff and also shows the consumption on these two sensors. Is this correct and if so, how can I link these 2 sensors into one sensor?

It would be nice if these two values could be added together and read as one consumption sensor.

The sensor sensor.power_consumption does not show any data.

Do you care about losing your old data?

I prefer to keep my old data, but if the only solution is to start over then so be it!

Go to Settings → Dashboards → Energy.

What are the sensors listed under the grid consumption section?

Also which DSMR integration are you using?

Or

sensor.energy_consumption_tarif_2 and sensor.energy_consumption_tarif_1

I use the DSMR Slimme Meter integration. (Netbeheer Nederland)

Ok. Thanks. So it is easy to add those two sensors together. The problem is if we just add that new summed sensor to the energy dashboard it will read twice your energy consumption unless you remove the two existing sensors from the dashboard. And if you do that you will lose your existing energy history.

Two solutions:

  1. Leave sensor _1 and _2 in the energy dashboard. Rename these sensors to: _1_new and _2_new on the integration device page. Create three new sensors. One that is the sum of _1_new and _2_new and two new sensors _1 and _2 that always read 0. Add the new summed sensor to the energy dashboard and leave the existing ones in place (that will read 0 from now on, but you can see the history).

Or

  1. Remove sensors _1 and _2 from the energy dashboard. Create a summed sensor for _1 and _2, add that to the energy dashboard and start again with no history.

Which would you like to do?

Option 2. I would really like to preserve my history.

Option 2 does not preserve your history.

So assuming you actually want to go with option 1:

Go to Settings → Devices & Services and find the DSMR Slimme Meter integration then click on the device link.

On the device page, click on each tariff sensor and change their entity id (not names) from:

sensor.energy_consumption_tarif_1
sensor.energy_consumption_tarif_2

To:

sensor.energy_consumption_tarif_1_new
sensor.energy_consumption_tarif_2_new

Add this to your configuration.yaml file:

template:
  - sensor:
      - name: Total Energy From Grid
        device_class: energy
        state_class: total_increasing
        unit_of_measurement: kWh
        state: "{{ states('sensor.energy_consumption_tarif_1_new')|float(0) + states('sensor.energy_consumption_tarif_2_new')|float(0) }}"
        avilability: "{{ has_value('sensor.energy_consumption_tarif_1_new') and has_value('sensor.energy_consumption_tarif_2_new') }}"

  - trigger:
      - platform: homeassistant
        event: start
    sensor:
      - name: energy_consumption_tarif_1
        device_class: energy
        state_class: total_increasing
        unit_of_measurement: kWh
        state: "{{ 0 }}"
      - name: energy_consumption_tarif_2
        device_class: energy
        state_class: total_increasing
        unit_of_measurement: kWh
        state: "{{ 0 }}"

Do a configuration check and if that passes restart home assistant.

Then go to Settings → Dashboards → Energy and add sensor.total_energy_from_grid to your grid sensors. Leave the existing sensors there. Do not delete anything.

From now on you should have only one grid sensor showing in the dashboard graph but in the history the two tariff sensors should still be there.

Sorry I made a typo, it should have been option 1.

Thank you for explaining !!
I will make the config change and let you know if it worked.

I made the changes, and the sensor “sensor.total_energy_from_grid” does not show up.
When i check the log file is says:

Invalid config for [template]: [avilability] is an invalid option for [template]. Check: template->sensor->0->avilability. (See /config/configuration.yaml, line 32).

It’s a typo.

Should be availability.

OK didn’t see there was a typo in it :wink:
Ok the error is gone now.
But i don’t see any historical data anymore, when i change the old sensors to the *_new sensors the historical data is displayed

Is it possible to stick with the old names and only combine these two sensors to a third sensor named sensor.total_energy_from_grid ?

Where did you make this change?

You should not change the names in the energy dashboard settings.

And no it is not possible to keep the old sensors as they are already adding their energy to the energy dashboard. If you also add their sum to the dashboard you would get twice the energy you actually used displayed.

EDIT:

In your Energy Dashboard you should have only these grid consumption sensors:

sensor.energy_consumption_tarif_1
sensor.energy_consumption_tarif_2
sensor.total_energy_from_grid

NOTE: they are not the *_new sensors.

I did exactly as you have described I only adjusted the name in the entity ID fields.

sensor.energy_consumption_tarif_1 to sensor.energy_consumption_tarif_1_new
sensor.energy_consumption_tarif_2 to sensor.energy_consumption_tarif_2_new

I have not adjusted the names.

In the energy dashboard i only added the new sensor and left the old ones without changing anything.

No historical data is displayed.

Also the sensor sensor.total_energy_from_grid is not displaying any new data on the dashboard.

As a test I adjusted the sensors to the *_New in the energy dasboard and then the history is shown.

Then I put the backup back to get the old situation back.

Maybe it is not possible what i want and should i start with no old data.
What should the code look like to have no historical data and only combine the two sensors to single tariff? And start with a clean new dashboard from now on.

Can you put this in the developer tools template editor and tell me what the result is:

{{ states('sensor.energy_consumption_tarif_1') }}
{{ states('sensor.energy_consumption_tarif_2') }}
{{ states('sensor.energy_consumption_tarif_1_new') }}
{{ states('sensor.energy_consumption_tarif_2_new') }}
{{ states('sensor.total_energy_from_grid') }}

I decided to leave it as it is with normal and off-peak rates.
I think it’s too much hassle for something so simple, the option should just be selectable there.

Thank you for all your help.

What an amazingly interesting discussion @tom_l !
I’m in the exact same position as boulanger and was reading your instructions. That’s when a question came up:

After renaming sensor.energy_consumption_tarif_1 to sensor.energy_consumption_tarif_1_new, doesn’t all of it’s historical data move with that entity to its new name?

That would explain why Boulanger did not see the data in the energy dashboard until he changed it to the renamed ‘_new’ entities.

But… When showing the new ‘sum’ entity as well as the ‘_new’ entities the usage displayed would double.

It’s a shame that my ‘smartmeter’ still provides 2 tarifs even though I don’t have 2 tarifs.
I actually have 24 different tariffs per day, just to undercomplicate things :slight_smile: