Repeating Timer - Cron or Expire?

Spent the evening doing some reading and still not sure the best way to attack this. Most everything I found dealt with a situation where you turn something on based on something that happened, check to see the state and act accordingly or expire after a certain time.

I just need a simple rule to run forever and ever of 3 minutes on and 15 minutes off and let me know in say 30 minutes of time if there has been an issue with the state. ie, it has not run.

Which is the best way to go cron or expire?

On OH 2.2.0-1


Because expire can only set to one command (ON or OFF) i would combine a cron every 18 minutes to ON and a expire after 3 minutes to OFF. You can also use Timer.

PS: 2.3.0 has been released

1 Like

For that part I’d use a persistence service and present the data of the last xx minutes on a chart. Since you are interested in a limited time only, you probably are looking for a non-growing database. RRD4J would be a solution.

Took my first stab at the code but it throws an error:


Switch inovelli_plug1 "Plug 1" { channel="zwave:device:5c353509:node9:switch_binary1" expire="3m,command=OFF" }


rule "tower timer"

	Time cron "0/1 0/18 0 ? * * *"
	{sendCommand(inovelli_plug1, ON)}
rule "tower timer"
	Time cron "0/1 0/18 0 ? * * *"
	sendCommand(inovelli_plug1, ON)

Thanks Harry, There is something wrong with my item as well. It throws this error:

[WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'default.items' has errors, therefore ignoring it: [19,87]: missing '}' at 'expire'

i used the model of what i have found in the post but something aint right…

You were missing the “,” before “expire”.

oops, got it! thanks!

Now I get this error…

[vent.ItemStateChangedEvent] - inovelli_plug1 changed from NULL to OFF

Immediately after I get this:

[ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Tower Timer changed': The name 'Off' cannot be resolved to an item or type; line 12, column 32, length 3

That’s not entirely correct. You can configure expire to send any command, not just ON or OFF. For example, if you don’t specify anything expire="2m" will set that Item to NULL after 2 minutes. If you have a Number Item you can use expire="2m,state=-1" which will set the Number Item to -1 using a postUpdate after 2 minutes without a change.

It is true that you can only specify one value that the expire binding sets the Item to.


Hey Rich, not sure I understand. I have this as the expire setting:


Where does it see “Off”?

I don’t know where, but in the Rule “Tower Timer changed” you are trying to use Off instead of OFF.

VSCode is great at finding problems like this.

Thanks Rick, found that error and have that cleared out now.

Now all i get is this, and then…nothing. Wait 15 minutes, nothing. Wait 20 minutes nothing. For some reason it is not turning the switch on.

18:04:46.016 [vent.ItemStateChangedEvent] - inovelli_plug1 changed from NULL to OFF

If you are expecting the expire binding to turn the Item ON then you need to change it to expire="3m,command=ON". The last part of the binding config tells expire what to set the state to. The Item is already OFF so there is nothing for the expire binding to do with “command=OFF”.

Well, i was wondering that. So should my rule be to turn it OFF? And then the expire binding turns it ON for 3 minutes?

Depends on what you want to happen when the timer expires. The “command=OFF” specifies the command that will get sent three minutes after the Item is set to any state that is not OFF.

Yes, so i want the timer to run for three minutes and off for 15…

So like Harry said, have a rule that runs every 18 minutes. sendCommand(ON) on in that Rule. Then configure expire with “3m,command=OFF”.

The switch will stay on for 3 minutes then off for 15 and then the rule will run again.

Hey Rick, was just writing this up. Was all making sense now. The rule runs to turn the switch ON. Immediately the Expire Binding starts tracking that and after 3 minutes it turns the switch OFF. The switch uses a cron job to run for a total of 18 minutes. So after the switch runs for 3 minutes, it then turns OFF for 15 minutes when the rule then fires again to turn the switch ON.

So that said I think there must be an issue with the rule. This is what I have in the log…

[INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'towers.rules'
[WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'towers.rules' is either empty or cannot be parsed correctly!
[INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'towers.rules'

Three minutes later…

[ome.event.ItemCommandEvent] - Item 'inovelli_plug1' received command OFF
[vent.ItemStateChangedEvent] - inovelli_plug1 changed from ON to OFF

at that point, the rule should fire again in 15 minutes to turn it back ON, but nothing happens.

Add logging to the rule to make sure it is firing.

Rebuild the Cron expression using the quartz Cron builder just to make sure there is nothing wrong with it. I’m not good enough with Cron to tell just by eye.