Trying to get correct day displayed


#1

1) Give a description of the problem
I have a piston that tells me the time of a Bulb was turned on or off.
2) What is the expected behavior?
I need help with the expression. I’d like to display not only the time, but aslo the date (or day). Right now I have $dayofweek, but I know that’s not right.

3) What is happening/not happening?
I’m getting the correct time displayed but not the correct date.


#2

Try…

formatDateTime($now,'E h:mm a')

Reference: https://docs.oracle.com/javase/tutorial/i18n/format/simpleDateFormat.html


#3

i still can’t get this work. I’ve tried your suggestion, but I’m pulling my hair out. Here is my piston if you could please take a look at it. I’m trying to get not only the time displayed when the temp. changed, but also the day it changed.

05 PM


#4

I’ll give it a shot :slight_smile:


#5

Thanks, I appreciate it…I’m taking a break for tonight. Later.


#6

contS + "🔵 "$device" is ["closeC"|"[$device:temperature]"] "formatDateTime(time($now - age([$device:temperature])), 'E hh:m a')",\n"


#7

Alright, It’s all good now!! Thank you very much!!


#8

Eibyer,

No dice this morning. It is showing the correct time of when the contact opened or closed, for each device. But some but for some reason it’s putting in the current day. Not the day of the contact changing. I’m tagging the rest of the @webCoRE_Minions because I really want this to work. Been trying for three days. Thanks guys.

Any ideas?


#9

The time() function only returns the time. Looks like formatDateTime is filling in the missing day, so try:

 formatDateTime($now-age([$device:contact]), 'E h:mm a')

i.e., remove the time() function.

If you want the full-blown date (e.g., Thu, Nov 16 2017 @ 8:44:07 PM PST) use:

datetime($now-age([$device:contact]))

#10

It’s working. For sure now. Thanks a lot guys for your help


#11

Be aware that age() works off events. Events are only kept for 7 days, so if a device has NO events in the last 7 days, age() may return … 0? You get it, it won’t work on those devices.