Energy: Add fixed daily cost

Hmmm - tricky. If there is a web page or app with the daily charges on it, you maybe able to download it to a separate entity and then use it with the “Use an entity with current price” option in your energy dashboard. Also this guy @joem seems to have managed to do a bit with Powershop data. Scrape sensor improved - scraping multiple values - #280 by stepsolar
Maybe ask him if he’s solved it ?

Yea so thats the exact code im using to bring the data into the entity. Using your original suggestion and having a bit of a play with it after i posted yesterday, i have it working! This morning it added $1.03 as a fixed charge for the day. Super happy with the result, thanks for sharing your solution. I actually ended up using the same thing for my gas bottle monitoring as well.

What i had todo is create an entity as follows, and then select that as the entity with current price (sensor.powershop_daily_charge being the scraped charge in $) in the energy dashboard:


- platform: template
    sensors:
      powershop_supply_charge_nzd_wh:
        friendly_name: "Powershop Supply Charge NZD Wh"
        unit_of_measurement: "NZD/kWh"
        device_class: monetary  
        value_template: "{{ (states('sensor.powershop_daily_charge') | float * 1000) | round(3) }}"

1 Like

@muzzak - One of the things I have observed is that the daily charge is added at 10pm each evening. Would this be because I setup the entity in your code around then? I was looking for a way to change it so that it is added at the beginning of the day so it shows as part of that days charges.

@Greminn - If you’ve set it up as I did (below for ref) then the sensor will be “total_increasing” every day. That’s using timestamp_custom(“%d”). At midnight it will increase by 1. You can easily check this by looking at the values for sensor “Supply Charge” through HA - Settings, Devices and Services, Entities and search for Supply Charge. It should increase by 1 at midnight every day.

If I take this variant, the counter is reset at the beginning of the month (day 1). Is that correct?

{{ int(as_timestamp(now()) | timestamp_custom("%d")) + 1 - int(as_timestamp("2023-07-01",default=0) | timestamp_custom("%d")) }}

Yep, here is my setup:

  - sensor:
    - name: "Powershop Supply Charge"
      unit_of_measurement: "Wh"
      device_class: energy
      state_class: total_increasing
      state: >-
        {{ int(as_timestamp(now()) | timestamp_custom("%d")) + 1 - int(as_timestamp("2023-08-03") | timestamp_custom("%d")) }}

But as you can see its adding at 10pm…

Looks like a problem with your clock or maybe your timezone settings. You may want to work your way through this How to set time? as your problem looks similar.

Just some backgrounds before I answer.
int(as_timestamp(now()) | timestamp_custom("%d"))
will give you the day of the month as an integer. ie 12th July 2023 returns 12. 31st July returns 31
1st August returns 1
If you are using %d, you could use this as your counter and it would work fine, since the total_increasing sensor will take care of the drop from 31 to 1 New sensor state class: total_increasing | Home Assistant Developer Docs
The second part + 1 - int(as_timestamp(“yyyy-mm-dd”) | timestamp_custom("%d")) is really just to make things nice for other values so you don’t end up with -ve values at the start, in certain cases.
@Herr.Vorragend in your variant you have used “2023-07-01”.
int(as_timestamp(“2023-07-01”) | timestamp_custom("%d")) will always = 1 as explained above, so you’ll have +1 -1 which is 0. Hence you could just use the first part int(as_timestamp(now()) | timestamp_custom("%d")) and still get the same result : Counter = Day of Month

1 Like

Can you share your card yaml for the grid energy please, I’m looking for this exact card for my dashboard


entities:
  - color: '#27ae60'
    entity: sensor.grid_sold_energy_day
    name: Energy Sold
  - color: '#e74c3c'
    entity: sensor.grid_consumed_energy_day
    name: Consumed from Grid
    show_state: true
  - aggregate_func: min
    color: gray
    entity: binary_sensor.night
    name: Night Time
    show fill: true
    show legend: false
    show_line: false
    show_points: false
    show_state: false
    smoothing: false
    y_axis: secondary
points_per_hour: 16
show:
  graph: line
  extrema: false
  labels: false
  labels_secondary: false
  smoothing: false
state_map:
  - label: Day
    value: 'off'
  - label: Night
    value: 'on'
hours_to_show: 24
name: Grid Energy Sold & Bought
type: custom:mini-graph-card

Or this one?


type: horizontal-stack
cards:
  - type: custom:bignumber-card
    entity: sensor.daily_grid_sold
    title: Sold Today
    scale: 20px
  - type: custom:bignumber-card
    entity: sensor.daily_grid_cost
    title: Bought Today
    scale: 20px
  - type: custom:bignumber-card
    entity: sensor.daily_cost_less_sold
    title: Net Cost Today (incl. daily service fee of $1.26)
    scale: 20px

awesome thanks, and for the sensors like daily_grid_sold, i take it i just create a sensor that multiplies the grid total kw / kw/h?


  - platform: template
    sensors:
      grid_usage_pos:
        value_template: "{{ ( -1 * states('sensor.fronius_grid_usage') |float) }}"
      
      fronius_house_load_pos:
        value_template: "{{ (states('sensor.fronius_house_load') |float) | abs }}"
        
      daily_grid_cost:
        friendly_name: 'Daily Grid Cost'
        value_template: >
               {% set value = (states('sensor.grid_consumed_energy_day') | float * 0.307 | round(2) ) %}
               ${{ '{:.2f}'.format(value) }}
      daily_grid_sold:
        friendly_name: 'Daily Grid Sold'
        value_template: >
               {% set value = (states('sensor.grid_sold_energy_day') | float * 0.08 | round(2) ) %}
               ${{ '{:.2f}'.format(value) }}
      daily_cost_less_sold:
        friendly_name: 'Daily Cost less Sold'
        value_template: >
               {% set value = ((states('sensor.grid_consumed_energy_day') | float * 0.307) - (states('sensor.grid_sold_energy_day') | float * 0.08 )) + 1.18 %}
               ${{ '{:.2f}'.format(value) }}

We have fixed costs in The Netherlands so this argument isn’t correct.

Love to see a UX based solution nevertheless :slight_smile:

2 Likes

Disappointing that something as simple as a daily charge hasn’t been added yet, I cant imagine it being too difficult to implement, but would really make the energy dashboard more useful, specially for those on variable tariffs like myself.

3 Likes

I set this up a few days ago. All working fine until this morning (1/1/24) and the sensors (electricity and gas) have both gone negative: -20 and -24 respectively. The difference is probably due to the initial dates I set (22 & 26 Dec). Is this just me or has anyone else seen this problem?

This solution works well and is easy to set up

1 Like

The energy dashboard hasn’t been abandoned, quite the opposite really. Many features have been added over the past 2 years, and more are in the works (check out the open PR’s on GitHub).

Please try to remember that the vast majority of HA features are contributed by volunteers, including many parts of the energy dashboard. You’re being disrespectful to people who volunteer their time to build cool stuff for others, for free.

Regarding the feature itself, you are right, it will never happen. That’s because the energy dashboard is not meant to be a billing management system, it’s meant to give you insight into your electricity consumption, how to reduce your consumption and how to automate your large consumers. Adding fixed costs does not add any meaningful insight in this regard. So yeah, if you really want to add fixed costs, you can use one of the many (terrible) hacks proposed above or otherwise just accept that the energy dashboard is not meant for this purpose.

2 Likes

I tried this and it’s just 0 for me, created them exactly as the link:
Here are the sensors:


This one seems to be going up but on the energy dashboard
image

I have it running for about 2 days now

Hi Andrew just used your code for Standing Charge in homeassistant worked a treat great thanks
just needed to add the word template at the very top of your code in the config file