now.getHourOfDay() -- nothing

I’ve been loving OpenHAB for the past year or so, but tonight, I want to gouge my eyes out. It seems like I’ve been working on a simple problem for entirely too long (at least 3 hrs now)! I’ve been reading the forums and the Rules documentation, and I just can’t figure out why this doesn’t work. It’s some type of conversion issue I’m sure. Maybe my mind is just “gone” for the night.

I guess another important point is that I know that the logs are showing 23:37, but regardless of the time, the logic doesn’t work. It seems like the value of now.getHourOfDay is just an empty string?

I’d love a little help!!!

  • Platform information:
    • Hardware: x64, 16GB RAM
    • OS: Linux version 5.4.0-59-generic (buildd@lcy01-amd64-028) (gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04)) #65-Ubuntu SMP Thu Dec 10 12:01:51 UTC 2020
    • Java Runtime Environment: zulu-8/stable,now amd64 [installed,automatic]
    • openHAB version: 2.5.11
  • Issue of the topic: getHourOfDay() returns empty string?
    I have a young son that turns his dimmer lights on full (100) at night, and then can’t fall back asleep. The intent of this rule is to only allow him to turn his lights to (21) before 7am and after 8p
  • Please post configurations (if applicable):
    • Rules code related to the issue
var Timer F1_GuestRoom_Light_Timer = null

rule "Light at Night"

when Item F1_GuestRoom_Light changed
  logInfo("Light", "GuestRoom_Light changed at ", now.getHourOfDay() )
  if( now.getHourOfDay() > 7 && now.getHourOfDay() < 20) return;  
  if( F1_GuestRoom_Light .state > 22) {
    logInfo("Light", "GuestRoom_Light changed to {}.", F1_GuestRoom_Light .state)
    sendCommand( F1_GuestRoom_Light, 21)
    if( F1_GuestRoom_Light_Timer === null ) {
        logInfo("Light", "GuestRoom_Light created Timer")
        F1_GuestRoom_Light_Timer = createTimer(now.plusMinutes(5), [ | 
            sendCommand( F1_GuestRoom_Light,0)
            F1_GuestRoom_Light_Timer = null ])
        logInfo("Light", "GuestRoom_Light rescheduled Timer")
  • If logs where generated please post these here using code fences:
2021-01-08 23:37:33.376 [INFO ] [eclipse.smarthome.model.script.Light] - GuestRoom_Light changed to 38.
2021-01-08 23:37:33.377 [INFO ] [eclipse.smarthome.model.script.Light] - GuestRoom_Light created Timer
2021-01-08 23:37:33.383 [INFO ] [eclipse.smarthome.model.script.Light] - GuestRoom_Light changed at 
2021-01-08 23:37:33.888 [INFO ] [eclipse.smarthome.model.script.Light] - GuestRoom_Light changed at 
2021-01-08 23:37:33.889 [INFO ] [eclipse.smarthome.model.script.Light] - GuestRoom_Light changed to 84.
2021-01-08 23:37:33.890 [INFO ] [eclipse.smarthome.model.script.Light] - GuestRoom_Light rescheduled Timer
2021-01-08 23:37:33.894 [INFO ] [eclipse.smarthome.model.script.Light] - GuestRoom_Light changed at 
2021-01-08 23:37:34.662 [INFO ] [eclipse.smarthome.model.script.Light] - GuestRoom_Light changed at 
2021-01-08 23:37:34.663 [INFO ] [eclipse.smarthome.model.script.Light] - GuestRoom_Light changed to 60.
2021-01-08 23:37:34.664 [INFO ] [eclipse.smarthome.model.script.Light] - GuestRoom_Light rescheduled Timer
2021-01-08 23:37:34.668 [INFO ] [eclipse.smarthome.model.script.Light] - GuestRoom_Light changed at 


While in

you have {} to replace the braces with the variable content in

you don’t have the braces.
Adding braces and if required conversion to a string should add the value.

Thank you! I should have written to the forum after an hour. Syntax errors, always the most painful!