1 of 2 template sensors aren't working and I'm at a loss for a solution

Please help. I’ve been trying to find a solution for 5 days. I’ve tried a thousand different things. I went back to my first attempt and ask someone to please point me in the right direction.

The first sensor (sensor.nws_daily_forecasts) works perfectly. The second sensor (sensor.current_forecast) just needs its state value to equal the value of the first sensor’s first attribute (forecast_0).

Here is the template sensor:

template:
  - trigger:
      - platform: time_pattern
        minutes: "/15"
    action:
      - service: nws.get_forecasts_extra
        data:
          type: twice_daily
        target:
          entity_id: weather.klqk_daynight
        response_variable: daily_forecast
    sensor:
      - name: "NWS Daily Forecasts" 
        unique_id: nws_daily_forecasts 
        state: "{{ now() }}"
        attributes:
          forecast_0: "{{ daily_forecast.forecast[0].detailed_description }}"
          forecast_1: "{{ daily_forecast.forecast[1].detailed_description }}"
          forecast_2: "{{ daily_forecast.forecast[2].detailed_description }}"
          forecast_3: "{{ daily_forecast.forecast[3].detailed_description }}"

      - name: "Current Forecast"
        unique_id: current_forecast
        state: "{{ daily_forecast.forecast[0].detailed_description }}"

No matter what I have tried, I always get ‘unknown’ on the second sensor.

Thanks…

What data does the detailed_description field contain? My local weather service does not provide that. A state is always a string and its max length is 255 characters. Most likely you are trying to forcefeed data which won’t automatically cast to a string or the string is too long.

1 Like

You could try:

      - name: "Current Forecast"
        unique_id: current_forecast
        state: "{{ daily_forecast.forecast[0].detailed_description | truncate }}"

If what @TheFes says doesn’t work, I’d be willing to bet you added unique_id at a later time and you’re looking at the wrong entity. Verify you don’t have sensor.current_forecast and sensor.current_forecast_2