Rule on no data with timer

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
rolfie
New user
Posts: 4
Joined: 04 Jun 2023, 22:46

Rule on no data with timer

#1 Post by rolfie » 04 Jun 2023, 22:55

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?

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Rule on no data with timer

#2 Post by Ath » 04 Jun 2023, 23:33

Most likely you have more rules than that, please share your complete set of rules, as the order of some may make a difference
/Ton (PayPal.me)

rolfie
New user
Posts: 4
Joined: 04 Jun 2023, 22:46

Re: Rule on no data with timer

#3 Post by rolfie » 05 Jun 2023, 08:23

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

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Rule on no data with timer

#4 Post by Ath » 05 Jun 2023, 08:39

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
/Ton (PayPal.me)

rolfie
New user
Posts: 4
Joined: 04 Jun 2023, 22:46

Re: Rule on no data with timer

#5 Post by rolfie » 05 Jun 2023, 11:24

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!

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 23 guests