Page 1 of 1

Rule on no data with timer

Posted: 04 Jun 2023, 22:55
by rolfie
Hello,

I have one ESP that sometimes hang, and need some love then. But an other ESP is running with an 7dgt on it showing the temperature. Now it shows continue the old value untill received new data. Thought I had an solution with rules but I can't get it to work. On startup showing boot till first data received works fine. Here my code:

Code: Select all

on MQTT#Buiten do
  timerSet,1,90
endon

On Rules#Timer=1 do
  7dtext,lost
  timerSet,1,0
endon
So in my opinion it's when receiving data on the MQTT topic it starts the timer for 90 seconds, every time data is received the timer is set to again 90 seconds. If the timer hits the end before date received it shows lost on the 7dgt and sets the timer to 0.

The "on MQTT#Buiten do" and "7dtext,lost" are the only lines i know for sure they work, because they work in a other rule.

Can someone help me please?

Re: Rule on no data with timer

Posted: 04 Jun 2023, 23:33
by Ath
Most likely you have more rules than that, please share your complete set of rules, as the order of some may make a difference

Re: Rule on no data with timer

Posted: 05 Jun 2023, 08:23
by rolfie
You where right! Had all in Rules Set 3 tab, but now I have placed one line in Rules Set 1 tab and all is working.

Rules Set 1:

Code: Select all

on MQTT#Buiten do
  7dt,[MQTT#Buiten]
  timerSet,1,90
endon
Rules Set 2:

Code: Select all

On System#Boot do 
7dtext,boot 
endon
Rules Set 3:

Code: Select all

on Rules#Timer=1 do
  7dtext,lost
  timerSet,1,0
endon

Re: Rule on no data with timer

Posted: 05 Jun 2023, 08:39
by Ath
And I think adding the line "7dt,[MQTT#Buiten]" helped a bit too.

If you had 2 event handlers for on MQTT#Buiten do, then only the first will be executed. As a performance optimization, after executing a rule that matches the condition, further processing of the rules is cancelled, so the events have to be ordered from most specific to more general, so the correct order would be:

Code: Select all

on MQTT#Buiten=10 do // More specific
...
endon

on MQTT#Buiten do // Less specific, 'catch all'
...
endon

Re: Rule on no data with timer

Posted: 05 Jun 2023, 11:24
by rolfie
That rule was existing already, only added the timer there. Your explanation about first rule going to be executed explained why it didn't work. On rule 3 I had the code from the first post.

Thanks, learned again today!