Get TimeStamp with SendMail()

I’ve setup a basic alert to receive an email whenever my garage door is opened. However, I do not understand the proper format or syntax to correctly show the date and time

This is Date Item

DateTime Date “Date & Time [%1$tm/%1$td/%1$tY %1$tT]” { ntp=“America/Detroit:en_EN” }

And my rule looks like this:

rule “Garage Door Email”

when
Item sGarageDoorStatus changed
then
if (sGarageDoorStatus.state==OPEN) {
sendMail(“xxxx@xxx.com; xxx@xxx.com”, “Garage Door Opened”, "The Garage Door was opened at " + Date)
}
end

But the email shows up like this:

The Garage Door was opened at Date (Type=DateTimeItem, State=2016-01-14T11:08:44)

How do I get that to just say

The Garage Door was opened at 11:08:44 on 01/14/2016?

I assume separate Time and Date Items. But how do include that in a Rule with SendMail()?

You’ll need to do something like:

sendMail("xxxx@xxx.com; xxx@xxx.com", "Garage Door Opened", "The Garage Door was opened at " + Date.state.format("%tH:%tM:%tS") + " on " + Date.state.format("%tm/%td/%tY"))
1 Like

Hey Daniel

Wanted to say thanks, but can you confirm that works on your end? When I change to that code, the email no longer comes through yet the OpenHab Designer does not report any syntax issues.

Apologies, was at work when I posted so couldn’t test it then.

This should work for you, I’ve tested that the string format and concatenation works (I don’t use the mail action to test that part) and the output was “The Garage Door was opened at 00:31 on 01/15/16”

sendMail("xxxx@xxx.com; xxx@xxx.com", "The Garage Door was opened at " + CurrentDate.state.format("%tR") + " on " + CurrentDate.state.format("%tD"))

Thanks Dan. That worked well.

Now I just wish there was a binding to send a SMS text to my phone telling me the garage was opened instead of using email for an alert.

But now I can continue to modify and get email alerts when other actions happen and start learning how to snap a webcam pic and attach it to the email.

@ptmuldoon my.openHAB offers an SMS service. This link has some information.

FYI - I know that if I use my phone to send a text and use my email address as the recipient I can then see that my phone text service actually has an email address. Its 555-555-1212@mms.att.net. That way I can use an email service to send a text.

Now if I can just figure out how to get openhab sending emails…thats for a new post