Page 1 of 1

Rules not working 20201227 and later

Posted: 16 Oct 2021, 18:43
by dynamicdave
I'm probably doing something incorrectly, but I can't make a rule for a normal switch to work after release esp8266-normal-2020-1227
I have two switches named top and bottom. I can see the values changing if I look on the devices tab.
But the rule dosen't want to publish the value.
If I send an event 'sendSensorPosition' from Node-RED it will publish the values correctly.
Any ideas as to what I'm doing wrong would be appreciated.

Code: Select all

On sendSensorPosition Do
   event,publishReading
EndOn

On publishReading Do
   publish,garagedoor/sensors,'{"level":[top#level],"sensor":"top"}'
   publish,garagedoor/sensors,'{"level":[bottom#level],"sensor":"bottom"}'
endOn

On top#level Do
   event,publishReading
EndOn

On bottom#level Do
   event,publishReading
EndOn

Re: Rules not working 20201227 and later

Posted: 16 Oct 2021, 19:07
by TD-er
Hmm at first sight, I don't see what may be wrong here.
Can you add some calls to logitem to help debugging?
For example, does it even enter On top#level Do
?

Re: Rules not working 20201227 and later

Posted: 16 Oct 2021, 19:36
by ThomasB
Along with that, check Tools->Advanced->RulesSettings and verify both RULES and OLD ENGINE are enabled.

Another cause of rule failure is due to the presence of an unprintable character in the rule text file. Hard to find these unless you copy/paste the entire text into an editor that shows such things. Notepad++ works well.

- Thomas

Re: Rules not working 20201227 and later

Posted: 16 Oct 2021, 19:52
by dynamicdave
It's really strange - it works fine in mega-version ESP8266 20201227, but in later versions it doesn't.
I've spent too much time on it today, but will insert some debugs, as suggested, and see if it is entering... on top#level do
I'm actually using a Wemos D1 Mini fitted with a 4Mb chip and an ESP01-S to create a voice-operated garage-door controller.

Re: Rules not working 20201227 and later

Posted: 16 Oct 2021, 20:00
by ThomasB
You didn't say if you've tried the very latest ESPEASY releases. But keep in mind that some 2020 releases had weird rule formatting quirks that were eventually resolved. The one that got me was reported here (not your issue, but this shows how fussy the rule syntax had been):
https://github.com/letscontrolit/ESPEasy/issues/2987

Long story short, go big and install the very latest.

- Thomas

Re: Rules not working 20201227 and later

Posted: 16 Oct 2021, 20:08
by ThomasB
Looks like a fun project.

Be sure to disable internal pullups on D1 / D2.

- Thomas

Re: Rules not working 20201227 and later

Posted: 16 Oct 2021, 20:21
by dynamicdave
Well it is developing into a fun project.
I'm using Alexa with some nodes in Node-RED, so I can say things like... "Alexa, open garage door" or "Alexa, close garage door"
I dropped one of the remote control key fobs the other day - broke the plastic case - BUT the electronics still works.
So rather than throwing it away I took it to pieces and found the place where the push-button switch joins to the PCB.
Soldered some wires, so if you touch them together for 3 or more seconds - the garage door is activated.
I'm using a relay on the ESP01-S to simulate the key-fob being pressed.
I installed a couple of microswitches at the top and bottom of the door's travel so I can detect where it is.
I've had the door (sort of) working today - but the rules aren't triggering the publish to MQTT.
key_fob_a.jpg
key_fob_a.jpg (150.45 KiB) Viewed 9177 times

Re: Rules not working 20201227 and later

Posted: 16 Oct 2021, 20:42
by dynamicdave
I don't believe this - I couldn't wait until tomorrow, so I went and got all the kit and reflashed it with... ESP_Easy_mega_20211005_normal_ESP8266_4M1M
It appears to be publishing the switch states now via MQTT.

Re: Rules not working 20201227 and later

Posted: 16 Oct 2021, 21:08
by ThomasB
That's good news.

I quickly looked at ESPEasy GitHub tickets and didn't see any reports about rule problems around the 20201227 time frame. Maybe @TD-er has an idea of what might have been the problem.

- Thomas

Re: Rules not working 20201227 and later

Posted: 16 Oct 2021, 21:30
by dynamicdave
Thanks for all your help.
I have no idea what has changed from this morning.
I swear it wasn't working and none of the other versions would work until I got back to 2020127.
Now after reflashing (again) with 20211105 it has decided to behave itself!!!
Makes me out to be a fraud !!
Totally confused of the UK.

Re: Rules not working 20201227 and later

Posted: 16 Oct 2021, 22:36
by TD-er
What could have helped here is that maybe you did save the rules again using one of the later versions?
I remember that the JavaScript used to save the rules, also has some basic checks in it like proper (or at least consequent) line endings.
So it could have been something Thomas already suggested, that it was a misbehaving non-ASCII character in there?