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
tom_l
June 8, 2021, 2:14pm
2
You don’t need to create a sensor. Just use this template in your message:
data:
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
tom_l
June 8, 2021, 3:45pm
4
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 ) }}
3 Likes
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 ?
tom_l
June 8, 2021, 4:23pm
6
Have a read of this and see how you go:
NOTE: I’ve tried to make all of these posts able to be copied as is into the template editor and work.
Due to some of the examples I’ve included you will get errors when you copy this post until you make corrections and use your correct entities in those examples.
I’ll annotate those sections that need to be modified in bold and with a “@@”.
–
The Unix Epoch (or Unix time or POSIX time or Unix timestamp) is the number of seconds that have elapsed since January 1 00:00:00
as_timestamp() - co…
1 Like
nnnooooooooiiiiiceeeee!
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
finity
June 8, 2021, 10:05pm
8
{{ 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
.
tom_l
March 31, 2023, 12:04am
11
No. Last changed is a property not an attribute. See Petro’s excellent explanation here:
Ok, so this is where things get funky. You should familiarize yourself with home assistant state objects. This is what home assistant passes around when doing pretty much anything. These state objects contain 8 or so properties. Do not get these properties confused with the devices attributes.
These properties are:
Field
Description
state.state
String representation of the current state of the entity. Example off.
state.entity_id
Entity ID. Format: .<object_id>. Example: light.…
1 Like