neilc2
January 4, 2024, 12:03am
1
I’m trying to come up with a template using helpers to switch between day and night rate tariff in the energy dashboard for imported energy. Start time for peak is 08:00 and end time is 23:00. Using my template below it just stays at peak rate at all times. Any ideas where I’m going wrong?
name: 'Energy Import Cost'
unique_id: "energy_import_cost"
unit_of_measurement: 'EUR/kWh'
state: >
{% set tariff = { "Day": 0.3836, "Night": 0.1840 } %}
{% set time = { "month": (now().strftime('%m') | int), "hour": (now().strftime('%H') | int), "weekday": (now().weekday() | int ) } %}
{%if ( 'input_datetime.end_charge_time' > now().strftime('%H.%M') < 'input_datetime.start_charge_time') %}
{{ tariff.Day }}
{% else %}
{{ tariff.Night }}
{% endif %}
tom_l
January 4, 2024, 1:08am
2
template:
- sensor:
- name: 'Energy Import Cost'
unique_id: "energy_import_cost"
unit_of_measurement: 'EUR/kWh'
state: >
{% set tariff = { "Day": 0.3836, "Night": 0.1840 } %}
{% if today_at(states('input_datetime.start_charge_time')) < now() < today_at(states('input_datetime.end_charge_time')) %}
{{ tariff.Night }}
{% else %}
{{ tariff.Day }}
{% endif %}
1 Like
neilc2
January 4, 2024, 3:06pm
3
tom_l:
- name: 'Energy Import Cost'
unique_id: "energy_import_cost"
unit_of_measurement: 'EUR/kWh'
state: >
{% set tariff = { "Day": 0.3836, "Night": 0.1840 } %}
{% if today_at(states('input_datetime.start_charge_time')) < now() < today_at(states('input_datetime.end_charge_time')) %}
{{ tariff.Night }}
{% else %}
{{ tariff.Day }}
{% endif %}
Thank you very much, works perfect!
1 Like
123
(Taras)
January 4, 2024, 3:15pm
4
Another way to do the same thing using an Immediate If .
template:
- sensor:
- name: 'Energy Import Cost'
unique_id: "energy_import_cost"
unit_of_measurement: 'EUR/kWh'
state: >
{% set is_night = today_at(states('input_datetime.start_charge_time')) < now() < today_at(states('input_datetime.end_charge_time')) %}
{{ iif(is_night, 0.1840, 0.3836) }}
1 Like