Has anyone been able to convert their live energy usage to a live price? For example if i was using 1kWh as that time, it would show me on a sensor that using 1kWh is costing me $0.12c at that time? and would increase and decrease depending on live current usage?
Can someone please show me how this can be done? Thanks!
Hi
What you need to do is find an energy meter that had been integrated into the Home assistant, then you will get the grid consumption in your system.
The price calculation should be done by the HA , not the sensor.
The periodic grid consumption calculation is also done by home assistant
What you need to do is
1 find an energy meter integration in HA that can measure the energy kwh data.(a lot)
2 calculate the periodic energy consumption(daily, monthly) in HA.
3 calculate the periodic energy cost in HA,
(if the electricity price is only a fixed rate,what you need to do is just to multiply the price with the periodic energy consumption dat)
I do it this way. I studied my electricity contract to know which months are - summer vs. winter costs; and when are the peak, part-peak and off-peak hours and hard coded those. The actual price I setup using UI (changes annually).
sensor:
- platform: template
sensors:
current_electricity_cost:
device_class: monetary
friendly_name: Current Electricity Cost
unit_of_measurement: '¢/kWh'
# summer / winter rates
value_template: >-
{% if is_state('sensor.current_electricity_season', 'summer') %}
{% if is_state('sensor.current_electricity_rate_type', 'off-peak')%}
{{states('input_number.summer_off_peak_rate')}}
{% elif is_state('sensor.current_electricity_rate_type', 'part-peak')%}
{{states('input_number.summer_part_peak_rate')}}
{% else %}
{{states('input_number.summer_peak_rate') |float}}
{% endif %}
{% else %}
{% if is_state('sensor.current_electricity_rate_type', 'off-peak')%}
{{states('input_number.winter_off_peak_rate')}}
{% elif is_state('sensor.current_electricity_rate_type', 'part-peak')%}
{{states('input_number.winter_part_peak_rate')}}
{% else %}
{{states('input_number.winter_peak_rate') |float}}
{% endif %}
{% endif %}
current_electricity_cost_usd:
device_class: monetary
friendly_name: Current Electricity Cost (USD)
unit_of_measurement: '$/kWh'
value_template: >-
{{states('sensor.current_electricity_cost') |float /100}}
current_electricity_season:
friendly_name: Current Electricity Season
value_template: >-
{% if now().month >= 6 and now().month < 10 %}
summer
{% else %}
winter
{% endif %}
current_electricity_rate_type:
friendly_name: Current Electricity Rate Type
value_template: >-
{% if now() >= today_at("00:00:00") and now() < today_at("15:00:00")%}
off-peak
{% elif (now() >= today_at("15:00:00") and now() < today_at("16:00:00")) or (now() >= today_at("21:00:00") and now() < today_at("23:59:59"))%}
part-peak
{% else %}
peak
{% endif %}
This is the best setup I’ve seen related to ease of use for differing tariffs. Digging into the sensor it looks like you have the exact same PG&E shenanigans as I do. Do you use this to display total costs on the energy dashboard, or just here in the UI you created?
I would LOVE a hand helping me implement this.
EDIT: Upon further investigation it doesn’t seem like you necessarily have these connected to any sensor monitoring actual energy use do you?
This allows to setup tariffs and provides UI for reference.
You can use sensor.current_electricity_cost_usd from the above when you setup the energy dashboard. For example, I have a clamp that monitors my subpanel, and it’s setup like so…
The output of above is “Unkown”. I think {{(states('input_number.summer/winter_offpeak/peak'))}} is not getting created/updated.
The sensors sensor.current_electricity_season and sensor.current_electricity_rate_type is working and I see the correct output.
My utility meter has tarriffs as peak, offpeak
and switching the tarriff using your code
current_electricity_rate_type:
friendly_name: Current Electricity Rate Type
value_template: >-
{% if now() >= today_at("14:00:00") and now() < today_at("18:59:59")%}
peak
{% else %}
offpeak
{% endif %}