pluemmi
(Wolfgang)
June 4, 2019, 7:39am
1
Hi all,
I am using the Astro Binding and I have defined the following thing and item:
astro:sun:home [ geolocation="00.000,00.000,100", interval=60 ]
DateTime Daylight_Start "Daylight [%1$tH:%1$tM]" { channel="astro:sun:home:daylight#start" }
The console shows the value of Daylight_Start in this format:
2019-06-04T05:24:00.000+0200
I have copied the following from the Astro Wiki:
if(now.isAfter((Daylight_Start.state as DateTimeType).zonedDateTime.timeInMillis))
But when the rule is triggered I get the error message:
“timeInMillis’ is not a member of 'java.time.ZonedDateTime”
The imports
import java.util.Calendar
import java.time.ZonedDateTime
import java.text.SimpleDateFormat
import java.util.Date
are apparently of no use:
“The import ‘java.util.Calendar’ is never used.
The import ‘java.util.Date’ is never used.
The import ‘java.time.ZonedDateTime’ is never used.
The import ‘java.text.SimpleDateFormat’ is never used.”
What’s wrong here?
rossko57
(Rossko57)
June 4, 2019, 8:40am
2
Try toEpochMillis
, no imports needed
With OpenHAB 2.2.0, the statement:
val long day_start = (vSunrise_Time.state as DateTimeType).calendar.timeInMillis
now gives a warning:
The method getCalendar() from the type DateTimeType is deprecated
Use this instead:
val long day_start = (vSunrise_Time.state as DateTimeType).zonedDateTime.toInstant.toEpochMilli
pluemmi
(Wolfgang)
June 4, 2019, 9:38am
3
if(now.isAfter((Daylight_Start.state as DateTimeType).zonedDateTime.toInstant.toEpochMilli))
is doing the job.
Thank you.
rossko57
(Rossko57)
June 4, 2019, 10:21am
4
I missed that part … old docs. See
Here is a thread which has several good resources for time comparison
This is a simple rule example for folks like me, who are new to openHAB, and need simple examples of rules to get started. In this example, two times are compared, enabling us to make a decision based on if one event occurred before another.
In the example, a contact switch on an entry door triggers a time stamp. A motion detector also triggers a time stamp. The two times can be compared to see if the occupant (andy) is home (motion since door was opened) or left (no motion since door was opene…