I have a template sensor to get the relative temperature of the forecast for tomorrow compared to today’s forecast:
- trigger:
- platform: time
at: "00:00"
- platform: event
event_type: forecast_test
action:
- service: weather.get_forecasts
target:
entity_id: weather.home
data:
type: daily
response_variable: my_forecast
sensor:
- name: Forecast temperature difference - tomorrow [weatherball]
state: "{{ my_forecast['weather.home'].forecast[1].temperature - my_forecast['weather.home'].forecast[0].temperature }}"
unit_of_measurement: F
This works. I can see the state in settings and in developer and it is accurate in my testing. I am trying to create an automation based on this sensor, but it keeps giving the error “Error rendering data template: UndefinedError: ‘sensor’ is undefined”
alias: Weatherball
description: ""
trigger:
- platform: event
event_type: weatherball_test
condition: []
action:
- service: light.turn_on
data:
color_name: >
{% if
states(sensor.forecast_temperature_difference_tomorrow_weatherball) |
float > 5 %}
red
{% elif
states(sensor.forecast_temperature_difference_tomorrow_weatherball) |
float < -5 %}
blue
{% elif 5 >
states(sensor.forecast_temperature_difference_tomorrow_weatherball) |
float > -5 %}
green
{% else %}
white
{% endif %}
target:
device_id: 8afa34b1dd524e9c68fcb5f700cbac2c
mode: single
Why am I getting this error when the state is defined everywhere else?