Energy Dashboard - How to add monthly electricity subscription?

Hi there,

As it seems that like to fit a square in a circle, I’m trying to add my monthly subscription for electricity to the energy dashboard. I’m almost there but there is one last thing that I cannot do. I will try to list everything that I have tried to see if someone has a better idea on how I should run those things…

Requirements

  • A new line in the table with 0 kWh (for not skewing the total Off Peak/Peak sum)
  • Increase the cost of subscription by a daily amount (monthly cost * 12 months / 365 days)

First Step
Sensors if declared in Configuration.yaml (measurement or even total_increasing) do not seem to retain values on reboot, so I had to use the Utility Meters in the Helpers section of the UI. A Helper cannot be used without a sensor as source, so I had to created a dummy sensor that stays at zero all the time.

template:
  - sensor:
    - name: "Energy Electric Subscription Dummy [kWh]"
      state_class: total_increasing
      unit_of_measurement: kWh
      device_class: energy
      state: 0

Then I created a Utility Meter called “Energy Electric Subscription” that uses this sensor. I now managed to show the 0 kWh and I can use an entity to track costs.

Second Step
To manage the costs, I tried to add directly to the cost sensor which is automatically generated when the Utility Meter is created. If I set the state by hand, it gets erased one minute later. Wrong approach.

Instead, I use another Utility Meter to track the total costs because this kind of entity can survive a reboot of HA without loosing its last value. This time, if I set some increments by hand with the Developer Tools, it works in the UI, I can see the increments.

My Problem
How can I increase this total costs entity by a fixed amount (0.62) every day at 00:01. By doing this, I would have the right amount reflected in the Energy dashboard with the various aggregates (weekly, monthly, etc.).

Automation does not seem to allow you to modify the value of a Utility Meter and “set_value” only works with Input Text and not sensors.

Has anyone a better idea on how to implement this?

Cheers,

G.

3 Likes

For those interested, I found a working solution: adding a sensor that calculates the increase based on the day of the year.

    - name: "Energy Electric Subscription Total Costs"
      state_class: total_increasing
      unit_of_measurement: EUR
      device_class: monetary
      state: "{{ ((now().strftime('%j')|float - 203) + (now().year - 2022) * 365) * 0.8824 }}"

Cheers,

G.

4 Likes

Wish I’d come across this earlier - been pulling my hair out with a lot of the kludges people have been using.
Set them up as you’ve described and it’s doing exactly what I wanted (to see the charges separate to consumption. Modified slightly for the daily as well.
Good job :clap:

1 Like

Hi,
Thanks for the solution.
However I’m facing an issue.
I created the dummy sensor for the constant 0kWh and the associated utility meter, but I cannot select the utility meter in the energy dashboard, only the dummy is seen. I check that utility meters has energy as class and kWh as unit.
Any idea ?
Do you still need a utility meter for it to work?
And for the cost, do you directly use the sensor or an associated utility meter as well ?

For mine, I use an input number to hold the supply charge cost (though this can be a direct value), then use two sensors in my sensors.yaml file - one for the zero kWh and one for calculating the cost

 - platform: template
   sensors:
     energy_supply_charge_kwh_zero:
       friendly_name: "Supply Charge Zero kWh Holder"
       unit_of_measurement: kWh
       device_class: energy
       value_template: "{{ states( 'input_number.energy_kwh_zero_holder' ) | float }}"
       attribute_templates:
         state_class: total
     energy_supply_charge_costing:
       friendly_name: "Supply Charge Costing"
       unit_of_measurement: AUD
       device_class: monetary
       icon_template: mdi:currency-usd
       value_template: "{{ (((now().strftime('%j')|float ) + (now().year - 2022) * 365) *  states( 'input_number.energy_charges_price_supply_charge' )|float() ) | round(3) }}"
       attribute_templates:
         state_class: total_increasing

I then have a utility meter in my utility_meter.yaml file - note that a tariff is required (SAPN is the name of my provider - change to suit)

 energy_suppy_charge_kwh_total:
   source: sensor.energy_supply_charge_kwh_zero
   name: "Supply Charge"
   tariffs:
     - SAPN

In the energy dashboard I use the utility meter for the consumed energy (this will always show zero on the dashboard), and the supply charge costing sensor in the field for ‘Use an entity tracking the total costs’

I have set up utility meters for daily, monthly and yearly also for my own tracking but this isn’t really necessary as the dashboard takes care of that if using 1st of month.
There are probably better ways to do this, but it works well for my use.

1 Like

Thank you for your answer.
I’ll try your solution. My issue was maybe that I left the tarif field empty in the utility meter.

1 Like

That caught me out for ages. I didn’t use one since it’s only single and it caused me all sorts of headaches. Hopefully it sorts your problem also.

Adding something in the tariff field of the utility meter that holds the 0 kWh solved my issue.
Without it I was not able to add it in the energy dashboard.
So I managed to get it working by mixing the proposed solutions. Now I need to see after a day or two if everything is OK in the energy dashboard.
Thanks !

1 Like

Please tell me… how do you rename the “individual devices” ?
Thanks in advance

Thank you for sharing these things. I, too, need this.

Could I ask you to elaborate a bit on your last line of code?

state: "{{ ((now().strftime('%j')|float - 203) + (now().year - 2022) * 365) * 0.8824 }}"

Do I need to update what looks like year 2022, now that we have a new year (2023)?
If so, I’m guessing I’d need to do that every new year.

The values “0.8824”, is that how much you need to pay per day?
I’m a rookie, but isn’t the Energy measurements done hourly? But this is perhaps something that is sorted out automagically (daily fee → hourly fee)?

Do you still use this solution yourself? Or have you perhaps found something even better?

Best regards,
/Richard

Hi Richard,

I’m still using it and I have updated to the new price:

{{ ((now().strftime('%j') | float - 17) + (now().year - 2023) * 365) * 1.01 + 157.9496 }}

I take the current day of the year minus the day I started the counter (18/01/2023 here). For the years, you do the same, remove the current year and multiply both by the daily price (monthly * 12 / 365). I have also added to value of my current cumulated counter on that day to it does not “jump” or “go back”.

I smoothly went from 0.8824 to 1.01 per day from now on :wink:

To rename the devices, you need to rename the “kwh” entity of the said device.

my calculation seems to be wrong.
for what are you using the “-17”?

You have to remove the current days of the year (minus one) so it ultimately depends when you will enter your formula.

Hi @gdesfeux,
this is a great solution that i was also looking for. Tahnk you very much :slight_smile:
I have tried your solution and basically it seems to work. My Tmeplate sensors look like this:

- sensor:
    - name: "Platzhalter Verbrauch Grundpreis"
      unit_of_measurement: kWh
      device_class: energy
      state: 0
      state_class: total
    - name: "Grundpreis"
      unit_of_measurement: EUR
      device_class: monetary
      state: "{{ ((now().strftime('%j')|float - 116) + (now().year - 2023) * 365) * 0.4077 + 47.2932 }}"
      state_class: total_increasing

As you can see, I started the sensor yesterday und it updated last night.
My problem now is that it is only showing the value for today, which is 0,41 €. It obviously ignores the last part of the template, where I’m adding the costs incurred to date amounting to 47,29 €.

Do you have any idea what I’m doing wrong and how I can fix this?
Would there also be a way to show the monthly costs directly instead of the daily costs? E.g. I’m paying 12,40 € per month. Until today this would account to 4 (April) * 12,40 = 49,60 €.

BR Philipp

Thank you for this - works perfectly. It’s amazing that there is no simple way to just add on x amount per day.

2 Likes

The value you are adding at the very end is actually the current value of your total costs sensor (total_increasing). It is used when your tariff change and you don’t want to loose history.

If you created your sensor yesterday, then it should be zero. If you have a look to my first formula, there was nothing at the end. I have added the current value of the sensor only when I migrated to a new tariff.

I hope it helps. Sorry for the “late” answer, I’ve been off Home Assistant for several months (something called having kids :wink:

Cheers,

G.

Hello there
i have Shelly pro 3em with 3 phase CT.
i installed the device and integrated to HA perfectly.
in our country if monthly consumption was 450 Kwh/Month the tariff will be 18 IQD/Kwh, but if exceeded that range next 450kwh will be 24 IQD/month,
My question how we can calculate that ??


In your case, you need to create another sensor to give you the current cost (with the condition you explained above).

The energy dashboard supports this kind of feature for consumption. Instead of a static cost, select your newly created entity and you should be good.

Edit: you will need a utility meter that reset one a monthly basis. This will be used in your cost sensor to test if you are above or below 450kwh.

1 Like

I have an issue where the sensors work perfectly, but it shows the total for all days on my dashboard rather than the individual days total. How do I fix this?