# Sometimes rules don't get executed?

**URL:** <https://community.openhab.org/t/sometimes-rules-dont-get-executed/51192>\
**Category:** Scripts & Rules\
**Created:** [September 10, 2018, 4:31pm UTC](https://community.openhab.org/t/sometimes-rules-dont-get-executed/51192 "2018-09-10T16:31:40Z")\
**Posts on this page:** 20\
**Page:** 3

<div class="post-metadata">

**Author:** ![rkrisi](https://community.openhab.org/user_avatar/community.openhab.org/rkrisi/32/68680_2.png) [@rkrisi](https://community.openhab.org/u/rkrisi)\
**Post date:** [September 17, 2018, 4:02pm UTC](https://community.openhab.org/t/sometimes-rules-dont-get-executed/51192/41 "2018-09-17T16:02:29Z")

</div>

Thanks for your help! I was able to get rid of the errors when it runs, by removing the System started trigger from the my other rules, where that error was referring to.  
I have added a switch to it, if I trigger it with it, it runs well, without errors and calculates the right time of day. I will see if the removed ‘System started’ trigger makes sense…

---

<div class="post-metadata">

**Author:** ![rlkoshak](https://community.openhab.org/user_avatar/community.openhab.org/rlkoshak/32/75251_2.png) [@rlkoshak](https://community.openhab.org/u/rlkoshak)\
**Post date:** [September 17, 2018, 4:33pm UTC](https://community.openhab.org/t/sometimes-rules-dont-get-executed/51192/42 "2018-09-17T16:33:01Z")

</div>

With the removed System started trigger, you will have to wait until the next scheduled time trigger for vTimeOfDay to be updated when OH restarts.

If the errors only occur during the System started trigger, then the errors are almost certainly caused by the previously mentioned bug in OH.

---

<div class="post-metadata">

**Author:** ![rkrisi](https://community.openhab.org/user_avatar/community.openhab.org/rkrisi/32/68680_2.png) [@rkrisi](https://community.openhab.org/u/rkrisi)\
**Post date:** [September 18, 2018, 8:43pm UTC](https://community.openhab.org/t/sometimes-rules-dont-get-executed/51192/43 "2018-09-18T20:43:48Z")

</div>

It seems that removing the System started trigger did the trick. Now it is working as normal…

---

<div class="post-metadata">

**Author:** ![rkrisi](https://community.openhab.org/user_avatar/community.openhab.org/rkrisi/32/68680_2.png) [@rkrisi](https://community.openhab.org/u/rkrisi)\
**Post date:** [October 1, 2018, 10:00pm UTC](https://community.openhab.org/t/sometimes-rules-dont-get-executed/51192/44 "2018-10-01T22:00:11Z")

</div>

Unfortunately I’m back again with this problem. However it is now clear that this rule is not only not executed triggered by astro events, but by cron events also. Sometimes it works as it should sometimes not. Now I’m on 2.4 M4 (the latest Milestone build) and I have experienced not only this, but (which was always there in my setup):

- Randomly one or more rules don’t get executed. Moreover not only don’t get executed but the event won’t trigger my rule. I have some rule which has a logInfo in the beginning of the rule and when an event should trigger the rule I can only see in the events.log that the corresponding trigger Item state changed, but not the log which the rule should produce
- I have increased the execution threads to 7 so now I always have at least 3-4 thread which is available.
- When these ‘rules don’t get executed’ errors happen I can’t see any change on hardware side (CPU load is around 5-10%, memory is not full, everything works as before).
- Moreover I even don’t have to restart openHab or RPi, just wait a couple of hours and everything is back to normal. The logs also don’t produce any significant error or any unfamiliar thing for me.

---

<div class="post-metadata">

**Author:** ![rlkoshak](https://community.openhab.org/user_avatar/community.openhab.org/rlkoshak/32/75251_2.png) [@rlkoshak](https://community.openhab.org/u/rlkoshak)\
**Post date:** [October 2, 2018, 4:49pm UTC](https://community.openhab.org/t/sometimes-rules-dont-get-executed/51192/45 "2018-10-02T16:49:24Z")

</div>

> [@rkrisi](#):
>
> However it is now clear that this rule is not only not executed triggered by astro events, but by cron events also.

Both Astro and cron triggered Rules are triggered from a separate thread pool.

> [@rkrisi](#):
>
> I have increased the execution threads to 7 so now I always have at least 3-4 thread which is available.

Do you know for sure this is the case? See the post I replied with above, particularly post 12. Look at the quartz thread pool to see if you are using those up. You cannot have more than two cron triggered Rules run at the same time.

Also, do you see “Scheduled Astro event-jobs for thing astro:sun:home” for each of your Astro Things? If not then the events are not even being scheduled which points to a problem with the Astro binding.

> [@rkrisi](#):
>
> When these ‘rules don’t get executed’ errors happen I can’t see any change on hardware side (CPU load is around 5-10%, memory is not full, everything works as before).

Look to see if all your RuleEngine threads are running too.

---

<div class="post-metadata">

**Author:** ![rkrisi](https://community.openhab.org/user_avatar/community.openhab.org/rkrisi/32/68680_2.png) [@rkrisi](https://community.openhab.org/u/rkrisi)\
**Post date:** [October 2, 2018, 4:59pm UTC](https://community.openhab.org/t/sometimes-rules-dont-get-executed/51192/46 "2018-10-02T16:59:03Z")

</div>

> [@rlkoshak](#):
>
> You cannot have more than two cron triggered Rules run at the same time.

That might be one problem. I have another rule which is triggered by cron exactly at 11pm. I will change that and see if it helps

---

<div class="post-metadata">

**Author:** ![rkrisi](https://community.openhab.org/user_avatar/community.openhab.org/rkrisi/32/68680_2.png) [@rkrisi](https://community.openhab.org/u/rkrisi)\
**Post date:** [October 9, 2018, 12:32pm UTC](https://community.openhab.org/t/sometimes-rules-dont-get-executed/51192/47 "2018-10-09T12:32:46Z")

</div>

Dear @rlkoshak!

I have tried simplyfing my rules and removing any unnecessary cron triggers from rules. Now my system mostly depends on the Time Of Day rule if the rule is based on day-states.

However I still have the original problem. My rule which turns on and off the LEDs (I have the same rule as in the original post), sometimes don’t get executed. I have made sure that there is enough rule execution thread is available all-time, so it might be some other problem. Funny though that I can see the log produced by the rule along all day, but not at night… (where this rule really works…)

---

<div class="post-metadata">

**Author:** ![rossko57](https://community.openhab.org/user_avatar/community.openhab.org/rossko57/32/70263_2.png) [@rossko57](https://community.openhab.org/u/rossko57)\
**Post date:** [October 9, 2018, 1:18pm UTC](https://community.openhab.org/t/sometimes-rules-dont-get-executed/51192/48 "2018-10-09T13:18:27Z")

</div>

That rule triggers on **changed** i.e. OFF to ON. It won’t trigger if you get repeated updates of ON if it is already ON. Confident you are actually getting changes logged for the Item?

---

<div class="post-metadata">

**Author:** ![rkrisi](https://community.openhab.org/user_avatar/community.openhab.org/rkrisi/32/68680_2.png) [@rkrisi](https://community.openhab.org/u/rkrisi)\
**Post date:** [October 9, 2018, 1:23pm UTC](https://community.openhab.org/t/sometimes-rules-dont-get-executed/51192/49 "2018-10-09T13:23:07Z")

</div>

Yes. I can see in the log that ‘Zone4 changed from OFF to ON’. If the rule works I can immediately see the log. If not, the ‘Zone4 changed from OFF to ON’ still there, but there are no other logs.

---

<div class="post-metadata">

**Author:** ![rossko57](https://community.openhab.org/user_avatar/community.openhab.org/rossko57/32/70263_2.png) [@rossko57](https://community.openhab.org/u/rossko57)\
**Post date:** [October 9, 2018, 1:35pm UTC](https://community.openhab.org/t/sometimes-rules-dont-get-executed/51192/50 "2018-10-09T13:35:32Z")

</div>

Okay, its a simple trigger and you’re confident about trigger event actually happening.  
Nothing weird about Item naming.  
First line is a logInfo. All good stuff so far.

Suggestion: change title of your rule (non-obviously, these must be system-wide unique) in case there is a duplicate cached.  
Suggestion: add another rule triggered by Item update to ON and see how that behaves

---

<div class="post-metadata">

**Author:** ![rkrisi](https://community.openhab.org/user_avatar/community.openhab.org/rkrisi/32/68680_2.png) [@rkrisi](https://community.openhab.org/u/rkrisi)\
**Post date:** [October 9, 2018, 1:51pm UTC](https://community.openhab.org/t/sometimes-rules-dont-get-executed/51192/51 "2018-10-09T13:51:52Z")

</div>

Thanks! I have tried it. Renamed my rule and add another rule (to the same file, maybe try adding it to a new file?)  
However I can’t see neither of the two rule running (no logging). Plus now I can’t even see any of my rule producing logs…  
One thing to add (I don’t know when it happens or it has anything related to it…) I have these switches in a group (OR) , and that group is displayed in a sitemap… However sometimes the group label says that it is OFF, but there are items in it which is ON…

Edit2: for example for the Time Of Day rule (day\_state) I have a dummy switch for debugging which can trigger this rule. If I press that switch the rule gets triggered (I can see it in the logs), but not other rules running now… So it seems that the triggers which has to happen ‘automatically’ are not triggering the rules.

---

<div class="post-metadata">

**Author:** ![rlkoshak](https://community.openhab.org/user_avatar/community.openhab.org/rlkoshak/32/75251_2.png) [@rlkoshak](https://community.openhab.org/u/rlkoshak)\
**Post date:** [October 9, 2018, 2:26pm UTC](https://community.openhab.org/t/sometimes-rules-dont-get-executed/51192/52 "2018-10-09T14:26:04Z")

</div>

> [@rkrisi](#):
>
> Edit2: for example for the Time Of Day rule (day\_state) I have a dummy switch for debugging which can trigger this rule. If I press that switch the rule gets triggered (I can see it in the logs), but not other rules running now… So it seems that the triggers which has to happen ‘automatically’ are not triggering the rules.

What are you using to trigger these other Rules? If you are triggering them using changed but you manually trigger the ToD Rule then those Rules won’t trigger because day\_state isn’t changing. Make sure that the Rules are using the appropriate trigger.

Over all I don’t have any ideas. If you are not out of Rule threads and the Item is changing states then the Rule should trigger.

---

<div class="post-metadata">

**Author:** ![rkrisi](https://community.openhab.org/user_avatar/community.openhab.org/rkrisi/32/68680_2.png) [@rkrisi](https://community.openhab.org/u/rkrisi)\
**Post date:** [October 9, 2018, 2:54pm UTC](https://community.openhab.org/t/sometimes-rules-dont-get-executed/51192/53 "2018-10-09T14:54:44Z")

</div>

I have around 40 rules, which is triggered by mostly Item changes, so it should work at any time…  
Any good method to track available/used rule execution threads?

---

<div class="post-metadata">

**Author:** ![rlkoshak](https://community.openhab.org/user_avatar/community.openhab.org/rlkoshak/32/75251_2.png) [@rlkoshak](https://community.openhab.org/u/rlkoshak)\
**Post date:** [October 9, 2018, 2:57pm UTC](https://community.openhab.org/t/sometimes-rules-dont-get-executed/51192/54 "2018-10-09T14:57:32Z")

</div>

> [@rkrisi](#):
>
> I have around 40 rules, which is triggered by mostly Item changes, so it should work at any time…

I think you miss my point. Rules triggered by changes will only trigger when the Item changes state.

If you trigger your time of day Rule by hand, the day\_state will not change. Thus those Rules that trigger on changes to day\_state will not trigger.

> [@rkrisi](#):
>
> Any good method to track available/used rule execution threads?

See post 12 by 5iver in the link I posted above.

---

<div class="post-metadata">

**Author:** ![rkrisi](https://community.openhab.org/user_avatar/community.openhab.org/rkrisi/32/68680_2.png) [@rkrisi](https://community.openhab.org/u/rkrisi)\
**Post date:** [October 9, 2018, 3:08pm UTC](https://community.openhab.org/t/sometimes-rules-dont-get-executed/51192/55 "2018-10-09T15:08:50Z")

</div>

I see your point, but for eg.: mobile phone’s location changes perodically and I have some rules which is triggered by that change. Sometimes all of these rules stops working, since it has logging and it won’t update the info…  
Secondly I have rules which are triggered for eg.: light switches. They also stop working at these times..

---

<div class="post-metadata">

**Author:** ![rossko57](https://community.openhab.org/user_avatar/community.openhab.org/rossko57/32/70263_2.png) [@rossko57](https://community.openhab.org/u/rossko57)\
**Post date:** [October 11, 2018, 10:42am UTC](https://community.openhab.org/t/sometimes-rules-dont-get-executed/51192/56 "2018-10-11T10:42:03Z")

</div>

> [@rkrisi](#):
>
> Sometimes all of these rules stops working

Okay, that’s clear and we’re wasting time concentrating on this one rule.

How-to monitor thread usage is here somewhere

> [@(OH 1.x and OH 2.x Rules DSL only\] Why have my Rules stopped running? Why Thread::sleep is a bad idea](https://community.openhab.org/t/why-have-my-rules-stopped-running-why-thread-sleep-is-a-bad-idea/47695):
>
> EDIT: While the general advice in this article still applies (i.e. it’s always worth while to make short running rules), the problem described in this article only applies to OH 1.x and Rules DSL in OH 2.x. In OH 3 and beyond, this is no longer a problem so if your rules stop running in any version of OH released in the last two years (as of this edit in 1/2023) this is not your problem. By way of explanation, in OH 3 each rule gets it’s own thread. It is no longer possible for a rule to starve…

---

<div class="post-metadata">

**Author:** ![rkrisi](https://community.openhab.org/user_avatar/community.openhab.org/rkrisi/32/68680_2.png) [@rkrisi](https://community.openhab.org/u/rkrisi)\
**Post date:** [October 11, 2018, 11:00am UTC](https://community.openhab.org/t/sometimes-rules-dont-get-executed/51192/57 "2018-10-11T11:00:03Z")

</div>

Yes and sorry for that, I’m also just found that this happens… hard to spot these errors. So for me (not sure) seems that sometimes all rules stops working and after an hour or so (not sure…) all rules starts to work again… no reboot or restart is required to work again.  
Thanks, I’ll try to set-up thread monitor and maybe that helps us to investigate this error.

---

<div class="post-metadata">

**Author:** ![rossko57](https://community.openhab.org/user_avatar/community.openhab.org/rossko57/32/70263_2.png) [@rossko57](https://community.openhab.org/u/rossko57)\
**Post date:** [October 11, 2018, 11:38am UTC](https://community.openhab.org/t/sometimes-rules-dont-get-executed/51192/58 "2018-10-11T11:38:13Z")

</div>

> [@rkrisi](#):
>
> hard to spot these errors

Oh yes. “Everything stopping” is not at all as clear-cut as it sounds, in an event driven system !

You might add a little rule that logs at ten-minute intervals or suchlike, to try and see what events lead up to seizure.

---

<div class="post-metadata">

**Author:** ![rkrisi](https://community.openhab.org/user_avatar/community.openhab.org/rkrisi/32/68680_2.png) [@rkrisi](https://community.openhab.org/u/rkrisi)\
**Post date:** [October 11, 2018, 2:15pm UTC](https://community.openhab.org/t/sometimes-rules-dont-get-executed/51192/59 "2018-10-11T14:15:56Z")

</div>

Yes this is what is strange to me also. No errors or any other sign of problem, just like the ruleEngine stops and everything else works as expected (bindings, etc…)

I will make a rule and try to monitor the threads

Thanks!

---

<div class="post-metadata">

**Author:** ![rkrisi](https://community.openhab.org/user_avatar/community.openhab.org/rkrisi/32/68680_2.png) [@rkrisi](https://community.openhab.org/u/rkrisi)\
**Post date:** [October 13, 2018, 6:08pm UTC](https://community.openhab.org/t/sometimes-rules-dont-get-executed/51192/61 "2018-10-13T18:08:06Z")

</div>

So I had a little time to play around with this. I have been watching the ruleEngine with this command:

```auto
shell:threads --list |grep "RuleEngine" |wc -l

```

If I’m right it should return how many threads are used by the rule engine, right? It is really unpredictable. Sometimes none of my rules are running and it returns 6 (which is 5 running threads if you distract the 1 from this caused by this call).

I have also set-up a test rule which runs every 10 minutes. For example, now the status is the following:

- The test rule is working, every 10 minute, it produces some log.
- The command above returns only 1 thread is used.
- My other rules don’t want to work…

After 5 mins:

- It seems that somewhere the execution is stuck, because all of the rules are executed together (around 100 log entry in my events.log that my rules ran around 20 times) which should ran in the previous 10 minutes. So it seems that it “knew” that the rule should run, but unable to execute them and now executes together.

For example the rule which I inserted in the first post, ran together, which should ran when it detects motion in one of my room:

```auto
2018-10-13 20:03:26.006 [INFO] [smarthome.model.script.wifiled.rules] - Night Light rule started!

2018-10-13 20:03:26.379 [INFO] [smarthome.model.script.wifiled.rules] - Night Light rule started!

2018-10-13 20:03:26.480 [INFO] [smarthome.model.script.wifiled.rules] - Night Light rule started!

2018-10-13 20:03:26.490 [INFO] [smarthome.model.script.wifiled.rules] - Night Light rule started!

2018-10-13 20:03:26.492 [INFO] [smarthome.model.script.wifiled.rules] - Night Light rule started!

2018-10-13 20:03:26.566 [INFO] [smarthome.model.script.wifiled.rules] - Night Light rule started!

2018-10-13 20:03:26.888 [INFO] [smarthome.model.script.wifiled.rules] - Night Light rule started!

2018-10-13 20:03:26.931 [INFO] [smarthome.model.script.wifiled.rules] - Night Light rule started!

2018-10-13 20:03:26.954 [INFO] [smarthome.model.script.wifiled.rules] - Night Light rule started!

2018-10-13 20:03:30.285 [INFO] [smarthome.model.script.wifiled.rules] - Night Light rule started!

2018-10-13 20:03:30.402 [INFO] [smarthome.model.script.wifiled.rules] - Night Light rule started!

```

…and many more…

After this “catching up” everything works as it should… and it happens after a random period…

Hope it is understandable what I’m trying to say.

[Previous page](https://community.openhab.org/t/sometimes-rules-dont-get-executed/51192.md?page=2)

[Next page](https://community.openhab.org/t/sometimes-rules-dont-get-executed/51192.md?page=4)
