Newbi help. How to read a state attribute

I seams simple but I struggle. In the template playground I can read
{{states.sensor.daylight}}
and it returns
<template TemplateState(<state sensor.daylight=16.606; yesterday=16.58412953138889, today=16.605679001111113, tomorrow=16.625686868333332, yesterday_hms=16:35:02, today_hms=16:36:20, tomorrow_hms=16:37:32, unit_of_measurement=hr, friendly_name=Daylight, icon=mdi:weather-sunny @ 2021-06-08T20:40:34.714211+02:00>)>
fine
with {{states.sensor.daylight.state}} I get the state. But what expression would give me e. g. tomorrow? {{states.sensor.daylight.tomorrow}} fails.


{{ states.sensor.daylight.attributes.tomorrow }}

# or

{{ state_attr('sensor.daylight', 'tomorrow') }}

1 Like

Great, thanks, couldn’t find this in the docs.

FYI You should use the second version to prevent errors.

Perhaps you missed the all-important Templating chapter where it explains:

state_attr('device_tracker.paulus', 'battery') will return the value of the attribute or None if it doesn’t exist.

It also contains the following advice: