In-case it helps anyone else, see sensor:
created to adjust energy pricing tariff based on time of day. This may be overly complex compared to other countries but Ausgrid in Australia have peak periods during specific hours in Winter and Summer months, Shoulder period and then Offpeak rates per Time of use pricing - Ausgrid
- platform: template
sensors:
energy_tariff:
friendly_name: My Energy Tariff
unit_of_measurement: 'AUD/kWh'
value_template: >
{% set tariff = { "Peak": 0.5, "Shoulder": 0.28, "OffPeak": 0.18 } %}
{% set time = { "month": (now().strftime('%m') | int), "hour": (now().strftime('%H') | int), "weekday": (now().weekday() | int ) } %}
{%if (time.hour > 21) or (time.hour < 7) %}
{{ tariff.OffPeak }}
{%elif ((time.month > 10) or (time.month < 4)) and (time.weekday < 5) %}
{%if (time.hour > 13) and (time.hour < 20) %}
{{ tariff.Peak }}
{%else%}
{{ tariff.Shoulder }}
{%endif%}
{%elif ((time.month > 5) and (time.month < 9)) and (time.weekday < 5) %}
{%if (time.hour > 16) and (time.hour < 21) %}
{{ tariff.Peak }}
{%else%}
{{ tariff.Shoulder }}
{%endif%}
{%else%}
{{ tariff.Shoulder }}
{%endif%}
or
- platform: template
sensors:
your_tariff:
friendly_name: My Tariff
unit_of_measurement: 'AUD/kWh'
value_template: >
{% set tariff = { "Peak": 0.5, "Shoulder": 0.28, "OffPeak": 0.18 } %}
{% set time = { "month": (now().strftime('%m') | int), "hour": (now().strftime('%H') | int), "weekday": (now().weekday() | int ) } %}
{%if (time.hour > 21) or (time.hour < 7) %}
{{ tariff.OffPeak }}
{%elif ((time.month > 10) or (time.month < 4)) and (time.weekday < 5) and ((time.hour > 13) and (time.hour < 20)) %}
{{ tariff.Peak }}
{%elif ((time.month > 5) and (time.month < 9)) and (time.weekday < 5) and ((time.hour > 16) and (time.hour < 21)) %}
{{ tariff.Peak }}
{%else%}
{{ tariff.Shoulder }}
{%endif%}
EDIT: Added unit_of_measurement: 'AUD/kWh'
which I realised I didnt copy over after seeing @nd100 post - unit_of_measuremeant:
is required for Energy dashboard to use the sensor