Total Energy Cost - Daily Standing Charge

Hi all,

I want to show my standing charge separately from my consumption on the energy dashboard. The plan was to add a second consumption source to the energy dashboard with a template sensor that never shows any consumption. All good. The next step was to add my standing charge price via a number helper and separate dashboard, then increment a total increasing sensor with the price once per day to put on the energy dashboard via the option ‘using an entity tracking the total costs’.

I got as far as the number helper, the template sensor (set to monetary) but I’m stuck with the increments. Initially I had another (counter) helper that incremented daily by one and the template sensor then multiplied this by the rate. This is obviously flawed if the rate changes as the result is cumulative. So next I tried to increment by adding the value of the template sensor to itself, which it appears HA doesn’t like.

I’m also wondering if the calculation will survive a restart i.e. what happens incrementing an unknown, as it’s not a zero? Gotten myself in a bit of a tangle.

Thanks!

I’ve actually now resolved this (I think).

I used dummy sensors for the consumption data (templates, fixed state at 0), then an input number helper for accrued cost. Used an automation to add the rate (also an input number) to the accrued cost helper once per day and then a template sensor to convert it to a cost that can be displayed on the dashboard.

Another automation resets the accrued cost helper to 0 at the end of the day and the cycle starts again. Time will tell, but it appears to be working so far! No data in the screenshot yet as it’s not had the time to update but tested and it worked in my test environment.

image

2 Likes

Sounds like a very complex solution … maybe you could have an input_number for the daily standing charge cost (£/day) and then use a Reimann sum integral to accumulate this over a unit_time of “day”.

Personally I calculate the daily cost using a template that includes the standing charge:

energy_cost_today:
      friendly_name: Energy Cost Today
      unit_of_measurement: £
      value_template: "{{ (states('sensor.energy_usage_day_std') | float * states('input_number.std_tariff') | float / 100.0) | float + ((states('input_number.standing_charge') | float / 30.0) | float ) | round(2) }}"

That just blew my mind.

My aim was to show the standing charge separately to usage though, which I’ve got now.

Probably much cleaner ways to do it but I got there in the end!

OK no problem, it was just a possible alternate way to achieve the same thing without needing the two automatons you described. If you have a working solution that you are happy with then that’s great!

1 Like

This looks great. Do you think you could post some more details? YAML examples, etc.? I’d love to set this up, but I’m struggling to follow exactly what you’ve done here.

Hi, I’m only just starting out with home assistant and not that confident with it yet, could you show me the steps involved in how you achieved this standing charge sensor please?

Would you be willing to share your yaml?

I’ve had searched for this solution also, and via a number of topics and development. Created a ‘daily charge’ or ‘Daily Standing Charge’. That takes that charge, as a separate sensor and also divides it over the 24 hour period (no start or end of day spikes).

I’ve attempted to document that process here: GitHub - Rumbaar/Electricity-Daily-Charge-HA: Calculation of a static daily rate charge over 24 hours, inline with the hourly metric of the energy dashboard in Home Assistant. hope it can help at least get you in the right direction. I need to make it more detailed and hoping to make it more step by step detailed.

1 Like

Would it be possible to update these ideas for 2023 as from what I understand it has changed, I have tried to reading Updating Templates with the new default values in 2021.10.x) but have absolutely no idea how to apply anything it says. I have been trying in reference to this (I have copied it exactly as I typed it in so it could even be missing stuff anyway)

energy_cost_today:
friendly_name: Energy Cost Today
unit_of_measurement: £
value_template: “{{ (states(‘sensor.energy_usage_day_std’) | float * states(‘input_number.std_tariff’) | float / 100.0) | float + ((states(‘input_number.standing_charge’) | float / 30.0) | float ) | round(2) }}”

which always gives

“ValueError: Template error: float got invalid input ‘unknown’ when rendering template 'energy_cost_today:”

Maybe this should not of been my first attempt at creating templates lol

Cheers :slight_smile:

This would be the updated template if the energy usage is in kw and with a 5% tax added:

    - unique_id: electricity_cost_today
      unit_of_measurement: £
      state: "{{ (((states('sensor.energy_usage_day_std') | float * states('input_number.std_tariff') | float) | float + (states('input_number.standing_charge') | float )) * 1.05 | float) | round(2) }}"