Rewriting the sensor last_boot

Hi,

trying to rewrite all my yams files to the format of:

    message: >
      Update {{ states('updater.updater') }} for Home Assistant is available, 
      check {{state_attr('updater.updater','release_notes'}} for the latest changes.

Im stuck with the sensor.last_boot:

{{states.sensor.last_boot.last_changed}}
would be rewritten like:

{{states('sensor.last_boot').last_changed}} but that doesnt work, and the last_changed isnt an attribute so {{state_attr('sensor.last_boot','last_changed')}} doesn’t work either.

How should this be done?

thx,
Marius

Correct, last_changed is a direct attribute of a state object, it’s not in the state object’s attributes attribute. You can’t use the states() function, because that returns the state object’s state attribute. And you can’t use state_attr() because that returns something from the state object’s attributes attribute. The only way to get at last_changed (and last_updated) is to use states.domain.object_id.last_changed. See State Object.

1 Like

Thank you, lesson learned +1.

just for my reassurance/confirmation, can i write

{{states.sensor.xboxid.attributes["XboxOne Full"]}}

as

{{state_attr('sensor.xboxid',' '["XboxOne Full"]')}} ?

apostrophes are a bit awkward here?

Well, I don’t have any entities that have an attribute with a name that contains spaces as far as I know. But I would think that maybe you could write that this way:

{{state_attr('sensor.xboxid','XboxOne Full')}}

At least worth a try.

k.
thanks, i will. much nicer to look at :wink:
had the look: perfecto!

thanks , your maybe should be written as a definitely

40

or
03