#NFC Tag Automation add date and time

1 messages ยท Page 1 of 1 (latest)

faint summit
#

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

distant bough
#

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

faint summit
#

yes i see this but how do i know what specific state. to put for last changed

distant bough
#

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

faint summit
#

in that example i shared they pulled states.cover.garage_door.last_changed

#

oh is that because they are watching for that specific state

distant bough
#

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

#

so something like {{ states('states.tag.testtag') }} will display it

faint summit
#

ahhh ok so im not looking for specific value as only values it can give is last scanned time

distant bough
#

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

faint summit
#

ok its said unknown when i ran it just now

distant bough
#

has the tag been scanned?

#

its default value is unkown until its been scanned

faint summit
#

ill physical scan it but it has a time im dev tools

#

it still said unknown

distant bough
#

you said it shows a date in the dev tools? but it says unknown when you try to access it from somewhere?

faint summit
#

the notification send shows unknown

distant bough
#

can you paste the yaml your using to write the notification?

faint summit
#

i have - Dog has been fed @ {{ states('states.tag.dog_fed') }}

distant bough
#

change to {{ states('tag.dog_fed') }}

#

you dont need the extra states in there

#

sorry my example above had a mistake

#

mistyped

faint summit
#

still says unknown just running action would it pull last date that is published on device in dev tools

#

or requires a physical scan

distant bough
#

just hitting action should work i think as it uses the most recent data

faint summit
#

hmmmm

distant bough
#

on dev tools go to the template tab and put the {{ states('tag.dog_fed') }} in there and see how it evalueates

faint summit
#

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?

distant bough
#

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

faint summit
#

saying malformed

distant bough
#

try it in the template section on dev tools

#

see if that gives any more info

faint summit
#

unexpected )

distant bough
#

thats odd

#

there's the right amount of paracentesis from what ii can tell

#

make sure theres nothing else in the tamplate editor

faint summit
#

i cleared it

#

same thing

distant bough
#

can you screenshot it? its not that i dont beleive you but i just cant see why it would be compalaining about a unexpected )

faint summit
distant bough
#

your missing a opening ( at the front

#

before states

faint summit
#

damn

distant bough
#

its unexpected close because of missing open

faint summit
#

always that one ( missing ha

distant bough
#

does it work as expected?

faint summit
#

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

distant bough
#

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 ๐Ÿ˜›

faint summit
#

perfect it works

distant bough
#

great!

faint summit
#

i was wondering how you knew what to put in there

distant bough
#

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 ๐Ÿ™‚

faint summit
#

yeah im good now

#

thanks for all the help

faint summit
#

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

distant bough
faint summit
#

ahh yes it is showing previous time

distant bough
#

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

faint summit
#

how do you give a time delay in notifications

distant bough
#

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()

faint summit
#

the delay worked perfect

#

thank you

distant bough
#

ah awesome. yeah it must jsut need a moment to actually update with the new data

faint summit
#

yep i was thinking i had time zone wrong doing all this unnecessary checking ha

distant bough
#

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 ๐Ÿ˜›

faint summit
#

My wife is loving this btw and this is such a game changer ha