Rule based on CronJob does not execute (OH3.2, Synology DSM > 7.0, Docker)

  • Platform information:
    • Hardware: Synology DS918+
    • OS: DSM 7.0.1-42218 Update 3
    • Java Runtime Environment: Contained in OH 3.2 docker image, no idea what that is
    • openHAB version:3.2
  • Issue of the topic:
    I am trying to switch on the coffee machine each weekday at 06:00 am.

What I already achieved:
I can switch on the coffee machine using the OH web interface

What does not work?
None of my time based rules get executed. But the rules engine seems to be up and running because the following script does work. It switches the subwoofer to ON when the receiver powers on.

Example of rule which works:

configuration: {}
  - id: "1"
      itemName: DenonAVRX2200WAVRX2200W_Power
      state: ON
    type: core.ItemStateChangeTrigger
conditions: []
  - inputs: {}
    id: "2"
      command: ON
      itemName: Subwoofer_Betrieb
    type: core.ItemCommandAction

Now the script which does not work:

configuration: {}
  - id: "1"
      cronExpression: 0 0 6 * * ? *
    type: timer.GenericCronTrigger
conditions: []
  - inputs: {}
    id: "2"
      command: ON
      itemName: Kaffeemaschine_Betrieb
    type: core.ItemCommandAction

Please note that I didn’t write the script but clicked it with the help of the “Design” tab.

My assumption is that for some reason no time events are sent to OH. the reason for that could be that my OH3.2 must run inside of a docker container (as Java 11 is not supported on DSM>7). I followed the instructions here: Synology DiskStation | openHAB. Now I am not an expert but could it be that the cron job is part of the OS. When OH runs inside the docker container perhaps the events of the surrounding OS with its cron service does not “reach” into the container?

Do you have any idea how to check whether any cron events reach OH? Some kind of hello world example to test whether timer events reach OH.
Or do you have any idea of how to resolve this issue?

  • If logs where generated please post these here using code fences:
    Here are the logs from the docker container where OH resides
    |022-05-12 06:05:21|stdout|e[?1he=e[90m~e[0m e[?2004he[36mopenhab>e[0m |
    |2022-05-11 20:49:34|stdout||
    |2022-05-11 20:49:34|stdout|To exit, use ‘e[1me[0m’ or ‘e[1mlogoute[0m’.|
    |2022-05-11 20:49:34|stdout|and ‘e[1m[cmd] --helpe[0m’ for help on a specific command.|
    |2022-05-11 20:49:34|stdout|Use ‘e[1me[0m’ for a list of available commands|
    |2022-05-11 20:49:34|stdout||
    |2022-05-11 20:49:34|stdout|e[91m || e[0m 3.2.0 - Release Builde[0m|
    |2022-05-11 20:49:34|stdout|e[91m ___/| / _/|
    | ||e[97m|| ||// _|/ e[0m|
    |2022-05-11 20:49:34|stdout|e[91m | (
    ) | (
    ) | __/| | | |e[97m| _ | / ___ \ | |
    ) )e[0m|
    |2022-05-11 20:49:34|stdout|e[91m / _ \ / _ \ / _ \ / _ \ e[97m| |
    | | / _ \ | _ \ e[0m|
    |2022-05-11 20:49:34|stdout|e[91m ___ ___ ___ ___ e[97m| | | | / \ | __ ) e[0m|
    |2022-05-11 20:49:34|stdout|e[91m e[97m _ _ _ ____ e[0m|
    |2022-05-11 20:49:34|stdout||
    |2022-05-11 20:49:15|stdout|Launching the openHAB runtime…|
    |2022-05-11 20:49:15|stdout|+ exec gosu openhab tini -s ./|
    |2022-05-11 20:49:15|stdout|+ ‘[’ true == false ‘]’|
    |2022-05-11 20:49:14|stdout|+ sync|
    |2022-05-11 20:49:14|stdout|+ ‘[’ -d /etc/cont-init.d ‘]’|
    |2022-05-11 20:49:13|stdout|+ sync|
    |2022-05-11 20:49:12|stdout|+ chown -R openhab:openhab /openhab|
    |2022-05-11 20:49:12|stdout|+ ‘[’ ‘!’ -z ‘]’|
    |2022-05-11 20:49:12|stdout|++ cmp /openhab/userdata/etc/ /openhab/dist/userdata/etc/|
    |2022-05-11 20:49:12|stdout|tmp’ ‘]’|
    |2022-05-11 20:49:12|stdout|secrets|
    |2022-05-11 20:49:12|stdout|persistence|
    |2022-05-11 20:49:12|stdout|logs|
    |2022-05-11 20:49:12|stdout|kar|
    |2022-05-11 20:49:12|stdout|jsondb|
    |2022-05-11 20:49:12|stdout|etc|
    |2022-05-11 20:49:12|stdout|config|
    |2022-05-11 20:49:12|stdout|+ ‘[’ -z ‘cache|
    |2022-05-11 20:49:12|stdout|++ ls -A /openhab/userdata|
    |2022-05-11 20:49:12|stdout|+ source=/openhab/dist/userdata|
    |2022-05-11 20:49:12|stdout|+ volume=/openhab/userdata|
    |2022-05-11 20:49:12|stdout|+ initialize_volume /openhab/userdata /openhab/dist/userdata|
    |2022-05-11 20:49:12|stdout|transform’ ‘]’|
    |2022-05-11 20:49:12|stdout|things|
    |2022-05-11 20:49:12|stdout|sounds|
    |2022-05-11 20:49:12|stdout|sitemaps|
    |2022-05-11 20:49:12|stdout|services|
    |2022-05-11 20:49:12|stdout|scripts|
    |2022-05-11 20:49:12|stdout|rules|
    |2022-05-11 20:49:12|stdout|persistence|
    |2022-05-11 20:49:12|stdout|items|
    |2022-05-11 20:49:12|stdout|icons|
    |2022-05-11 20:49:12|stdout|html|
    |2022-05-11 20:49:12|stdout|+ ‘[’ -z ‘automation|
    |2022-05-11 20:49:12|stdout|++ ls -A /openhab/conf|
    |2022-05-11 20:49:12|stdout|+ source=/openhab/dist/conf|
    |2022-05-11 20:49:12|stdout|+ volume=/openhab/conf|
    |2022-05-11 20:49:12|stdout|+ initialize_volume /openhab/conf /openhab/dist/conf|
    |2022-05-11 20:49:12|stdout|+ id -u openhab|
    |2022-05-11 20:49:12|stdout|Starting with openhab user id: 1028 and group id: 65536|
    |2022-05-11 20:49:12|stdout|+ echo ‘Starting with openhab user id: 1028 and group id: 65536’|
    |2022-05-11 20:49:12|stdout|+ NEW_GROUP_ID=65536|
    |2022-05-11 20:49:12|stdout|+ NEW_USER_ID=1028|
    |2022-05-11 20:49:12|stdout|+ rm -f /openhab/userdata/tmp/instances/|
    |2022-05-11 20:49:12|stdout|+ rm -f /openhab/runtime/instances/|
    |2022-05-11 20:49:12|stdout|+ ‘[’ limited = unlimited ‘]’|
    |2022-05-11 20:49:12|stdout|’|
    |2022-05-11 20:49:12|stdout|+ IFS=’|
    |2022-05-11 20:45:22|stdout|e[?1le>e[?1000le[?2004l|
    |2022-05-11 20:45:20|stdout|e[?1he=e[90m~e[0m e[?2004he[36mopenhab>e[0m |

I have a similar setup (OH3.2 in Docker on DSM7 and similar rules work well for me. The rules above seem correct to me, but I use .rules files not the UI rules so I’m not familiar with the syntax. Have you verified that the time in OpenHab is correct?

This works in a .rules file:

rule SetOfficeLightOn
when Time cron "0 0 7 ? * MON-FRI *" 
then sendCommand( OfficeLight,70)
     logInfo("SetOfficeLightOn", "OfficeLight set to {}", OfficeLight.state.toString)

Have you set the timezone? Look at your logs, do the timestamps make sense?

The cron jobs are actually scheduled and managed internal to openHAB and do not use the OS cron service. So my guess would be your OH instance thinks it’s in some other timezone so the rules might be firing many hours from when you think you’ve scheduled it.

To be exact, the schedule runs on the Java timezone. It is possible to set up openHAB in a different timezone to Java and wonder why cron is cranky. The giveaway is the timestamping in your openhab.log and events.log, which also use Java time.

How can I check the logs (ok that is a newbie question) but I don’t know it.

How do I set the timezone?

$OH_USERDATA/logs where $OH_USERDATA is the folder you’ve mounted as a volume into the container to /openhab/userdata.

Ok I found it thank you

And I opened the terminal window entered “date” and thus found out that inside the container the clock shows 2 hours less than the current date. So it’s about setting the timezone. Where do i set this: On the container, on the script,?

Thanks for your super fast response this helped me a lot!

On a Synology I’ve no idea. ON “normal” machines I mount /etc/localtime and /etc/timezone from the host into the container. That will make the OH inside the container see the same timezone config as is on the host. I’ve never had to do anything special to get the JVM to use the right timezone so I’m not sure what that entails.

But I don’t know if those two files even exist on Synology or if they do something custom.

To set the time zone add your timezone to the EXTRA_JAVA_OPTS parameter in the environments section of the Docker config. For me it is -Duser.timezone=America/Chicago

1 Like

Thank you very much! This helped. (I stopped and edited the environment then restarted the container for this. Don’t know if that was necessary, just in case someone has a similar problem)

thanks a lot for your super fast replies. I assume this is also a solution although I don’t know how to mount this to my docker :slight_smile:

The same way you mount a volume to save your config and userdata folders as described in the openHAB Docker docs. Docker Hub