I’m trying to create a sensor for the Energy dashboard that provides the current price of Electricity.
Unfortunately my templating skills are not up to scratch for a task such as this just yet.
My energy rate works as follows
Weekdays:
0700-1359 - $0.27555
1400-1959 - $0.65626
2000-2159 - $0.27555
2200-0659 - $0.17974
Weekends & Public Holidays:
0700-2159 - $0.27555
2200-0659 - $0.17974
I’m not sure if I’m on the right track, but so far I’ve got the following
- platform: template
sensors:
current_electricity_rate:
value_template: >-
{% set t = strptime(states('sensor.time'), '%H:%M') %}
{%- if t.hour >14 and t.hour <=20 and is_state('binary_sensor.workday_sensor', 'on') -%}0.65626
{%- elif t.hour >7 and t.hour <=14 and is_state('binary_sensor.workday_sensor', 'on') -%}0.27555
{%- elif t.hour >20 and t.hour <=22 and is_state('binary_sensor.workday_sensor', 'on') -%}0.27555
{%- elif t.hour >7 and t.hour <=22 and is_state('binary_sensor.workday_sensor', 'off') -%}0.27555
{%- else -%}0.17974
{%- endif -%}
friendly_name: Current Electricity Rate
unit_of_measurement: AUD/kWh
There seem to be a couple of issues.
Firstly, at 2230 last night it was showing the rate as $0.27555/kWh when it should have been $0.17974/kWh - so there’s obviously something wrong with my template.
Secondly, the Energy panel accepts this sensor I’ve created however it just sits at $0 of usage even though its getting the current energy price from this sensor. Could there be something wrong with the format? Previous attempts it would give an error when trying to add this as the cost sensor, but its no longer giving any errors so I thought it must have been right, but even after a good 12 hours, its still sitting at $0 so clearly something isn’t right.
Would really appreciate some help with this!