Template sensor of sub entity is shown as unknown

I created a template sensor. All sub entities (temperature, temperature_unit, etc) would result in correct value except the one for “forecast”, which result in unknown. In the templating sheet it does work.

Could the problem be the value starting in the next line?

This is the template sensor and the value of the sensor for templating

- sensor:
    - name: frankfurr_forecast
      state: >-  
        "{{state_attr('weather.frankfurt_hourly','forecast')}}" 
      
      
-------


temperature: 12.4
temperature_unit: °C
pressure: 1013.6
pressure_unit: hPa
wind_bearing: 109
wind_speed: 19
wind_speed_unit: km/h
visibility_unit: km
precipitation_unit: mm
forecast:
  - datetime: '2023-04-28T10:00:00+00:00'
    custom_dwd_ww: 3
    condition: cloudy
    cloud_cover: 83
    precipitation_probability: 9
    wind_bearing: 109
    temperature: 12.4
    pressure: 1013.6
    wind_speed: 19
    precipitation: 0
  - datetime: '2023-04-28T11:00:00+00:00'
    custom_dwd_ww: 3
    condition: cloudy
    cloud_cover: 86
    precipitation_probability: 8
    wind_bearing: 110
    temperature: 12.9
    pressure: 1013.1
    wind_speed: 17
    precipitation: 0
  - datetime: '2023-04-28T12:00:00+00:00'
    custom_dwd_ww: 3
    condition: cloudy
    cloud_cover: 88
    precipitation_probability: 15
    wind_bearing: 111
    temperature: 13.1
    pressure: 1012.8
    wind_speed: 17
    precipitation: 0

You’re using multiline notation and single line notation at the same time, this will result in a set of quotes being inside your state.

Use one or the other, not both.

as a single line

- sensor:
    - name: frankfurr_forecast
      state: "{{state_attr('weather.frankfurt_hourly','forecast')}}" 

as a multiline

- sensor:
    - name: frankfurr_forecast
      state: >
        {{state_attr('weather.frankfurt_hourly','forecast')}}

this is a bare example of single line notation in yaml

single_line_value: "..."
multiline_value: >
  ...

Notice single line value has quotes but the multiline version does not.

Be advised that the total length of any entity’s state value is limited to 255 characters. Your Template Sensor’s attempt to display the entire value of the forecast attribute is likely to exceed the limit and the value will be automatically truncated (thereby rendering it incomplete).

1 Like

Okay, but even without quotes the value is unknown. I get a value in the template section of developer tools. Could you imagine why?

Perhaps there is an easier way to solve the issue I am facing. I would like to display the values of “forecast” in this https://community.home-assistant.io/t/flex-table-card/461173.

How would you do it?

Thanks in advance.

You’re hitting the states character limit like 123 said