Add date and time to msg notification how do I know the state to look for https://community.home-assistant.io/t/how-to-add-time-to-notification/469668 - I just want to add date and time to when it was scanned.
#NFC Tag Automation add date and time
1 messages ยท Page 1 of 1 (latest)
This shows its looking for state last changed on garage door. I don't know how to find the reference for this in HA for an NFC tag
the state of the tag entity shows its last scanned time as a datetime
the entity name would be
tag.TAGNAME to search for it if you look in the dev tools on the "states" tab you will be able to search for it and see it
yes i see this but how do i know what specific state. to put for last changed
you dont need .last_changed or anything
the main state is the last scanned datetime
you can see on the aboce that its "unknown" for that one as its never been scanned
in that example i shared they pulled states.cover.garage_door.last_changed
oh is that because they are watching for that specific state
in that case "garage door" has an attribute for "last changed"
the state for garge door will be open/closed or something
but the state for a tag is its last scanned datetime
documentation here - https://www.home-assistant.io/integrations/tag/
so something like {{ states('states.tag.testtag') }} will display it
ahhh ok so im not looking for specific value as only values it can give is last scanned time
yeah its base value is its last scanned so you dont need to specify that
it does have some attributes for its ID and what device it was last scanned at and stuff but for your current question they dont need to be called
ok its said unknown when i ran it just now
you said it shows a date in the dev tools? but it says unknown when you try to access it from somewhere?
the notification send shows unknown
can you paste the yaml your using to write the notification?
i have - Dog has been fed @ {{ states('states.tag.dog_fed') }}
change to {{ states('tag.dog_fed') }}
you dont need the extra states in there
sorry my example above had a mistake
mistyped
still says unknown just running action would it pull last date that is published on device in dev tools
or requires a physical scan
just hitting action should work i think as it uses the most recent data
hmmmm
on dev tools go to the template tab and put the {{ states('tag.dog_fed') }} in there and see how it evalueates
it shows date
not in my time zone of course but its there
wonder if @ is messing it up
it was at sign ha
it works now. how do I make it more readable and correct time zone?
thats interesting and good to know i guess. i havent used an @ sign in notifications before i dont think
can try something like this
{{ (states('tag.dog_fed')|as_datetime).astimezone() }}
i think that converts to locally set TZ
saying malformed
unexpected )
thats odd
there's the right amount of paracentesis from what ii can tell
make sure theres nothing else in the tamplate editor
can you screenshot it? its not that i dont beleive you but i just cant see why it would be compalaining about a unexpected )
damn
its unexpected close because of missing open
always that one ( missing ha
does it work as expected?
yes but puts everything down to the milliseconds i think
how to just get hour and minutes
and move it to mm-dd hh:mm
moment
{{ (as_datetime( states('tag.dog_fed') ).astimezone()).strftime('%m-%d %H:%M') }}
try that
or {{ ((states('tag.dog_fed')|as_datetime).astimezone()).strftime('%m-%d %H:%M') }}
depending on how you like it formatted ๐
the strftime bit can be adjusted a bit to display whichever time data you like. theres some documentation on the notation here - https://www.programiz.com/python-programming/datetime/strftime
perfect it works
great!
i was wondering how you knew what to put in there
yeah, one of those things you have to look up sometimes. although trial and error gets you the basics most of the time if you want simple stuff
anyway i gotta run. good luck with your next one. hopefully you can get there yourself now ๐
Hey i just noticed that the time of day is incorrect. I checked state of tag and it shows 14:21:49.303+00:00 i checked my time zone is set properly in config yaml. I ran the template test and results show correct but notification actually showed 20:04 from mobile app.
Should have been 10:21 am
does it change if you scan again?
is it showing the previous scan data?
ahh yes it is showing previous time
i am not sure on the timeline of how the stuff updates. you could try adding a small delay and see if that gives it time to update
how do you give a time delay in notifications
you can add a delay into the automation
do it just above the "send notificaiton action"
also another option if your notification is only ever going to send the time that it is when sending the notification you could use the current datetime instead of the one from the tag. so you would replace states(tag.dog_fed) with now()
ah awesome. yeah it must jsut need a moment to actually update with the new data
yep i was thinking i had time zone wrong doing all this unnecessary checking ha
yeah i thought that might be a thing at first but the give away was the the minutes was different
there are a few timezones that are not a complete hour different but to my knowledge none of them are 17 minutes off ๐
My wife is loving this btw and this is such a game changer ha