Calculation of a static daily rate change for Electricity over 24 hours, inline with the hourly metric of the energy dashboard in Home Assistant.
As of Home Assistant 2023.5 the inclusion of a daily flat Electricity rate within the Energy Dashboard and overall calculations isn't present or easily created to offer flat rate calculated over the 24 hour (hourly) daily dashboard. Inspired by a hourly rate present in a locally available power monitor device (Powerpal) and hourly calcuations of HA Energy dashbaord this repository will look to create an energy sensor that will allow the input of a flat rate and then have that value split over the full day for a (at best) realtime cost.
Example for the Australian Electricity Market; suppliers charge a flat daily rate of say $1.24, that is calcuated and added for each day of usage on top of the actual power usage that is calculatee per kWH of import from the grid.
{
"version": 1,
"minor_version": 1,
"key": "input_number",
"data": {
"items": [
{
"id": "electricitydaily",
"min": 0.0,
"max": 1500.0,
"name": "ElectricityDaily",
"icon": "mdi:currency-usd",
"step": 0.01,
"unit_of_measurement": "AUD/kWh",
"mode": "box"
}
]
}
}
{
"version": 1,
"minor_version": 1,
"key": "input_datetime",
"data": {
"items": [
{
"id": "dailychargestarttime",
"has_time": true,
"has_date": true,
"name": "DailyChargeStartTime",
"icon": "mdi:clock-time-twelve-outline"
}
]
}
}
Create an automation to reset the Date/Time at the start of the day to reset the usage calcuation for the day, raw YAML in automation.yaml. You'll need to define the "Actions" code via "Edit in YAML" as the syntax required isn't avalable via the visual editor (as of 2023.5).
alias: Reset DailyChargeTimer at Midnight
description: ""
trigger:
- platform: time
at: "00:00:00"
condition: []
action:
- service: input_datetime.set_datetime
data:
datetime: "{{ (now() | string)[:19] }}"
target:
entity_id: input_datetime.dailychargestarttime
mode: single
Add the Energy Sensor code for the "DailyCharge" entity to the appropriate configuration.yaml file.
template:
- sensor:
- name: "DailyCharge"
unique_id: "7ac7c3b4-1238-4961-9b61-cc2cc8sample"
unit_of_measurement: "kWh"
device_class: energy
state_class: total_increasing
icon: mdi:solar-power
state: >
{{ (((as_timestamp(states('sensor.date_time_iso'))) - (as_timestamp(states('input_datetime.dailychargestarttime')))) / 86400 * 0.001) | round(5) }}
Restart Home Assistant
Define the new "DailyCharge" sensor via your Energy Dashbaord settings under Electricity grid => Grid consumption, and set the 'Use an entity with current price' with the "ElectricityDaily" Helper entity defined earlier. It can take 24 hours for the values and figures to be correct.