I have a template that renders a timestamp that indicates when precipitation is expected. The device class set to timestamp to take advantage of time formatting in the front end.
If the timestamp is not valid (no precipitation) the template renders a value of none
which results in an entity value of unknown. For regular templates this works just fine. However, if I change that template to a trigger based template I get the following warning on startup and when templates are reloaded.
WARNING (MainThread) [homeassistant.components.sensor.helpers] sensor.precipitation_start rendered invalid timestamp: None
The trigger based template actually works fine, I’m just wondering why the warning appears when a trigger based template is used instead of a regular one.
Template Sensor YAML
- trigger:
- platform: homeassistant
event: start
- platform: event
event_type: event_template_reloaded
- platform: time_pattern
minutes: 15
- platform: state
entity_id:
- binary_sensor.rain
- binary_sensor.snow
sensor:
- name: "Precipitation Start" # next 12 hours
unique_id: precipitation_start
icon: mdi:weather-pouring
device_class: timestamp
state: >
{% set forecast = none %}
{% set time = namespace(value=none) %}
{% if state_attr('sensor.weather_forecasts', 'envcan_hourly') != none %}
{% set forecast = state_attr('sensor.weather_forecasts', 'envcan_hourly') %}
{% elif state_attr('sensor.weather_forecasts', 'weatherflow_hourly') != none %}
{% set forecast = state_attr('sensor.weather_forecasts', 'weatherflow_hourly') %}
{% elif state_attr('sensor.weather_forecasts', 'pirate_hourly') != none %}
{% set forecast = state_attr('sensor.weather_forecasts', 'pirate_hourly') %}
{% endif %}
{% if is_state('binary_sensor.snow', 'on') %}
{% set time.value = states.binary_sensor.snow.last_changed %}
{% elif is_state('binary_sensor.rain', 'on') %}
{% set time.value = states.binary_sensor.snow.last_changed %}
{% elif forecast not in ['', none] %}
{% for item in forecast %}
{% if loop.index0 < 12
and item.precipitation_probability | int(-1) >= 50
and (item.condition | contains('rain')
or item.condition | contains('snow')
or item.condition | contains('storm')) %}
{% set time.value = item.datetime %}
{% break %}
{% endif %}
{% endfor %}
{% endif %}
{{ time.value }}
attributes:
12hour: >
{% from 'speech.jinja' import twelve_hour %}
{{ twelve_hour(this.entity_id) }}
provider: >
{% if state_attr('sensor.weather_forecasts', 'envcan_hourly') != none %}
Environment Canada
{% elif state_attr('sensor.weather_forecasts', 'weatherflow_hourly') != none %}
WeatherFlow Cloud
{% elif state_attr('sensor.weather_forecasts', 'pirate_hourly') != none %}
Pirate Weather
{% endif %}
availability: >
{{ state_attr('sensor.weather_forecasts', 'envcan_hourly') != none
or state_attr('sensor.weather_forecasts', 'weatherflow_hourly') != none
or state_attr('sensor.weather_forecasts', 'pirate_hourly') != none }}