Now.gethour > 7


I have read, that now.gethour > xx might not be working in OH3. However, I am still looking for an alternative.

until OH 2 I had:

if ((now.getHourofDay >= 7 )) && (now.isAfter(new DateTime(Min_Rolladen_Open_Zeit.state.toString) ))) {

now I tried:
if ((now.isAfter( && (now.isAfter(new DateTime(Min_Rolladen_Open_Zeit.state.toString) ))) {

The error is still:
Script execution of rule with UID 'sonne-9' failed: An error occurred during the script execution: null in sonne


Hi Daniel,

I have been struggling with these time comparisons also enormously after the migrating to OH3.

I think yo can use:

if (now.isAfter(now.withHour(7).withMinute(0).withSecond(0)) &&
   now.isAfter((Min_Rolladen_Open_Zeit.state as DateTimeType).getZonedDateTime()))

Hope this helps.


1 Like

Thanks, really not so intuitive…:wink:

First, there are missing brackets in the first place. :wink:
Second, the OH2 method is .getHourOfDay and every letter is case sensitive. Though you sure did use the correct spelling, it’s crucial use it also here.

Third, I’m pretty sure you can easily use instead. For complete documentation, see ZonedDateTime (Java Platform SE 8 )

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.