OH3: Script running every X Minutes

Hello Guys,

how can i achieve a script (like Blockly or ECMA) running every couple of minutes once?

I found the SetInterval-Command (ECMA), but that wont work as the script need to be triggered and it isnt constantly running, right?

Better to use the Rule with a CRON trigger?

Idea: Check every like 15 Minutes if generated power is higher than consumed power - if yes, turn on AC. If no, turn off AC

This is possible with the GUI functions without use scripts.

You can do that under Settings → Schedule
As Trigger you can choose Time-Event and then "on a schedule (cron).
You can build a cron expression with the builder:

Example every 15 minutes:

1 Like

Thank you very much. That worked.

Openhab is event based, why do you want to check every 15 minutes and not e.g. of the consumed / generated power is changing?

Because im not very familiar with timers and i dont want to switch OFF and ON and OFF and ON the AC-Units every few seconds.

I like to have a delay, like

Generated Power is less than X → Switch off AC Units
DONT Switch on during next X Minutes

If generated power is more than X and Timeout is not running anymore → Switch on AC Units

So for me it was easier to just run the script checking the energy every few minutes instead of dealing with timers

1 Like

Cool, thanks for sharing.

Would I would also recommend is to use hysteresis and set different threshold for on and off command, e.g. turning AC on if generated power - consumed power > 100, but turn it off when generated power - consumed power > 50

1 Like

Thats exactly what i did in Blockly - but at the moment fix values.

Not sure how i should define “internal” or “virtual” Items to be used without any connection to like KNX or Binding/Thing … just to show on HMI later