Hello, I do need some help with this template sensor. It is throwing the error:
- Invalid config for ‘sensor’ from integration ‘template’ at sensor.yaml, line 16: invalid template (TemplateSyntaxError: expected token ‘end of statement block’, got ‘if’) for dictionary value ‘sensors->electricity_price->value_template’, got ‘{% if now().hour() >= 23 %}0.04 {% elif now().hour() >= 7 %}0.04 {% elif now().month() >= 5 \n and now().month() <9\n if now().weekday() < 5 \n if now().hour() >= 14 \n and now().hour() <=19%}.30 \n {%else%}.12\n {%else%}.12\n{%else%}.12 {% endif %}"\n’, please check the docs at Template - Home Assistant
- platform: template
sensors:
electricity_price:
friendly_name: Electricity price
unit_of_measurement: USD
value_template: >
{% if now().hour() >= 23 %}0.04
{% elif now().hour() >= 7 %}0.04
{% elif now().month() >= 5
and now().month() <9
if now().weekday() < 5
if now().hour() >= 14
and now().hour() <=19%}.30
{%else%}.12
{%else%}.12
{%else%}.12
{% endif %}"
Those docs are not easy to consume. Any tips?
I’m trying to codify this logic:
Super Off-peak
Every day of the year from 11 p.m. – 7 a.m. It’s cheapest for Georgia Power to produce electricity during these hours so the savings are passed on to you. About 33% of the hours in a year fall in the Super Off-peak time period and it’s the lowest price. : .04
Off-peak
All hours of the year not identified as On-Peak or Super Off-peak From June to September, weekdays from 7 a.m. to 2 p.m. and 7 p.m. to 11 p.m., and during weekends from 7 a.m. to 11 p.m. For October to May, this period is from 7 a.m. to 11 p.m. Prices during this period are higher than the Super Off-peak time period, but much lower than the On-peak time period. The majority of the hours in a year (62%) fall in the Off-peak time period. :.12
On-peak
Period from June to September, weekdays 2 p.m. to 7 p.m. represents the time when it’s the most expensive for Georgia Power to produce electricity. Although the On-peak period has the highest prices, only about 5% of the hours during a year fall in this period. :.30