Cron/time triggers not working

New install of OH3 & I’m testing rules. I set a lamp module set to turn on & off every 2 minutes but got no action. I also tried just setting a time trigger with the same results. It works if I click the “Run Now” button so I know the commends are right, just not triggering.

This seems really simple so I can’t see what could be causing the problem. Any ideas?

Here’s the code:
triggers:

  • id: “1”
    configuration:
    cronExpression: 0 0/2 * * * ? *
    type: timer.GenericCronTrigger
    conditions: []
    actions:
  • inputs: {}
    id: “2”
    configuration:
    itemName: AtticLampModule_Dimmer
    command: ON
    type: core.ItemCommandAction

I haven’t played with the UI rules much, but it looks to me like this rule will only turn the lamp ON. Do you have a second rule that turns it off?

Yes, I have another one which is the same except the ON command is OFF

This would not be the correct way to do this - you are using a cron schedule so in effect both rules will be run at the same time and hence the lamp could get put in either state depending on which rule happens to run slightly slower (ie. last).

What you should do is a use a script to check the state of the lamp and then toggle it:

var myItem = XXX
if (myItem.state == ON) {
  myItem.sendCommand(OFF)
} else {
  myItem.sendcommand(ON)
}
1 Like

Have you looked in your events.log ?

Sunny, thanks. That would be a cleaner way to do it. I’m trying to stay with the GUI as much as possible. I set the ON rule for even minutes & the OFF rule for odd minutes.

Rossko57, I have not. Thanks for the suggestion I’ll take a look today.

Another place to look in addition to events.log is the developer sidebar. Type alt-shift-d to open it up and select the second tab. You can see Items events and rule events there which will tell you whether or not your rules are running.

rlkoshak, thanks. I do see teh triggers. This is what teh ON looks like:

openhab/items/AtticLampModule_Dimmer/state
ItemStateEvent
{“type”:“Percent”,“value”:“1”}

Then there’s this:

openhab/items/AtticLampModule_Dimmer/statechanged
ItemStateChangedEvent
{“type”:“Percent”,“value”:“1”,“oldType”:“Percent”,“oldValue”:“100”}

I also tried triggering manually which results in teh item changing from 0 to 1 but the code in teh event monitor looks exactly the same. Don’t understand it.

Apparently it’s something to do with the dimmer. I tried again with a binary switch and it’s working without issue.

That doesn’t explain why it works manually & not from the timed rule but that’s all I needed for now so I’m not going to chase this rabbit any further.

That looks like the effect of an OFF to me. But do you not see commands preceding the state events?

Yeah I copied teh wrong one in there. There is a state event, then the confirmation.

Anyway, as I said I just needed to test this functionality aside from whatever problem the dimming feature is introducing so I’m good. Thanks for your help.

I have what I think is the same issue.

Time triggers seem to not work at all when set up in the GUI.

To reproduce:

Set up a rule with a trigger that works (e.g. on an item state update).

Check that it works and indeed turns, for example, the light on.

Delete the trigger.

Add Trigger → Time Event → on a schedule (cron)

Then type “* * * * *” as the cron expression.

Enable the rule and wait a minute.

The rule should trigger but doesn’t.

When were you expecting that to trigger?

Every minute

https://crontab.guru/every-1-minute

Have you looked in your openhab.log?

The scheduler used in openHAB uses seconds, so you’d want six or seven elements.

1 Like

OK I changed it to the correct 7 element cron specification using the cron builder and it worked.

Thanks heaps @rossko57

1 Like