Energy fixed costs

Possibility for fixed cost details - Yes please.
Readers, please vote for this (top left of this page). :point_up:

Fixed pricing based on time (month/year) is a thing here in Sweden as well.
I.e. the price is not at all connect to the amount of kWh used. The price is the same if you use 0 or, 10000 kWh.
These things are only connected to time (month/year…)
But, they show up on the electricity bill nevertheless. :face_with_raised_eyebrow:

Perhaps best if we add our fixed prices in cost/hour, so it mesh well with kWh.
But that is easily calculated.

2 Likes

Hello Miquel,

While we’re waiting for your excellent suggestion to be implemented, :smiley: could you share more details on how you set up the “dummy sensor with 0 fixed value and total cost entity”?

I created the template sensor, but when I add it I end up “multiplying by 0” since the sensor use 0 kWh. Resulting in fixed cost of 0, due to the multiply by 0. :roll_eyes:
In other words, could we ask you to show your zero-kWh-sensor-setup - end to end? And please show some code too, if possible.

Also, thanks for suggesting to Home Assistant to include this great feature “out of the box”.

/Richard, from Sweden.

1 Like

Hi!

I created two sensors. First, a dummy sensor that always return 0, for other hand, a sensor that every day sum all my fixed costs

template:  

  - sensor:
     - name: "Potencia y cuota"
       unique_id: Potencia y cuota
       state: 0
       unit_of_measurement: kWh
       device_class: energy
       state_class: total_increasing
  
  - trigger:
      - platform: time_pattern
        minutes: 5
        seconds: 0
        hours: 0
    sensor:  
      name: "Costes fijos"
      unique_id: "costes_fijos"
      unit_of_measurement: "€"
      state_class: total_increasing
      state: | 
        {{ states('sensor.costes_fijos') | float(0) 
          + states('input_number.potencia_valle') | float(0) * states('input_number.precio_potencia_valle') |float(0)
          + states('input_number.potencia_punta') | float(0) * states('input_number.precio_potencia_punta') | float(0)
          + states('input_number.cuota_lidera') | float(0) / 30.0
          + states('input_number.bono_social') | float(0) / 30.0 }}


You must use “total cost entity” so HA don’t multiply, only save the diff.

You only need change the formula for you use (and change the names)

2 Likes

Thank you very much! :+1:

Just a follow-up question. The prices in your

"Costes fijos"

Do you state them as cost per day, or cost per hour, or…?
Just trying to figure out what multiple to use.
For example, 0.16947 (per hour) or 4.067 (per day) (016947 * 24)…

Is cost by day.

If you look the time_pattern, only update one time each day (at 00:05).

And one question for you… 4€ fixed by day?!! My fixed cost by day are 0.42€.

1 Like

Hahaha, very valid question. :smiley:
The “4” in my example is in SEK (Swedish Krona). It is roughly = 0.4€.
So pretty much the same as you.

Thanks again for the crystal clear instructions.
Have a nice day.

1 Like

This workaround won’t be suitable for everyone, but as I have my energy data in influxdb, I use the integration and a flux query to create a sensor that accounts for the standing charge.

- platform: influxdb
  api_version: 2
  ...
  queries_flux:
  - name: import_cost_today
    range_start: "today()"
    unit_of_measurement: "GBP"
    imports:
      - date
    query: |
        filter(fn: (r) => r["_measurement"] == "mqtt_consumer" and r["topic"] == "emon/power/import")
        |> integral(unit: 1h)
        |> map(fn: (r) => ({
            _value: r._value * 0.001 * {{ sensor.daily_rate }} + {{ sensor.standing_charge }},
            _time: r._stop})
         )

Or for a time-of -day tariff:

- platform: influxdb
  api_version: 2
  ...
  queries_flux:
  - name: import_cost_today
    range_start: "today()"
    unit_of_measurement: "GBP"
    imports:
      - date
    query: |
        filter(fn: (r) => r["_measurement"] == "mqtt_consumer" and r["topic"] == "emon/power/import")
        |> window(every: 30m)
        |> integral(unit: 1h)
        |> map(fn: (r) => ({
          _value: if r._stop > date.add(to: today(), d: 5h30m) and r._stop <= date.add(to: today(), d: 23h30m) then 
                    r._value * {{ sensor.peak_rate }}
                  else 
                    r._value * {{ sensor.off_peak_rate }}, 
          _time: r._stop}))
        |> sum()
        |> map(fn: (r) => ({_value: r._value * 0.001 + {{ sensor.standing_charge }}, _time: now()}))

Thanks for the great solution to include fixed costs in the energy dashboard. It works great!

Just to help others, I share a slightly modified approach for the second sensor that is triggered at 00:05.

I update the sensor every hour and changed the calculation from relative (add daily cost at 00:05) to an absolute calculation (hours*hourly_costs)
Reason: If HA is not running during the trigger time (at 00:05), it will miss the daily cost for that day.
For the value, I therefore calculate the hours passed since I started to track fixed cost and multiply that with the costs per hour. So if HA is down, it will catch up later adding the missing hours:

- trigger:
  - platform: time_pattern
    hours: "/1"
  sensor:  
  - unique_id: vastrecht_elektra_per_uur
    name: "vastrecht elektra"
    unit_of_measurement: "€"
    state_class: total_increasing
    state: |
      {% set hours=((as_timestamp(now())-as_timestamp(as_datetime('2023-09-06'))) / 3600)  %}
      {{ (hours+1) * 0.046 }}

Note1: just enter the date of the day you create this sensor
Note2: 0.046 is the total fixed cost per hour for my provider. Of course you can look them up from input helpers, as done in the original. But this is a little more readable.

1 Like

+1!! Here in Italy fixed costs are huge! (we also have a national tv fixed cost in our electricity bills!)

HA users have had this Energy Dashboard for at least a year now, or maybe more? And despite several users from different countries (I am speaking from the UK) stating that we have fixed daily standing charges, the dashboard that was touted as a massive new feature to manage costs, has been completely neglected. YES, NEGLECTED by Home Assistant. Not everyone has to be a developer. Most people using HA are normal users, just wanting something that works.

And when as a user that person invests significant time and money to use this platform with promises that it is maintained, nothing is more irritating than reporting the same issue for more than a year with nothing concrete being done about it. HA needs to get real and add this feature. If I knew how to code, I would. But I definitely know how to complain about stuff, so here I am. Will my comment be well-received? No, complaints and open source are never a good match, but that’s the problem right there: if open source services and products want a chance to become anything on any market, they need to be treated exactly the same as paid privately-made closed-source products and services, and vendors are open to receiving complaints in those cases, so should HA. I also must add - HA is funded by Nabu Casa subscriptions, so there is in fact quite a lot of revenue on the background. HA cannot expect to be treated like a good open source angel when it’s a money-hungry private business like any other in reality. Nabu Casa is taking money, so HA can take criticism.

I would like to see this before the end of 2023, because standing charges are now taking a huge chunk of money from customer’s bank accounts every month and it’s helpful to have a dashboard that reflects the true cost rather than just kWh usage.

I do not want to create custom sensors. I want a field for a standing charge entity just like I have for the kWh cost. I get all this data from Hildebrand Glow, it’s a complete waste and oversight from HA to create a dash that ignores the energy market realities of so many countries as evidenced in this thread and others.

2 Likes

Why you not use a private platform? Ah, yes… All private platforms are several years behind Home Assistant…

HA es Open Source, a big BIG open source project with several new features every month. Do you want a specific feature and you’re not developer? Ok, pay a developer to develop it and make a pull request to add to HA.

I knew a comment like this was coming and I don’t care. Do you know WHY the other platforms are several years behind? Because they have become complacent. You are living in illusion if you don’t think the same thing can happen to HA. There are at least 169 people who want/need the feature as of the time of writing this reply. So unless you are working to push FORWARD for development, get down from your little soap box and go away because your defensiveness is nothing but a push for complacency and laziness. I don’t mind being unpopular and being seen as the c#nt as long as I get results - and my track record posting complaints is testament that I do. Because this isn’t just whining - it is a completely logical argument, whether you like it or not. Not gonna see if you reply so maybe don’t bother.

It is very funny because I am the original author of the post, and others users and me make alternatives to get fixed costs xD

1 Like

Can anyone provide one sample for the UK energy markets please - I am struggling with what I am reading above and would love to understand it better, thanks in advance!

I use Octopus Energy in the UK (with a HomeMini) and just used @erkr instructions above to add an hourly Standing Charge.

I just added this to my configuration.yaml:

template:  
  - sensor:
     - name: "Electricity Standing Charge"
       unique_id: Electricity Standing Charge
       state: 0
       unit_of_measurement: kWh
       device_class: energy
       state_class: total_increasing
  - trigger:
    - platform: time_pattern
      hours: "/1"
    sensor:  
    - unique_id: standing_charge_per_hour
      name: "standing charge per hour"
      unit_of_measurement: "£"
      state_class: total_increasing
      state: |
        {% set hours=((as_timestamp(now())-as_timestamp(as_datetime('2023-11-10'))) / 3600)  %}
        {{ (hours+1) * 0.025075 }}

  - sensor:
     - name: "Gas Standing Charge"
       unique_id: Gas Standing Charge
       state: 0
       unit_of_measurement: kWh
       device_class: energy
       state_class: total_increasing
  - trigger:
    - platform: time_pattern
      hours: "/1"
    sensor:  
    - unique_id: gas_standing_charge_per_hour
      name: "gas standing charge per hour"
      unit_of_measurement: "£"
      state_class: total_increasing
      state: |
        {% set hours=((as_timestamp(now())-as_timestamp(as_datetime('2023-11-11'))) / 3600)  %}
        {{ (hours+1) * 0.0114458333 }}

And then added a new Electricity Consumption & Gas Consumption to my Energy Dashboard thus:

The 0.025075 and the 0.0114458333 are the Hourly amounts of my Daily Standing Charge.

However, I’m not sure I like using an Hourly Standing Charge, as my Energy Provider obviously charges daily. So I think I would prefer to see a Daily Charge added just after midnight, although I’m unsure how to alter the template sensors to allow for this.

Have a look at Energy - How to account for daily standing charge? - #29 by bjeanes

I followed this and now have a daily standing charge added at start of day :+1:t2:

1 Like

Thanks for posting as I’m also with Octopus Energy, what do use for the Electricity cost?

I had this all working in my last HA setup but did a clean build and it’s not the correct usage.

My previous config

# Shelly electric sensor
  - platform: template
    sensors:
      electricity_kwh_unit_price:
        friendly_name_template: "Electricity Unit Price"
        value_template: "0.2620"
        unit_of_measurement: "£/kWh"
      electricity_standing_charge_price:
        friendly_name_template: "Electricity Standing Charge Price"
        value_template: "20.1083" # (£0.4567 per day * 1000) / 24
        unit_of_measurement: "GBP/kWh"

I’m not sure what you mean by “what do you use for the Electricity cost” ?

I have an ‘Octopus HomeMini’ to get my SmartMeter data into HomeAssistant (if you don’t have one, you should get yourself on the waiting list to get one - just Google it).

I then use the Octopus Energy Integration from BottlecapDave to get the data into HomeAssistant. I believe you can also use it if you don’t have a HomeMini. Follow the ‘setup instructions’ here:

I count costs deliberately hourly, as the energy dashboard has an hour granularity in the daily view. This avoids a jump in costs around midnight