How to make a card in Lovelace that tells you How much You’ll pay on the electricity bill

Hi!

I currently have a shelly installed on my electric board, and it’s taking good measurements and telling me how much I spent in that day (since i told hassio how much 1 kWh is).

But I would like to have a card on my dashboard that accumulates how much I spent everyday until it’s pay day (day 3 of every month).

Could anyone help me out on this? Kinda a big noob around here eheh.

Thank you so much for your time!

1 Like

Create a utility meter that resets on the third of each month ( Crontab.guru ) using the shelly usage sensor as it’s source

utility_meter:
  electricity_imported_billing_month:
    source: sensor.shelly_usage
    name: Electricity Imported Billing Month
    cron: 0 0 3 * *

Create a template sensor that takes the utility meter sensor and multiplies it by the electricity price.

template:
  - sensor:
      - name: "Electricity Cost Billing Month"
        unique_id: electricity_cost_billing_month
        unit_of_measurement: "$"
        state: {{ states('sensor.electricity_imported_billing_month') | float(0) * 0.12345 }}

You can then use that sensor however you like. An entities card, a graph, a guage etc.

3 Likes

If you are in the UK you can also incorporate your standing charge (using input_numbers) like this :

  - platform: template
    sensors:
      monthly_cost_tracked:
         friendly_name: "Energy Cost Monthly"
         unique_id: energy_cost_monthly
         unit_of_measurement: "£"
         value_template: >-
           £{{((states('sensor.energy_usage_monthly')|float(default=0)*states('input_number.kwh_cost')|float(default=0)) + (states('input_number.standing_charge')|float(default=0)*now().day|int(default=0)))|round(2)}}

End result :

image

Yep it can be very complex if required. I have 6 tariffs and a daily charge to consider personally.

1 Like

This definitely helped and I think it did the job, Well… now I have to wait for September 3 :stuck_out_tongue_closed_eyes: Thank you so much!

2 Likes

UK user here

what would be the code to use for a dual tarrif?

im 44p during 5:30am-11:30pm and 10p during 11:30pm-5:30am

please?!

also which file / directory im i editing here for this sensor?

At minimum, you need a utility meter which has two tariffs and the source sensor is your electricity usage

Then you need an automation which changes the tarrif on that utility meter at the appropriate times (time triggers) so your one usage sensor gets split between the two tarrifs at appropriate times.

Then you need a template sensor which does the calculation of the cost for you. multiplying the lower tarrif usage by the lower tarrif and the higher tarrif usage by the higher tarrif and adding them together to give a daily usage.

@SgtBatten

I have utility meter installed and the source sensor is my daily eletric usage.

If i start basic and just add in a flat rate this is where things get stuck for me.

Where would i find the calculation for the sensor and where would i use this sensor?

Post what you have so far

This is me so far

image

image

Thats all i have

Here is how I track my very complex tariffs [GUIDE] Australian Electricity Demand tariffs (e.g AGL)

You will need to create a utilty meter with the two tariffs for the energy usage:

utility_meter:
  electricity_imported_power_daily:
    source: sensor.electricity_imported_power_kwh
    name: Electricity Imported Power Daily
    cycle: daily
    tariffs:
      - peak
      - off-peak

Then an automation to set the tariff at the correct time:

alias: Set Electricity Tariff
description: ''
trigger:
  - platform: time
    at: '05:30:00'
  - platform: time
    at: '23:30:00'
  - platform: homeassistant
    event: start
condition: []
action:
  - service: select.select_option
    data:
      option: >-
        {% set t = now() %}  {%- if t.hour < 5 or (t.hour = 5 and t.minute < 30) or (t.hour = 23 and t.minute >= 30) %}
          off-peak
        {%- else -%}
          peak
        {%- endif -%}
    target:
      entity_id:
        - select.electricity_imported_power_daily
mode: single

Then a template sensor to add the costs together

template:
  - sensor:
      - name: Total Daily Electricity Cost
        icon: mdi:currency-usd
        state_class: total_increasing
        device_class: monetary
        unit_of_measurement: $
        state: >
          {% set supply = 0.xx %}
          {% set offpeak = states('sensor.electricity_imported_power_daily_off_peak') | float(0) * 0.10 %}
          {% set peak = states('sensor.electricity_imported_power_daily_peak') | float(0) * 0.44 %}
          {{ (supply + offpeak + peak) | round(2) }}

You can easily adapt this for monthly etc.

thanks very detailed and helpful

im getting an error on creating the sensor as i think the method/syntax has changed?

my other sensors are set like this

sensor:
  - platform: template
    sensors:
        solar_pv_voltage_total:
            friendly_name: "Combined Solar PV Voltage"
            unit_of_measurement: 'V'
            value_template: '{{ states("sensor.solax_pv_voltage_1") |float + states("sensor.solax_pv_voltage_2") | float }}'

your sensor I have set like this to try and conform to the new syntax but getting error

sensor:
  - platform: template
    sensors:
        monthly_eletric_cost3:
            friendly_name: "Total Daily Electricity Cost"
            icon: mdi:currency-usd
            device_class: monetary
            state_class: total_increasing
            unit_of_measurement: '£'
            state: >
          {% set supply = 0.xx %}
          {% set offpeak = states('sensor.smart_meter_electricity_import_today') | float(0) * 0.10 %}
          {% set peak = states('sensor.smart_meter_electricity_import_today') | float(0) * 0.44 %}
          {{ (supply + offpeak + peak) | round(2) }}        

image

i have also created 2 utility sensors

That both reference sensor.smart_meter_electricity_import_today

My template sensor is the new format. Your others are the old format. Template docs

You should create One utility meter with two tarrifs. Not two seperate utility meters. It will give you two sensors, one for peak and one for off peak. (Or whatever tariff names you choose)

You need to set the supply charge (I put 0.xx as an example only.) If you do not have a daily supply charge, set it to 0 or fix the template to remove references to supply.

Ok i have deleted and re-created utility meter with off-peak & peak in the tarrif section.

but im still struggling to get the template sensors in the right format to work in conjunction of my other sensor code

template:
  - sensor:
      - name: Total Daily Electricity Cost
        icon: mdi:currency-usd
        state_class: total_increasing
        device_class: monetary
        unit_of_measurement: £
        state: >
          {% set offpeak = states('sensor.electricity_imported_power_daily_off_peak') | float(0) * 0.10 %}
          {% set peak = states('sensor.electricity_imported_power_daily_peak') | float(0) * 0.44 %}
          {{ (offpeak + peak) | round(2) }}

I’ve simplified it a bit in case the supply was causing you issues.
It’s already in the right format. Put it in configuration.yaml

It won’t work in sensors.yaml (assuming you are doing it that way) because it’s not a sensor integration it’s a template integration.

You just need to change the peak and off-peak sensor names to match the utility meter tariff ones you should now have

i get this error when putting in configuration.yaml

       
 
sensor:

  - platform: waste_collection_schedule
    source_index: 0
    name: Rubbish  # Change this to whatever you want the UI to display
    details_format: generic
    date_template: '{{value.date.strftime("%A %d %B %Y")}}'  # date format becomes 'Tuesday 1 April 2022'
    value_template: 'in {{value.daysTo}} days'

  - platform: waste_collection_schedule
    source_index: 1
    name: Recycling  # Change this to whatever you want the UI to display
    details_format: generic
    date_template: '{{value.date.strftime("%A %d %B %Y")}}'  # date format becomes 'Tuesday 1 April 2022'
    value_template: 'in {{value.daysTo}} days'

  - platform: waste_collection_schedule
    source_index: 2
    name: Garden  # Change this to whatever you want the UI to display
    details_format: generic
    date_template: '{{value.date.strftime("%A %d %B %Y")}}'  # date format becomes 'Tuesday 1 April 2022'
    value_template: 'in {{value.daysTo}} days'


template:
  - sensor
      - name: Total Daily Electricity Cost
        icon: mdi:currency-usd
        state_class: total_increasing
        device_class: monetary
        unit_of_measurement: £
        state: >
          {% set offpeak = states('sensor.electricity_imported_power_daily_off_peak') | float(0) * 0.10 %}
          {% set peak = states('sensor.electricity_imported_power_daily_peak') | float(0) * 0.44 %}
          {{ (offpeak + peak) | round(2) }}

image

I missed a colon after the word sensor

so i now have set

template:
  - sensor:
      - name: Total Monthly Electricity Cost
        icon: mdi:currency-usd
        state_class: total_increasing
        device_class: monetary
        unit_of_measurement: £
        state: >
          {% set offpeak = states('sensor.utilitymeter_monthly_cost_off_peak') | float(0) * 0.10 %}
          {% set peak = states('sensor.utilitymeter_monthly_cost_peak') | float(0) * 0.44 %}
          {{ (offpeak + peak) | round(2) }} 

which shows me

image

not sure why its showing £12

It’s just doing math. So what’s the utility meter entities saying?


image

i presume its only making a calc from 25th march