Template editor error

I am trying to test out a template in the template editor under developer tools. I practically copy/pasted most of what I have in there from another topic here but I get the error “UndefinedError: ‘daily_forecast’ is undefined”

Am i not defining it here under “response_variable”?

- trigger:
    - trigger: time_pattern
      hours: /1
    - trigger: homeassistant
      event: start
  action:
    - action: nws.get_forecasts_extra
      data:
        type: twice_daily
      target:
        entity_id: weather.kofp
      response_variable: daily_forecast
  sensor:
    - name: "NWS Daily Forecast"
      unique_id: "nws_daily_forecasts"
      state: "{{now() }}"
      attributes:
        forecast_0: "{{ daily_forecast['weather.kofp'].forecast[0].detailed_description }}"
        forecast_1: "{{ daily_forecast['weather.kofp'].forecast[1].detailed_description }}"

The template editor literally only takes Jinja code. Anything in any YAML is irrelevant.

Use the Action tool to run you action, then copy the response over to the Template tool for testing.

Thanks for that tip. It looks like it was all working correctly I just couldn’t tell.

The end result is I would like to be able to get a speaker to announce the forecast when triggered. I have the detailed forecast now stored as an attribute (forecast_0 and forecast_1) of sensor.nws_dailly_forecast.

How do I call that in a message from the action Text to speech?

I have the following and it does not seem to work. I am not sure how to call the attribute into the announcement.

target:
  entity_id: tts.piper
data:
  cache: true
  message: >-
    Tomorrow {{states('sensor.nws_daily_forecast.forecast_0')}}.  {{states('sensor.nws_daily_forecast.forecast_0')}}
    
  media_player_entity_id: media_player.office_clock
action: tts.speak

The function states() requires an entity ID string as an argument. You have provided… something else :smile:

Based on the sensor configuration in your previous post, you are trying to access a value store in the attributes property, so you should be using the state_attr() function. The first argument for that function should be the entity ID and the second should be the name of the attribute you want to retrieve:

{{ state_attr('sensor.nws_daily_forecast', 'forecast_0') }}

Templating Docs - State functions

thanks so much for the helpful link as well. Lots more reading to do!