I’m trying to return the current tariff based upon the day and time but I’m getting the opening part of the code too. What documents should I read to learn what’s up ?
I’ve used Helpers before but it’s my first crack at a template.
Thanks
- platform: template
sensors:
current_tariff:
friendly_name: "Current Tariff"
value_template: >
{% set hour = now().hour %}
{% set weekday = now().weekday() %}
{% if weekday in [0, 1, 2, 3, 4] %} # Monday to Friday
{% if hour >= 14 and hour < 20 %}
Peak
{% elif (hour >= 7 and hour < 14) or (hour >= 20 and hour < 22) %}
Shoulder
{% else %}
Offpeak
{% endif %}
{% else %} # Saturday and Sunday
{% if hour >= 7 and hour < 22 %}
Shoulder
{% else %}
Offpeak
{% endif %}
{% endif %}
Result type: string
-
platform: template
sensors:
current_tariff:
friendly_name: “Current Tariff”
value_template: ># Monday to Friday Offpeak