Have been running openhab 1.8 for months now and have been able to resolve all issues, but today I’m stumped on a seemingly simple issue…
In my UI I display the last time my zwave front door sensor experienced a change in state. Based on a review of the sample rules, it seems the way to do this is as I show below - i.e. to get each component of the time and then concatenate them together. This works, but I have two issues:
- This seems rather convoluted - is there not a way to simply bring back the full time stamp?
- If the number of minutes or seconds is less than 10, the display is awkward, for example 16:3:21 instead of 16:03:21.
I’ve tried to enhance the code by using the length method to calculate the length of the string, such as second.length, but that syntax is not accepted.
Appreciate any help with finding a more elegant way to capture and display the time of an event and or to calculate the length of a string.
rule "Front Door Check"
when
Item ZWave_FrontDoor changed
then
var month = now.getMonthOfYear
var day = now.getDayOfMonth
var hour = now.getHourOfDay
var minute = now.getMinuteOfHour
var second = now.getSecondOfMinute
var CurrentTime = month+"/"+day+" @ "+hour+":"+minute+":"+second
postUpdate(strLastFrontDoorTime, CurrentTime)
end