Hello,
I have had some automation running for over a year and after HA updates one stopped working. Traced it back to a triggered sensor not having any value (or rather in this case the attribute not sensor).
If I just copy/paste the attribute script to the template, it works fine. But it never is triggered any more…
All help appreciated
- trigger:
- platform: time
at: input_datetime.carcharge_night_start
sensor:
- name: night_charge_scheduler
unit_of_measurement: ""
state: >-
{{ 'NaN' }}
attributes:
charging_schedule: >
{% set charge_time = states('input_number.CarCharge_time') | int -%}
{% set night_start = states('input_datetime.CarCharge_Night_Start') | truncate(3, False, '.', 0) | int -%}
{% set night_end = states('input_datetime.CarCharge_Night_End') | truncate(3, False, '.', 0) | int -%}
{% set final_prices = namespace(values = state_attr('sensor.total_electricity_price', 'price_list')) -%}
{% set night = namespace(values = []) -%}
{% for price in final_prices.values -%}
{% if (loop.index0 >= night_start) and (loop.index0 < (night_end + 24)) -%}
{% set night.values = night.values + [{'time':loop.index0 % 24, 'price':price}] -%}
{% endif -%}
{% endfor -%}
{{ ((night.values | sort(attribute='price'))[:charge_time]) | sort(attribute='time') }}