Creating a sensor from secondary info: last-changed

hey all,

I was wondering: is there a way to create a “sensor” from the secondary info “last-changed”?

i know how to “show” it in lovelace, but i want that information to be sent out as notification to my phone.
there is an automation i would like to integrate it in, so when my phone is detected as “not home”, i will get the “last changed” info from an entity.

i figured that if i can make a “sensor” out of it - like with other attributes that an entity might have - it will be easy to send out, but i would except any other method, obviously

could anyone help out with that?

cheers :slight_smile:

You don’t need to create a sensor. Just use this template in your message:

  message: "Your message here {{ states.sensor.your_sensor_here.last_changed }} more message if needed"
1 Like

Tom, my man… when you r right, you’re soooooooo right…

i couldn’t figure out the syntax, but yours - magically works.

thanks man!

1 Like

You can use the relative time function if you want it in a more human readable format too:

{{ relative_time( states.sensor.your_sensor_here.last_changed ) }}

hey! that nice too!
but maybe a little to simplistic… anything in between?
maybe, just the “time” in a hh:mm:ss \ hh:mm presentation ?

Have a read of this and see how you go:

1 Like


never new it existed…

i’d still would need some syntax pointers…

like… where do i put the: “%H:%M” argue?
(sorry for my zero programing background)


1 Like
{{ as_timestamp( states.sensor.your_sensor_here.last_changed ) | timestamp_custom('%H:%M') }}
1 Like

i got the “| timestamp_custom(’%H:%M’) }}” part right, but the first part wrong…

all works now,

thank you guys

Is it possible to do this with a recommended style like this?

{{ state_attr('sensor.my_sensor', 'last_changed') }}

Unfortunately that gives just None in Templates DevTools section (while using {{ states.sensor.my_sensor.last_changed }} gives expected 2023-03-29 23:55:32.819148+00:00.

No. Last changed is a property not an attribute. See Petro’s excellent explanation here:

1 Like