Dynamic Energy Cost

Hi all. I’ve been a bit away for some time.

Just released a new 0.5.0 version that will solve the currency issues. It will now use the Home Assistant default currency and that should solve the issue for everybody. I think it’s better than asking user to define the currency in the integration because probably HA locale has been set right by everybody.

Power Based Sensors:

Energy Based Sensors:

3 Likes

weekly energy cost is added in version 0.5.0

2 Likes

Also, I can’t emphasize enough to use energy-based sensors (kWh) instead of power-based sensors (kW) for more precise outcomes.

1 Like

Awesome!! Now you need to get a cool logo for the integration to!! GitHub - home-assistant/brands: 🎨 Brands for Home Assistant

Very Good work !
For the moment i tested with 2 devices, so i understood that for each devices, i need to reproduce adding the integration right ?

image

Hello

Haven’t installed yet, before I do.

A question has anyone installed or using it with a variable cost for the “Electricity price Sensor”?

Trying to avoid configuration of a static entity with the supply price, as I have a sensor with the dynamic price as published by my electricity provider.

The supply price can change every 30 minutes, but remains stable for a couple of hours everyday, so a static entry won’t really work for me.

How often the integration refresh and recalculate?

Great work!
I have used version 0.1.0 with my EV charger and just updated to 0.5.0 via custom repo in HACS.
That created new entities with (in my case) 0 SEK, an manual update replaces also all files as I’m aware of. Is there a way that consumed energy can survive an update, or did I missed something?

If not, do you think there is possibility to write data to a separate file that is created by integration, in that way file will not be overwritten by update and consumed amounts will preserve.

Yeah, about that. Could you please add the possibility to define currency anyways. I get my hourly prices from Nordpool in cents/kWh, while my default currency is EUR, so…

Yes, it works perfectly. This is from my water heater, using 3 kW until 4 PM today. Great work, @arva!

1 Like

As I am not a programmer this took some testing to put together correctly. :smile: I hope it may be useful for others. The variable price of power in Norway (per kWh) is made up of two parts, the energy itself and for use of the grid. The energy price change every hour, the grid use has a low and a high price, depending of time of day and if it is a workday or not. The energy price is simple - i get that from an integration (Tibber or Nordpool). The grid part I have to add myself, and this Template sensor does the job for me, with two helpers “input number” to make it possible to change the price when updated without editing yaml code. Finally I use a helper that sums the two parts, and that is what i use in Dynamic Energy Cost.

This is in my sensor.yaml file (can also be in configuration.yaml):

  - platform: template
    sensors:

      bkk_nettleie:
        friendly_name: BKK Nettleie
        unit_of_measurement: NOK/kWh
        value_template: >
          {% set tariff = { "dag": states('input_number.bkk_nettleie_dag'), "natt": states('input_number.bkk_nettleie_natt_helg') } %}
          {% if is_state('sensor.calender.norway', 'On') %} 
            {{ tariff.natt }}
          {% elif now().weekday() >= 5 %} 
            {{ tariff.natt }}
          {% elif now().hour >=6 and now().hour < 22 %}
            {{ tariff.dag }}
          {% else %}
            {{ tariff.natt }}
          {% endif %}
1 Like

Hi, I set the integration up yesterday to run overnight and I’ve got a result that doesn’t like up with what I had expected. It must be a configuration issue on my part as the produced cost graph follows the same curve as the kWh consumed graph:



The cost output for last night’s usage is many times higher than what it should be. The kWh usage was 5.27kWh at a rate of £0.1195/kWh (£0.6297).

Any ideas where the £3.55 figure has come from? It would suggest a unit rate of £0.6736/kWh (with 5.27kWh) or 29.7kWh consumed at £0.1195/kWh.

I thought it may have used the day rate initially but that doesn’t math right either.

I have used the sensors in the images above in the configuration for the integration.

Update

Clearly I made some configuration error initially. I went through and deleted the original entities and reconfigured the integration using a kWh sensor. The new entities populated with the existing bad data but last night the daily sensor reset and now shows a much more sensible number of £0.32 kWh usage. I will manually reset the weekly, monthly and yearly entities and start fresh.

Thanks for making a great integration arva.

1 Like

This is great, thank you for creating this!

1 Like

Hi,
What card this is? Or custom CSS? Do you mind to share code?

Sure !

image

type: entities
title: Electroménager
entities:
  - entity: sensor.lave_linge_electric_consumption_kwh
    type: custom:multiple-entity-row
    name: Lave-linge
    secondary_info: last-changed
    icon: mdi:washing-machine
    entities:
      - entity: sensor.lave_linge_electric_consumption_kwh_daily_energy_cost
        name: Jour
        format: precision2
        unit: €
      - entity: sensor.lave_linge_electric_consumption_kwh_weekly_energy_cost
        name: Semaine
        format: precision2
        unit: €
      - entity: sensor.lave_linge_electric_consumption_kwh_monthly_energy_cost
        name: Mois
        format: precision2
        unit: €
      - entity: sensor.lave_linge_electric_consumption_kwh_yearly_energy_cost
        name: Année
        format: precision2
        unit: €
  - entity: sensor.lave_vaiselle_electric_consumption_kwh
    type: custom:multiple-entity-row
    name: Lave Vaiselle
    secondary_info: last-changed
    icon: mdi:washing-machine
    entities:
      - entity: sensor.lave_vaiselle_electric_consumption_kwh_daily_energy_cost
        name: Jour
        format: precision2
        unit: €
      - entity: sensor.lave_vaiselle_electric_consumption_kwh_weekly_energy_cost
        name: Semaine
        format: precision2
        unit: €
      - entity: sensor.lave_vaiselle_electric_consumption_kwh_monthly_energy_cost
        name: Mois
        format: precision2
        unit: €
      - entity: sensor.lave_vaiselle_electric_consumption_kwh_yearly_energy_cost
        name: Année
        format: precision2
        unit: €
  - entity: sensor.seche_linge_electric_consumption_kwh
    type: custom:multiple-entity-row
    name: Sèche Linge
    secondary_info: last-changed
    icon: mdi:washing-machine
    entities:
      - entity: sensor.seche_linge_electric_consumption_kwh_daily_energy_cost
        name: Jour
        format: precision2
        unit: €
      - entity: sensor.seche_linge_electric_consumption_kwh_weekly_energy_cost
        name: Semaine
        format: precision2
        unit: €
      - entity: sensor.seche_linge_electric_consumption_kwh_monthly_energy_cost
        name: Mois
        format: precision2
        unit: €
      - entity: sensor.seche_linge_electric_consumption_kwh_yearly_energy_cost
        name: Année
        format: precision2
        unit: €

3 Likes

Thank you for sharing your project. This is what I was looking for and tried to configure multiple times. I am not sure if this issue is caused by the sensors or a mistake in the code. After each reboot:

I use a sensor that tracks the lifetime counter in kWh. When setting up the integration, it starts counting from that point onward. However, if there is a reboot of Home Assistant, it calculates based on the real counter instead of the delta from when the integration was set up.

normal way of calculating:

after reboot:

any idea on how to solve this?

I installed this addon recently and added my devices and linked them to my P1 meter, which are filled in with day and night rates via the Energy tab.
Most of the devices do not have much correct prices because then the electricity would be very expensive.

I am slowly switching from Homey to Home assistant and in Homey there is an app called “Power by the hour” that I use.
When I compare the data from Dynamic Energy with Power by the hour in Homey I see big differences and I know that the app works well when I compare it again with what I see in my Homewizard P! meter software.

My P1 meter automatically changes to rate 1 and 2 at 23:00 and 07:00.
I have also tried it with a utility meter that set the two rates via an automation at the correct time, but in both cases the result is the same and incorrect.

Attached are some pictures to make things clearer.
What am I doing wrong?

This is how I have it set up and have tried both options. Which one is correct?
2024-10-14 08_00_45-Instellingen – Home Assistant

This is the rest of my data.
2024-10-14 07_20_25-Thuis – Home Assistant



2024-10-14 07_25_55-Instellingen – Home Assistant


2024-10-14 07_21_27-Instellingen – Home Assistant

Thanks.

Is there a way to change the price sensor in an existing configuration? My Nordpool sensor changed the naming for the zones, thus the name of the sensor changed as well. I could setup a new sensor, but then I do not have the old data anymore.

I think this is kind of a weakness of Home Assistant, but I don’t think that will change anytime soon.

1 Like

This will not help you now - but a way to avoid the same problem later. Take a look at what I wrote in this thread aug 24. I have created a helper that sums grid tariff and energy price and use this helper as the price sensor in Dynamic Energy Cost. If there are changes to either grid tariff or energy price sensor I can update the helper without loosing the history.