need help with a Ping rule - pinging 2 devices

563 views
Skip to first unread message

Eric Koester

unread,
Feb 5, 2024, 5:30:17 PM2/5/24
to TasmotaUsers
2 years ago, I made a build of Tasmota 10.1.0 with the Ping command included.  I loaded it in a few Sonoff S31 switches and the basic ping rules I've tried all work correctly, so I know ping is working.  
I do not have IF statement support compiled in the build.
 
I want to power cycle an S31 switch after I get successful pings from 2 local devices.
I'm trying to catch bootup errors, so I only want to power cycle if I get successful pings.
If either device fails to boot, I do NOT want to power cycle, so I can investigate.

I made a rule to ping one device and power cycle.  It works.
Rule2 ON Time#Minute|3 DO Ping4 192.168.7.223 ENDON ON Ping#192.168.7.223#Success>1 DO Backlog Power1 0; Delay 100; Power1 1; ENDON

I'm trying to figure out how to have the rule check BOTH devices and only power cycle if BOTH respond. 

I've tried this rule variation:
Rule3 ON Time#Minute|3 DO Backlog Ping4 192.168.7.223; Ping4 192.168.7.224 ENDON ON Ping#192.168.7.223#Success>1 DO Ping#192.168.7.224#Success>1 DO Backlog Power1 0; Delay 100; Power1 1 ENDON

Tasmota pings both devices and both respond, but the Tasmota Console shows "Unknown Command" when the 2nd part of the rule runs.
Can anyone see a way to make this work without compiling for IF statement support?

Thanks!
Eric

Justin Adie

unread,
Feb 5, 2024, 5:36:56 PM2/5/24
to Eric Koester, TasmotaUsers
Your syntax looks wrong

Rule3 

ON Time#Minute|3 
DO Backlog Ping4 192.168.7.223; Ping4 192.168.7.224 ENDON 

ON Ping#192.168.7.223#Success>1 
DO Ping#192.168.7.224#Success>1<---  this is Syntax for a trigger not a command.  Also missing Endon 

DO Backlog Power1 0; Delay 100; Power1 1 ENDON <--- missing on condition 



--
You received this message because you are subscribed to the Google Groups "TasmotaUsers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonoffusers...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/sonoffusers/b16e878e-c6f1-41d5-9bc3-9b2605034fe0n%40googlegroups.com.

Eric Koester

unread,
Feb 5, 2024, 5:45:34 PM2/5/24
to TasmotaUsers
Can someone suggest a working syntax, that checks for successful pings from both devices?

Thanks!
Eric

Eric Koester

unread,
Feb 5, 2024, 7:45:04 PM2/5/24
to TasmotaUsers
I just read about the BREAK syntax, 
see: https://tasmota.github.io/docs/Rules/#using-break-to-simulate-ifelseifelseendif
It says that putting BREAK at the end of a line "will stop the execution of the remaining rules that follow this rule within the rule set."

This rework of my rule appears to have the correct syntax, but BREAK isn't working as advertized...
The last line of the rule is getting parsed and executed anyway. 
What is going wrong?

Rule3 ON Time#Minute|3 DO Backlog Ping4 192.168.7.223; Ping4 192.168.7.224 ENDON
ON Ping#192.168.7.223#Success<1 DO DELAY 1 BREAK
ON Ping#192.168.7.224#Success<1 DO DELAY 1 BREAK
ON Ping#192.168.7.223#Success>1 DO Backlog DELAY 10; Power1 0; Delay 100; Power1 1 ENDON

Eric Koester

unread,
Feb 5, 2024, 10:26:47 PM2/5/24
to TasmotaUsers
Ahhh.  BREAK has been broken since 2020 and hasn't been fixed!

https://github.com/arendst/Tasmota/issues/7985

Philip Knowles

unread,
Feb 6, 2024, 1:20:33 AM2/6/24
to Eric Koester, TasmotaUsers
This might work - not tested
Rule3
ON Time#Minute|3 DO Backlog Ping4 192.168.7.223; Ping4 192.168.7.224; var1 0 ENDON
ON Ping#192.168.7.223#Success>1 DO add1 1 ENDON
ON Ping#192.168.7.224#Success>1 DO add1 1 ENDON
ON var1#state=2 DO Backlog Power1 0; Delay 100; Power1 1 ENDON

From: sonof...@googlegroups.com <sonof...@googlegroups.com> on behalf of Eric Koester <eric.k...@gmail.com>
Sent: 06 February 2024 03:26
To: TasmotaUsers <sonof...@googlegroups.com>
Subject: Re: need help with a Ping rule - pinging 2 devices
 

Justin Adie

unread,
Feb 6, 2024, 3:10:05 AM2/6/24
to Eric Koester, TasmotaUsers
I'm not aware of it not working.  That particular issue was related to one-shot rules

I suspect it is more an issue with your rules.  Remember that the ping may complete at different times leading to the rule firing separately for each ping.
Philip's solution is more elegant and avoids race conditions.  



Eric Koester

unread,
Feb 6, 2024, 11:26:36 AM2/6/24
to TasmotaUsers
I tried the suggested rule tweak.  I shortened the check time to 2 minutes.

Rule3
ON Time#Minute|2 DO Backlog Ping4 192.168.7.223; Ping4 192.168.7.224; var1 0 ENDON
ON Ping#192.168.7.223#Success>1 DO add1 1 ENDON
ON Ping#192.168.7.224#Success>1 DO add1 1 ENDON
ON var1#state=2 DO Backlog Power1 0; Delay 100; Power1 1 ENDON

The successful pings do increment the var1.  
No power cycle occurs.
There is no evidence the last rule check is occuring.

10:13:58.140 RSL: STATE = {"Time":"2024-02-06T10:13:58","Uptime":"0T11:30:11","UptimeSec":41411,"Heap":29,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":19,"MqttCount":0,"POWER":"ON","Wifi":{"AP":1,"SSId":"homeland","BSSId":"C4:91:CF:30:94:1E","Channel":11,"Mode":"11n","RSSI":100,"Signal":-50,"LinkCount":1,"Downtime":"0T00:00:03"}}
10:14:00.151 RUL: TIME#MINUTE|2 performs "Backlog Ping4 192.168.7.223; Ping4 192.168.7.224; var1 0"
10:14:00.389 RSL: RESULT = {"Ping":"Done"}
10:14:00.613 RSL: RESULT = {"Ping":"Done"}
10:14:00.817 RSL: RESULT = {"Var1":"0"}
10:14:04.683 RSL: RESULT = {"Ping":{"192.168.7.223":{"Reachable":true,"IP":"192.168.7.223","Success":4,"Timeout":0,"MinTime":7,"MaxTime":19,"AvgTime":11}}}
10:14:04.771 RUL: PING#192.168.7.223#SUCCESS>1 performs "add1 1"
10:14:04.908 RSL: RESULT = {"Add1":"1.000"}
10:14:05.301 RSL: RESULT = {"Ping":{"192.168.7.224":{"Reachable":true,"IP":"192.168.7.224","Success":4,"Timeout":0,"MinTime":2,"MaxTime":11,"AvgTime":7}}}
10:14:05.385 RUL: PING#192.168.7.224#SUCCESS>1 performs "add1 1"
10:14:05.523 RSL: RESULT = {"Add1":"2.000"}

I tried changing the last rule check to "ON var1#value=2" and it didn't fix it.

Rule3
ON Time#Minute|2 DO Backlog Ping4 192.168.7.223; Ping4 192.168.7.224; var1 0 ENDON

ON Ping#192.168.7.223#Success>1 DO add1 1 ENDON
ON Ping#192.168.7.224#Success>1 DO add1 1 ENDON
ON var1#value=2 DO Backlog Power1 0; Delay 100; Power1 1 ENDON

Eric Koester

unread,
Feb 6, 2024, 11:52:40 AM2/6/24
to TasmotaUsers
In the Rules documentation, I see it says that= is for string comparison and == is for numerical comparison.

I changed the last rule check to use == and it didn't fix it.  
As before, the successful pings do increment var1, but no power cycle occurs.

Rule3
ON Time#Minute|2 DO Backlog Ping4 192.168.7.223; Ping4 192.168.7.224; var1 0 ENDON
ON Ping#192.168.7.223#Success>1 DO add1 1 ENDON
ON Ping#192.168.7.224#Success>1 DO add1 1 ENDON
ON var1#value==2 DO Backlog Power1 0; Delay 100; Power1 1 ENDON

Eric Koester

unread,
Feb 6, 2024, 11:56:41 AM2/6/24
to TasmotaUsers
I did a custom compile of Tasmota 13.3.0 using Tasmocompiler
https://github.com/benzino77/tasmocompiler
and added the Ping command and Rules, which I believe contains IF statements in the rules.
So, the IF statement is now vailable, if that makes this dual ping rule easier.

NA

unread,
Feb 6, 2024, 12:34:08 PM2/6/24
to TasmotaUsers
Rule1
  ON system#boot do Var1 0 ENDON
  ON Var1#State>1 DO Backlog Var1 0; Power1 0; Delay 100; Power1 1 ENDON
  ON Time#Minute|3 DO Backlog Ping2 192.168.7.223; Ping2 192.168.7.224 ENDON
  ON Ping#192.168.7.223#Success==0 DO Var1 0 ENDON
  ON Ping#192.168.7.223#Success>0 DO ADD1 1 ENDON
  ON Ping#192.168.7.224#Success==0 DO Var1 0 ENDON
  ON Ping#192.168.7.224#Success>0 DO ADD1 1 ENDON

Justin Adie

unread,
Feb 6, 2024, 1:25:42 PM2/6/24
to Eric Koester, TasmotaUsers
The syntax for the trigger is var1#state

A single = sign will work.   Or use > 1

If this isn't working then execute rule3 and check that there are not any odd characters getting in.  Lastly see whether the rule triggers when you manually assert var1 2

Be careful shortening the time period for repetition as this will reset the variable.  It must be a chunk longer than the value for ping timeout that tasmota uses (and I don't know what that is).





Philip Knowles

unread,
Feb 6, 2024, 2:22:25 PM2/6/24
to Justin Adie, Eric Koester, TasmotaUsers
You are misreading it. == is only used in IF statements.
You are resetting var1 when you don't need to. The whole point was to reset it when you ping so you can be sure of its state 


From: 'Justin Adie' via TasmotaUsers <sonof...@googlegroups.com>
Sent: Tuesday, February 6, 2024 6:25:26 PM
To: Eric Koester <eric.k...@gmail.com>
Cc: TasmotaUsers <sonof...@googlegroups.com>

Subject: Re: need help with a Ping rule - pinging 2 devices

Eric Koester

unread,
Feb 6, 2024, 3:19:40 PM2/6/24
to TasmotaUsers
Hi Philip Knowles.

Can you clairfy who this message is directed to?  You didn't start the message by addressing anyspecifically.
I believe it's to Justin Adie, since his message is the most recent message quoted in your message?

"You are misreading it. == is only used in IF statements.
You are resetting var1 when you don't need to. The whole point was to reset it when you ping so you can be sure of its state "

Thanks.
Message has been deleted

Eric Koester

unread,
Feb 6, 2024, 3:59:07 PM2/6/24
to TasmotaUsers
I can report that BOTH of these rules work as intended:

Rule1
ON system#boot do Var1 0 ENDON
ON Var1#State>1 DO Backlog Var1 0; Power1 0; Delay 100; Power1 1 ENDON
ON Time#Minute|2 DO Backlog Ping2 192.168.7.223; Ping2 192.168.7.224 ENDON

ON Ping#192.168.7.223#Success==0 DO Var1 0 ENDON
ON Ping#192.168.7.223#Success>0 DO ADD1 1 ENDON
ON Ping#192.168.7.224#Success==0 DO Var1 0 ENDON
ON Ping#192.168.7.224#Success>0 DO ADD1 1 ENDON
Rule3
ON Time#Minute|2 DO Backlog Ping4 192.168.7.223; Ping4 192.168.7.224; var1 0 ENDON
ON Ping#192.168.7.223#Success>1 DO add1 1 ENDON
ON Ping#192.168.7.224#Success>1 DO add1 1 ENDON
ON var1#state>1 DO Backlog Power1 0; Delay 100; Power1 1 ENDON

Eric Koester

unread,
Feb 7, 2024, 10:14:25 AM2/7/24
to TasmotaUsers
Thanks all for the advice and suggestions in getting the rules to work.

The rules documentation is not very complete, so it's hard to fully understand the rule syntax.
It would be helpful to see examples of working rules, in the documentation.
https://tasmota.github.io/docs/Rules/

NA

unread,
Feb 7, 2024, 10:24:38 AM2/7/24
to TasmotaUsers
Totally agree that the documentation is incomplete and not written with the mindset of someone just started Tasmota. It is kinda written from the perspective of someone who also knows everything. Nothing is cross linked in the documentation, it is hard to find commands and rules, there is no easy search bar where you can enter a rule or command and it shows it. Some descriptions are written in a very strange weird way.

Justin Adie

unread,
Feb 7, 2024, 10:28:51 AM2/7/24
to Eric Koester, TasmotaUsers
Tasmota is open source.  Everyone is free to contribute to the code and the documentation.

If you feel that there are things missing in the documentation then I'd suggest writing the missing text and submitting to the GitHub for assessment and inclusion

There is a rules cookbook available here: https://tasmota.github.io/docs/Rules/#rule-cookbook



Eric Koester

unread,
Feb 7, 2024, 10:33:26 AM2/7/24
to TasmotaUsers
" If you feel that there are things missing in the documentation then I'd suggest writing the missing text and submitting to the GitHub for assessment and inclusion"

That is unrealistic for me, as I barely know how the rules work.  I am NOT in a position to write about something I don't understand.
I need someone who knows, to document how it works.

NA

unread,
Feb 7, 2024, 10:37:48 AM2/7/24
to TasmotaUsers
Here are a few examples btw though which should have helped you find the solution from the documentation: https://tasmota.github.io/docs/Rules/#watchdog-for-wi-fi-router-or-modem

NA

unread,
Feb 7, 2024, 10:41:59 AM2/7/24
to TasmotaUsers
A good way to learn and get help is also using ChatGPT https://openai.com/chatgpt , just an example:

User
Can you make a Rule for Tasmota which does the following: Ping the ip 192.168.7.223 and 192.168.7.224 every 2 minutes, and if both ping results are successful, turn the power off, wait 5 seconds, and turn it on again.
ChatGPT
Sure, you can create a rule in Tasmota to accomplish this task using the RuleTimer1 feature for scheduling and the Power<x> command to control the power state. Here's a sample rule for your requirements:

plaintext
Copy code
Rule1
  ON Time#Timer=00:00:00 DO // Start the rule when the timer is triggered
    Ping1 192.168.7.223 // Ping the first IP address
    Ping2 192.168.7.224 // Ping the second IP address
    If [Ping1#Success]=1 && [Ping2#Success]=1 // If both pings are successful
      Power1 0 // Turn off the power
      Delay 5 // Wait for 5 seconds
      Power1 1 // Turn on the power
    EndIf
    RuleTimer1 120 // Schedule the rule to run again in 2 minutes
  ENDON
This rule will ping the specified IP addresses every 2 minutes. If both pings are successful, it will turn off the power, wait for 5 seconds, and then turn it back on.

User
Can you write the same rule but with no if clauses which are not present in the Tasmota firmware.
ChatGPT
Certainly! Here's the revised rule without using if clauses:

plaintext
Copy code
Rule1
  ON Time#Timer=00:00:00 DO // Start the rule when the timer is triggered
    Ping1 192.168.7.223 // Ping the first IP address
    Ping2 192.168.7.224 // Ping the second IP address
    Power1 0 [Ping1#Success] && [Ping2#Success] // Turn off the power if both pings are successful
    Delay 5 [Ping1#Success] && [Ping2#Success] // Wait for 5 seconds if both pings are successful
    Power1 1 [Ping1#Success] && [Ping2#Success] // Turn on the power if both pings are successful
    RuleTimer1 120 // Schedule the rule to run again in 2 minutes
  ENDON
This rule uses the [Ping#Success] placeholder directly to conditionally execute commands based on the success of the ping operations.

User
Can you write the same rule without timers which are not present in the firmware used.
ChatGPT
Sure, if timers aren't supported in your firmware, you can use a loop to achieve the same functionality. Here's the rule without timers:

plaintext
Copy code
Rule1
  ON System#Boot DO // Start the rule when the device boots up
    Repeat 0 // Start an infinite loop
      Ping1 192.168.7.223 // Ping the first IP address
      Ping2 192.168.7.224 // Ping the second IP address
      Power1 0 [Ping1#Success] && [Ping2#Success] // Turn off the power if both pings are successful
      Delay 5 [Ping1#Success] && [Ping2#Success] // Wait for 5 seconds if both pings are successful
      Power1 1 [Ping1#Success] && [Ping2#Success] // Turn on the power if both pings are successful
      Delay 120 // Wait for 2 minutes
    ENDRepeat
  ENDON
This rule uses a Repeat loop that continuously checks the ping status of the specified IP addresses, turns off the power, waits, and then turns it back on if both pings are successful. The loop runs indefinitely.

These examples might not work, but give you a good start and hint.

You can just use ChatGPT to create rules and if theyre not correct learn from it, even ask ChatCPT about why it is not working, for example enter your rule and ask whats wrong with it or how to make it work.

Reply all
Reply to author
Forward
0 new messages