I am looking to switch from Smartthings to openHAB. I have zero Java experience and the last few days I am trying to adapt irrigation rule to suit my needs. The problem is that the rule was written in OH2 and the time comparison are modified in OH3 which I have running.
I did read several forum topics on the subject and I have to admit that all this Java stuff looks very scary and unfriendly for somebody who is just doing the home automation for hobby.
I am trying to execute some simple comparison:
I have string item that has value in “HH:mm” format:
var DateTimeType userStartTime = parse(now.getYear() + "-" + now.getMonthValue() + "-" + now.getDayOfMonth() + "T" + itmIrrigationStartTime.state + ":00.000-01:00")
//Check the time hour by hour minute by minute, whether we are checking the set time. If the system is already watering, it does not check the conditions and does not water.
if ( ( ( userStartTime.getHour() == now.getHour() && userStartTime.getMinute() == now.getMinute() ) || checkUserStartTime == false )
&& itmIrrigationAuto.state == ON && (isWatering == false)
) {
The rule execution reports the following error:
2020-12-27 16:20:00.180 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'irrigation-8' failed: 'getHour' is not a member of 'org.openhab.core.library.types.DateTimeType'; line 455, column 30, length 23 in irrigation
How to get this working?
I tried conversions of the hour and minute from the itmIrrigationStartTime to integer that I found on the following link, but it also didn’t work for me
Thanks @spy0r, but it doesn’t work either. I don’t have problems with now.getHour(), that works (see logs below), but I have problem getting out the hour and minute from the user set time.
For testing I changed the code as follows and I still get error on “hour”.
Another option would be to extract the set hour and minute of the item itmIrrigationStartTime to integer, and then do the if comparison, but I couldn’t solve that also.
var DateTimeType userStartTime = parse(now.getYear() + "-" + now.getMonthValue() + "-" + now.getDayOfMonth() + "T" + itmIrrigationStartTime.state + ":00.000-01:00")
logInfo( "FILE", " ======= Wheather algorithm ======= ")
logInfo( "FILE", "Irrigation_Main_algorithm: now [" + now + "]")
logInfo( "FILE", "Irrigation_Main_algorithm: userStartTime [" + userStartTime + "]")
logInfo( "FILE", "Irrigation_Main_algorithm: checkUserStartTime [" + checkUserStartTime + "]")
logInfo( "FILE", "Irrigation_Main_algorithm: isWatering [" + isWatering + "]")
logInfo( "FILE", "Irrigation_Main_algorithm: itmIrrigationAuto.state [" + itmIrrigationAuto.state + "]")
//Check the time hour by hour minute by minute, whether we are checking the set time. If the system is already watering, it does not check the conditions and does not water.
logInfo( "FILE", "Irrigation_Main_algorithm: now.getHour()[" + now.getHour() + "]")
logInfo( "FILE", "Irrigation_Main_algorithm:: now.getMinute()[" + now.getMinute() + "]")
if ( ( ( userStartTime.hour == now.getHour() && userStartTime.minute == now.getMinute() ) || checkUserStartTime == false )
&& itmIrrigationAuto.state == ON && (isWatering == false)
How would the syntax look like in the above if check?
Basically what I am trying to do is to trigger execution bunch of commands at the time specified by the user in the item itmIrrigationStartTime?