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

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

Yes the utility meter was only just created.

But your off peak is reading zero which seems unrealistic to me. So is the automation working? I see the peak graph flatlining at the right times, but the off peak is not changing.

Im not sure what I am doing wrong, it shows a cost, but doesnt seem to be tracking it correctly, and doesnt reset at midnight. I am in the UK, trying to implement this for a daily cost:

input_number:
  kwh_cost:
    name: kwh_cost
    initial: 0.35
    min: 0.34
    max: 0.35
  standing_charge:
    name: standing_charge
    initial: 0.42
    min: 0.41
    max: 0.42

utility_meter:
  electricity_imported_billing_day:
    source: sensor.house_power_power
    name: Electricity Imported Billing Day
    cron: 0 0 * * *

sensor:
  - platform: template
    sensors:
      monthly_cost_tracked:
         friendly_name: "Energy Cost Daily"
         unique_id: energy_cost_daily
         unit_of_measurement: "£"
         value_template: >-
           £{{((states('sensor.electricity_imported_billing_day')|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)}}

i dont think the automation is running properly checking the YAML has errors

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

Yes you need to fix your data line. See the example I gave you earlier.

You have a daily utility meter but your template sensor multiplies the daily charge by the day of the month so it’s increasing every day and not going back to 0