[SOLVED] Comparing iCloud lastUpdate with now().minusHours(1) not working

Hi there,

i would like to compare the lastUpdate information from the iCloud binding to now().minusHours(1) to check if the binding is working and the current location is the actual location.
This checks helps me to use the iCloud location or the WiFi connection for presence detection.

I´m struggling to get oH to compare these to values.
As far as i currently understand i´m trying to compare to values that are looking the same but are probably not in the same format.

Item:

DateTime iPMichael_LastUpdate "Letztes Update [%1$td.%1$tm.%1$tY, %1$tH:%1$tM]" <lastupdate> (iPhones, gPersist) {channel="icloud:device:openHAB:iPMichael:locationLastUpdate"}

Rule to test:

rule "Test"
when
	Item itmTestSwitch changed
then
        val lastUpdate = iPMichael_LastUpdate.state
        val test = (lastUpdate.isBefore(now().minusHours(1)))
        logInfo("Test", "Test: " + test)
end

Whats leads to:

2019-09-15 12:01:02.007 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Test': 'isBefore' is not a member of 'org.eclipse.smarthome.core.types.State'; line 13, column 21, length 40

I had a look on this thread and the chapter DateTime Item.

So i tried to get the .state as a DateTimeType
val lastUpdate = (iPMichael_LastUpdate.state as DateTimeType)
only to get another error

2019-09-15 12:08:25.796 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Test': 'isBefore' is not a member of 'org.eclipse.smarthome.core.library.types.DateTimeType'; line 13, column 21, length 40

What am i missing to succesfull compare these values?

kind regards
Michael


  • Platform information:
    • Hardware: Raspberry Pi 4 Model B Rev 1.1 - 4GB
    • OS: Raspbian GNU/Linux 10 (buster) (latest raspbian image)
    • Java Runtime Environment:
      • openjdk version “1.8.0_222”
      • OpenJDK Runtime Environment (Zulu8.40.0.178-CA-linux_aarch32hf) (build 1.8.0_222-b178)
      • OpenJDK Client VM (Zulu8.40.0.178-CA-linux_aarch32hf) (build 25.222-b178, mixed mode, Evaluation)
    • openHAB version: 2.4.0-1

See:

1 Like

Thanks :+1:
That leaded me to the correct way of using the .state and now().minusHours(1)
I used the solution from this thread.
To verify the other method i also tried to use the compare with .calendar.timeInMillis and it´s not working.

Rule 1 (working):

rule "Test"
when
	Item itmTestSwitch changed
then
        val lastUpdate = new DateTime(iPMichael_LastUpdate.state.toString)
        val timeCheck = new DateTime(now().minusHours(1).toString)
        val test = (lastUpdate.isBefore(timeCheck))
        logInfo("Test", "Test: " + test)
end

Rule 2 (not working):

rule "Test"
when
	Item itmTestSwitch changed
then
        val lastUpdate = new DateTime((iPMichael_LastUpdate.state as DateTimeType).calender.timeInMillis)
        val timeCheck = new DateTime((now().minusHours(1) as DateTimeType).calender.timeInMillis)
        val test = (lastUpdate.isBefore(timeCheck))
        logInfo("Test", "Test: " + test)
end

Error:

2019-09-15 12:41:04.868 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Test': 'calender' is not a member of 'org.eclipse.smarthome.core.library.types.DateTimeType'; line 9, column 39, length 53