Hi, don’t know if this is a feature or a bug, but wanted to bring out my findings. It almost got me crazy this morning.
Below here is a very truncated version of my E-ink display template sensor. It’s fetching weather forecast every 30 mins and updating a sensor (most of the sensor attributes are deleted in this post). While I was debugging the template sensor, I wanted to speed up the refresh from the 30 mins time pattern, so I created another trigger for input_boolean.demo. With that I could trigger the template on demand.
Now the problem is the input_boolean -trigger. If I enable it uncommenting the lines, I’m getting the following error:
Logger: homeassistant.helpers.template
Source: helpers/template.py:2742
First occurred: 10:46:00 AM (1 occurrences)
Last logged: 10:46:00 AM
Template variable warning: ‘hourlytimes’ is undefined when rendering ‘{{hourlytimes}}’
If I trigger the input_boolean, the sensor will update correctly. When the time_pattern triggers, it will create the error. But when input_boolean trigger is commented out, time_pattern works
- trigger:
- platform: time_pattern
minutes: /30
# - platform: state
# entity_id: input_boolean.demo
# to: "on"
variables:
hourlytimes: >
{%- set hourlytimes = [] %}
{%- if now().strftime('%H.%M') < '07.10' %}
{%- set hourlytimes = hourlytimes + ["09:00"] %}
{%- else %}
{%- set hourlytimes = hourlytimes + ["12:00"] %}
{%- endif %}
{{hourlytimes}}
action:
- action: weather.get_forecasts
data:
type: hourly
target:
entity_id: weather.forecast_home
sensor:
- name: eInk WeatherBoard Data
unique_id: eink_weatherboard_data
state: "OK"
attributes:
hourly_times: "{{hourlytimes}}"