Tips for shortening rules

Moderators: Voyager, BertB, rtenklooster, Stuntteam, grovkillen, TD-er

Post Reply
Message
Author
Prutsium
Normal user
Posts: 31
Joined: 29 Mar 2018, 15:39
Location: Germany / Netherlands

Tips for shortening rules

#1 Post by Prutsium » 10 Sep 2018, 18:02

Hello all,

I am looking for some help to be able to shorten the below rule as when i would add all the tags i require i will exceed the character limit from the rules.
This is for a small project with RFID tags to open a door by various users.

The idea is that each tag sends a "Text" string and if the Tag matches it activates the Timer,1,5 so that the relay stays On for 5 seconds and after that the relay is set to off.

What is below is working so thats no issue it's a matter of cleaning up

Code: Select all

On RFID#Tag do
if [RFID#Tag]=1899267376
gpio,13,0
gpio,14,1
publish domoticz/in,{"command": "switchlight", "idx": 125, "switchcmd": "On" }
publish domoticz/in,{"idx":124,"nvalue":0,"svalue":"Card"}
timerSet,1,5

if [RFID#Tag]=2271020827 // Jerome
gpio,13,0
gpio,14,1
publish domoticz/in,{"command": "switchlight", "idx": 125, "switchcmd": "On" }
publish domoticz/in,{"idx":124,"nvalue":0,"svalue":"Tag"}
timerSet,1,5
endif
endon

On Rules#Timer=1 do 
gpio,13,1
gpio,14,0
publish domoticz/in,{"command": "switchlight", "idx": 125, "switchcmd": "Off" }
endon
Thanks for help :)

User avatar
grovkillen
Normal user
Posts: 2256
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Tips for shortening rules

#2 Post by grovkillen » 10 Sep 2018, 18:11

How many tags are we talking about?
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

User avatar
grovkillen
Normal user
Posts: 2256
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Tips for shortening rules

#3 Post by grovkillen » 10 Sep 2018, 18:13

If we could use multiple eventvalues we could shorten the rule some. I'd like you to add that as a suggestion on GitHub. Or maybe even better a array variable that we could use in rules! :)
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

Prutsium
Normal user
Posts: 31
Joined: 29 Mar 2018, 15:39
Location: Germany / Netherlands

Re: Tips for shortening rules

#4 Post by Prutsium » 10 Sep 2018, 18:33

grovkillen wrote:
10 Sep 2018, 18:11
How many tags are we talking about?
In the range of 15-20 tags (As it act as a central door opener)

Prutsium
Normal user
Posts: 31
Joined: 29 Mar 2018, 15:39
Location: Germany / Netherlands

Re: Tips for shortening rules

#5 Post by Prutsium » 10 Sep 2018, 18:36

grovkillen wrote:
10 Sep 2018, 18:13
If we could use multiple eventvalues we could shorten the rule some. I'd like you to add that as a suggestion on GitHub. Or maybe even better a array variable that we could use in rules! :)
Would it be possible within a rule to activate for example Rule2 or a sort of script?

As then i could move the Gpio and send to Domoticz ON to a rule / script and would cleanup the most already a bit.
Since the Bold commands could move out then:
On RFID#Tag do
if [RFID#Tag]=1899267376
gpio,13,0
gpio,14,1
publish domoticz/in,{"command": "switchlight", "idx": 125, "switchcmd": "On" }

publish domoticz/in,{"idx":124,"nvalue":0,"svalue":"Card"}
timerSet,1,5

User avatar
grovkillen
Normal user
Posts: 2256
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Tips for shortening rules

#6 Post by grovkillen » 10 Sep 2018, 18:49

Maybe we could have a rule chunk replacement similar to values... Hmm, I'm thinking out loud now. I need to discuss it with @TD-er
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

marion9
Normal user
Posts: 5
Joined: 02 Oct 2018, 10:46

Re: Tips for shortening rules

#7 Post by marion9 » 02 Oct 2018, 10:52

Very useful thread, you raised important question!

TD-er
Normal user
Posts: 1154
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Tips for shortening rules

#8 Post by TD-er » 02 Oct 2018, 13:07

At company level security, it is customary to have a central point where authorization and authentication is configured.
Often this is done via some kind of Active Directory or something similar.
So I guess it would make sense to create a query somehow to ask if some key is valid for that access.

It may be an issue that this will introduce some delay and doesn't work when the wifi is offline or the server you would send your query to.
So this is a trade-off for ease of access management and availability.

Another detail is that we currently have no user management system, nor an ActiveDirectory component in ESPeasy.
Maybe we can add an "Active Directory" like plugin to which you can send a value and get a true/false response.

The easiest work-around for now is to have a set of lines like this and use that to set a value in a Dummy parameter

Code: Select all

if [RFID#Tag]=1899267376
Then use that dummy to trigger the rule for those with access.
These "check for access" rules can be very short.

You also have up-to 4 rules files in which you can store rules.

User avatar
toffel969
Normal user
Posts: 466
Joined: 03 Jan 2017, 10:58
Location: Germany

Re: Tips for shortening rules

#9 Post by toffel969 » 02 Oct 2018, 14:19

Hi

Maybe a small improvement only,but I think you could already shorten the rules quite a bit.

Code: Select all


On [RFID#Tag]=1899267376 do
gpio,13,0
gpio,14,1
event,open
Endon

On [RFID#Tag]=2271020827 // Jerome
gpio,13,0
gpio,14,1
event,open
endon

On Rules#Timer=1 do 
gpio,13,1
gpio,14,0
publish domoticz/in,{"command": "switchlight", "idx": 125, "switchcmd": "Off" }
endon

On open do
timerSet,1,5
publish domoticz/in,{"command": "switchlight", "idx": 125, "switchcmd": "On" }
publish domoticz/in,{"idx":124,"nvalue":0,"svalue":"Card"}
Endon

Thanks for help :)
[/quote]
Domoticz on Raspi 2 -- 14 ESP units (hacked Sonoff,NodeMCUs, Wemos, self-built units) running with RC140- Mega 2.0.0 dev8

User avatar
budman1758
Normal user
Posts: 193
Joined: 15 Apr 2017, 05:13
Location: Riverside CA USA

Re: Tips for shortening rules

#10 Post by budman1758 » 02 Oct 2018, 20:47

Code: Select all

on rfid#tag do
if [rfid#tag]=1626454649  //joe blo
Event,goodtag
if [rfid#tag]=1626454648  //john doe
Event,goodtag
if [rfid#tag]=1626454647  // etc
Event,goodtag
if [rfid#tag]=1626454646  //etc
Event,goodtag
if [rfid#tag]=1626454645
Event,goodtag
if [rfid#tag]=1626454649
Event,goodtag
if [rfid#tag]=1626454648
Event,goodtag
if [rfid#tag]=1626454647
Event,goodtag
if [rfid#tag]=1626454646
Event,goodtag
if [rfid#tag]=1626454645
Event,goodtag
if [rfid#tag]=1626454649
Event,goodtag
if [rfid#tag]=1626454648
Event,goodtag
if [rfid#tag]=1626454647
Event,goodtag
if [rfid#tag]=1626454646
Event,goodtag
if [rfid#tag]=1626454645
Event,goodtag
if [rfid#tag]=1626454649
Event,goodtag
if [rfid#tag]=1626454648
Event,goodtag
if [rfid#tag]=1626454647
Event,goodtag
if [rfid#tag]=1626454646
Event,goodtag
if [rfid#tag]=1626454645
Event,goodtag
endif
endon

On goodtag do
Whatever you are doing...
endon
This takes less than 1 page of rules. I don't know if its "efficient" but it does work.
I use something similar in my keypad rules to determine what to do with the scan code output.
Last edited by budman1758 on 02 Oct 2018, 22:07, edited 1 time in total.
"The glass is twice as big as it needs to be".

User avatar
grovkillen
Normal user
Posts: 2256
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Tips for shortening rules

#11 Post by grovkillen » 02 Oct 2018, 21:37

Cool budman! Didn't know the rules engine could parse that many ifs.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

User avatar
budman1758
Normal user
Posts: 193
Joined: 15 Apr 2017, 05:13
Location: Riverside CA USA

Re: Tips for shortening rules

#12 Post by budman1758 » 02 Oct 2018, 22:14

grovkillen wrote:
02 Oct 2018, 21:37
Cool budman! Didn't know the rules engine could parse that many ifs.
To be honest I dd not try the above but in my keypad setup it does the 12 possibles that the keypad puts out. I would imagine that there is some upper limit but have no idea what it would be.
As a side note the speed problems I was having a log time ago are pretty much gone. Rules parsing speed is WAYYYYYYYY better than it was.
"The glass is twice as big as it needs to be".

Prutsium
Normal user
Posts: 31
Joined: 29 Mar 2018, 15:39
Location: Germany / Netherlands

Re: Tips for shortening rules

#13 Post by Prutsium » 02 Oct 2018, 22:51

budman1758 wrote:
02 Oct 2018, 20:47

Code: Select all

on rfid#tag do
if [rfid#tag]=1626454649  //joe blo
Event,goodtag
if [rfid#tag]=1626454648  //john doe
Event,goodtag
if [rfid#tag]=1626454647  // etc
Event,goodtag
if [rfid#tag]=1626454646  //etc
Event,goodtag
if [rfid#tag]=1626454645
Event,goodtag
if [rfid#tag]=1626454649
Event,goodtag
if [rfid#tag]=1626454648
Event,goodtag
if [rfid#tag]=1626454647
Event,goodtag
if [rfid#tag]=1626454646
Event,goodtag
if [rfid#tag]=1626454645
Event,goodtag
if [rfid#tag]=1626454649
Event,goodtag
if [rfid#tag]=1626454648
Event,goodtag
if [rfid#tag]=1626454647
Event,goodtag
if [rfid#tag]=1626454646
Event,goodtag
if [rfid#tag]=1626454645
Event,goodtag
if [rfid#tag]=1626454649
Event,goodtag
if [rfid#tag]=1626454648
Event,goodtag
if [rfid#tag]=1626454647
Event,goodtag
if [rfid#tag]=1626454646
Event,goodtag
if [rfid#tag]=1626454645
Event,goodtag
endif
endon

On goodtag do
Whatever you are doing...
endon
This takes less than 1 page of rules. I don't know if its "efficient" but it does work.
I use something similar in my keypad rules to determine what to do with the scan code output.
Hmmmm thats a nice one ... i lose only still a lot of date as i want to send to Domoticz who comes in so each line of your version would still have:
publish domoticz/in,{"idx":124,"nvalue":0,"svalue":"Name of Person"}
(If only dummy sensors could hold text then i could reduce about 50% of the text :) )

But .... it saves quite a bunch with your idea will try this later this week.

Thanks for the tip!

User avatar
budman1758
Normal user
Posts: 193
Joined: 15 Apr 2017, 05:13
Location: Riverside CA USA

Re: Tips for shortening rules

#14 Post by budman1758 » 03 Oct 2018, 01:41

Prutsium wrote:
02 Oct 2018, 22:51
budman1758 wrote:
02 Oct 2018, 20:47

Code: Select all

on rfid#tag do
if [rfid#tag]=1626454649  //joe blo
Event,goodtag
if [rfid#tag]=1626454648  //john doe
Event,goodtag
if [rfid#tag]=1626454647  // etc
Event,goodtag
if [rfid#tag]=1626454646  //etc
Event,goodtag
if [rfid#tag]=1626454645
Event,goodtag
if [rfid#tag]=1626454649
Event,goodtag
if [rfid#tag]=1626454648
Event,goodtag
if [rfid#tag]=1626454647
Event,goodtag
if [rfid#tag]=1626454646
Event,goodtag
if [rfid#tag]=1626454645
Event,goodtag
if [rfid#tag]=1626454649
Event,goodtag
if [rfid#tag]=1626454648
Event,goodtag
if [rfid#tag]=1626454647
Event,goodtag
if [rfid#tag]=1626454646
Event,goodtag
if [rfid#tag]=1626454645
Event,goodtag
if [rfid#tag]=1626454649
Event,goodtag
if [rfid#tag]=1626454648
Event,goodtag
if [rfid#tag]=1626454647
Event,goodtag
if [rfid#tag]=1626454646
Event,goodtag
if [rfid#tag]=1626454645
Event,goodtag
endif
endon

On goodtag do
Whatever you are doing...
endon
This takes less than 1 page of rules. I don't know if its "efficient" but it does work.
I use something similar in my keypad rules to determine what to do with the scan code output.
Hmmmm thats a nice one ... i lose only still a lot of date as i want to send to Domoticz who comes in so each line of your version would still have:
publish domoticz/in,{"idx":124,"nvalue":0,"svalue":"Name of Person"}
(If only dummy sensors could hold text then i could reduce about 50% of the text :) )

But .... it saves quite a bunch with your idea will try this later this week.

Thanks for the tip!
Write the tag number to a dummy value. Send the tag number to Domoticz and let Domoticz figure out who the tag belongs to. (maybe?)
"The glass is twice as big as it needs to be".

Prutsium
Normal user
Posts: 31
Joined: 29 Mar 2018, 15:39
Location: Germany / Netherlands

Re: Tips for shortening rules

#15 Post by Prutsium » 03 Oct 2018, 10:57

budman1758 wrote:
03 Oct 2018, 01:41
Prutsium wrote:
02 Oct 2018, 22:51
budman1758 wrote:
02 Oct 2018, 20:47

Code: Select all

on rfid#tag do
if [rfid#tag]=1626454649  //joe blo
Event,goodtag
if [rfid#tag]=1626454648  //john doe
Event,goodtag
if [rfid#tag]=1626454647  // etc
Event,goodtag
if [rfid#tag]=1626454646  //etc
Event,goodtag
if [rfid#tag]=1626454645
Event,goodtag
if [rfid#tag]=1626454649
Event,goodtag
if [rfid#tag]=1626454648
Event,goodtag
if [rfid#tag]=1626454647
Event,goodtag
if [rfid#tag]=1626454646
Event,goodtag
if [rfid#tag]=1626454645
Event,goodtag
if [rfid#tag]=1626454649
Event,goodtag
if [rfid#tag]=1626454648
Event,goodtag
if [rfid#tag]=1626454647
Event,goodtag
if [rfid#tag]=1626454646
Event,goodtag
if [rfid#tag]=1626454645
Event,goodtag
if [rfid#tag]=1626454649
Event,goodtag
if [rfid#tag]=1626454648
Event,goodtag
if [rfid#tag]=1626454647
Event,goodtag
if [rfid#tag]=1626454646
Event,goodtag
if [rfid#tag]=1626454645
Event,goodtag
endif
endon

On goodtag do
Whatever you are doing...
endon
This takes less than 1 page of rules. I don't know if its "efficient" but it does work.
I use something similar in my keypad rules to determine what to do with the scan code output.
Hmmmm thats a nice one ... i lose only still a lot of date as i want to send to Domoticz who comes in so each line of your version would still have:
publish domoticz/in,{"idx":124,"nvalue":0,"svalue":"Name of Person"}
(If only dummy sensors could hold text then i could reduce about 50% of the text :) )

But .... it saves quite a bunch with your idea will try this later this week.

Thanks for the tip!
Write the tag number to a dummy value. Send the tag number to Domoticz and let Domoticz figure out who the tag belongs to. (maybe?)
The part of Tag ID > Name is an idea yeah but makes it bit more tricky too.
Anyway with your idea i save already alot of space so thats gonna help.

Here is my version of it (short test version now still)

Code: Select all

On RFID#Tag do
if [RFID#Tag]=1899267376
publish domoticz/in,{"idx":124,"nvalue":0,"svalue":"Card 1"}
Event,OkTag

if [RFID#Tag]=82431090
publish domoticz/in,{"idx":124,"nvalue":0,"svalue":"Card 2"}
Event,OkTag
endon
endif

On OkTag do
gpio,13,0
gpio,14,1
timerSet,1,5
endon

On Rules#Timer=1 do 
gpio,13,1
gpio,14,0
endon
So if a tag is scanned it triggers OkTag and OkTag has timer to keep lock unlocked for 5 seconds and switches all off after that.

Again thanks for your help!

tozett
Normal user
Posts: 733
Joined: 22 Dec 2015, 15:46
Location: Germany

Re: Tips for shortening rules

#16 Post by tozett » 04 Oct 2018, 20:17

great ideas, to solve rfid-keyopen with rules.
did you ever thought of time-slots, on which some key is only valid?
i send tag-id to my gira-homeserver, wich checks if the key comes in on an allowed day.
and i check, if the key comes in at daytime (for parcel-delivery) and some key-groups are forbidden at night-time.
only some ideas for more rules...maybe..

Prutsium
Normal user
Posts: 31
Joined: 29 Mar 2018, 15:39
Location: Germany / Netherlands

Re: Tips for shortening rules

#17 Post by Prutsium » 08 Oct 2018, 09:29

tozett wrote:
04 Oct 2018, 20:17
great ideas, to solve rfid-keyopen with rules.
did you ever thought of time-slots, on which some key is only valid?
i send tag-id to my gira-homeserver, wich checks if the key comes in on an allowed day.
and i check, if the key comes in at daytime (for parcel-delivery) and some key-groups are forbidden at night-time.
only some ideas for more rules...maybe..
I did not implement timeslots or additional checks as this ESP must run without Internet connection (read: its mounted in a dead zone of my wifi)
When i get some coverage in that area (it's actually about 100m away from my own entry) i for sure want to work with additional checks but it creates also an extra point of failure.

Further within the rules i assume it would be possible to work with timeslots so this might also be an area to play with but i needed to compress my rules due the fact i had to add about 30 key;s and with my original rules it would have never fitted :)

Post Reply

Who is online

Users browsing this forum: Majestic-12 [Bot] and 1 guest