Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question about Rules (or feature request) #2475

Closed
krasatos opened this issue Apr 18, 2018 · 13 comments
Closed

Question about Rules (or feature request) #2475

krasatos opened this issue Apr 18, 2018 · 13 comments
Labels
stale Action - Issue left behind - Used by the BOT to call for attention

Comments

@krasatos
Copy link

Hey there,
I have just started messing with the new feature implemented: Rules.
I must say that it give me great comfort to know that some stuff are done right on the sonoff and dont depend on mqtt or other connection. This makes me able to place safeguards in order to rest assured that i wont have any problematic behavior when else something disconnects or goes wrong (ie. have my irrigation run all night).

To my question:
I have been placing safeguards for all relays (5 of them) to turn off at several points, example:
rules on System#Boot do backlog power1 off;power2 off;power3 off;power4 off;power5 off endon on Mqtt#Disconnected do backlog power1 off;power2 off;power3 off;power4 off;power5 off endon

(might have some typos, im outside and remembering the code by heart )
I also understand that there is a maximum amount of rules due to memory restrictions.

  1. Is there some way to refactor the code in order to replace the backlog power1 off;power2 off;power3 off;power4 off;power5 off with something like powerALL off or would that be possible anytime soon?

  2. Another behavior i want to implemet is for all the other relays to turn off (like above) when any relay toggles PowerX#State. So i guess ill have to do it 5 times, when 1 toggle, 2,3,4,5 off - when 2 toggle 1,3,4,5 off and so on. Is there some clever way to shorten this command?

I know the rules implementation is still fresh and experimental, but im guessing a way to contribute to it is talking about it and requesting features :)

Thanks again for this wonderful firmware.
K.

@arendst
Copy link
Owner

arendst commented Apr 18, 2018

Well the first rule on System#Boot can easily be solved by changing PowerOnState from 3 to 0 setting all outputs off after power on.

The second one is a nice rule wanting solution ;-)

@localhost61
Copy link
Contributor

localhost61 commented Apr 18, 2018

For item 2, isn't it the result of the command: SetOption14 1 // global interlock

@localhost61
Copy link
Contributor

localhost61 commented Apr 19, 2018

I just wish to add my 2 cents...
Here is a rule I entered in the console of my Dual R2 used to command a window roller shutter ( build 5.12.0m) :
CMD: rule
RSL: RESULT = {"Rule":"OFF","Once":"OFF","Rules":""} //oups I forgot to enable rules in user_config.h
CMD: rule 1
RSL: RESULT = {"Rule":"ON","Once":"OFF","Rules":""}
CMD: rule on Clock#Timer=2 do backlog power2 1;delay 220;power2 0;delay 4;power1 1;delay 1;power1 0 endon
RSL: RESULT = {"Rule":"ON","Once":"OFF","Rules":"rule on Clock#Timer=2 do backlog power2 1;delay 220;power2 0;delay 4;power1 1;delay 1;power1 0 endon"}

Explanation:
20" is the time it takes to fully open the shutter (Relay2), once up, I rotate the motor backward (Relay1) in order to release the tension because in summer, when it's hot, the rubber joins of the guide rails become very soft and stick to the end slat, when in forced position. At night, when one want to shut them down, they are often locked and one have to turn the motor back and forth to unlock it. It's the reason why, last night I could see on the web console that the sunset timer triggered and the commands occurred, but the shutter was still open. :-[
I'll see next evening if this workaround does the trick.

sonoff_5 12 0m - configuration timer

[Edith] Edited the rule: "delay 220" for 20s and "delay 1" for 100ms is enough to release the tension on the slats. [/Edith]

@arendst
Copy link
Owner

arendst commented Apr 19, 2018

Rules#timer is not timer2!

Rules#timer is a countdown timer useable by rules only.
In your case you should trigger on Clock#timer=2

@krasatos
Copy link
Author

krasatos commented Apr 19, 2018

"Well the first rule on System#Boot can easily be solved by changing PowerOnState from 3 to 0 setting all outputs off after power on." @arendst

Unfortunately, due to my (probably ill-configured) HA based mosquito broker, poweronstate does not work for me, so on Mqtt#Connected do gives me a peace of mind :).
Just want to minimize my code characters.

@localhost61 Great input, i want to set up my garage door to open/close, so my application will be similar. Also the interlocking tip did it for me on this project, Thanks

@krasatos
Copy link
Author

krasatos commented Apr 19, 2018

Got another question, just posting here not to open another issue:

Connected a magnetic contact switch as switch4.
Gave it a switchtopic as if i leave it 0 it will fire my relay1 whenever triggered.

Trying to have it turn off all my relays when activated (as it will be the end sensor on my sliding garage door)
entered this rule on Switch4#State do backlog power1 off;power2 off endon
I am getting the activation message on console:

13:12:48 MQT: cmnd/sonoff_garage1_magnet/POWER4 = ON
13:12:48 MQT: cmnd/sonoff_garage1_magnet/POWER4 = OFF

But i cant get it to turn off the relays.
What am i missing?
Also, would a trigger syntax like on Switch4#State=ON be correct?

edit: with on switch4#State do backlog power1 off;power2 off endon and switchtopic 0, it works fine but then i cant broadcast the switch to the broker

edit2: could not find a workaround to have switchtopic on and have the switch obay the rules, so i turned it of and created a rule for it to broadcast on change on switch4#State do publish cmnd/sonoff_garage1_magnet/power4 %value% endon

@localhost61
Copy link
Contributor

localhost61 commented Apr 19, 2018

@arendst, thanks for the input. It's surely the reason why the timer2 didn't trigger this morning on sunrise event ;-).
Just for my understanding, isn't it weird that when applying a rule to a timer, like in my previous screenshot, the Output field has to be defined when it's not necessary involved in the rule (In my case both outputs are used)?
@krasatos for my Dual R2 I have also setup Pulstime to 120 for both outputs in order to limit the ON state to 20s, but in your case, if the door is blocked by an obstacle, it will never trigger your swith4.
Can't help much with rules syntax, I'm discovering too ;-).
@krasatos , PowerOnState can be setup using webserver console, if you didn't optout the webserver in user_config.h

@krasatos
Copy link
Author

@localhost61
Regarding poweronstate i have repeatedly set it up they return to previous state on boot, perhaps since my HA keeps the relays on irregardless of the tasmota's restart, they will read that and turn on upon boot.
Regarding pulsetime, i am planning to set it up too, just need the magnetic switch to be there as a backup. I plan on stopping the door by timer about 1 cm before it reaches the magnetic switch. Just need some help to point me to the correct syntax i think.

@arendst
Copy link
Owner

arendst commented Apr 20, 2018

@localhost61 regarding the Output field when Rule is selected: It would need another enable/disable of a HTML item leading to more code while it's just a cosmetic problem.

It would be great if everyone could just use the command line options and get rid of the webserver freeing about 60k for more useful options...

@localhost61
Copy link
Contributor

localhost61 commented Apr 21, 2018

Yes the CLI is really powerful, but it's a step ahead from the GUI in the learning curve.

I wonder why Timer Json is not logged in the console when altered by the GUI, that would make sense for debugging. (thinking at recent #2447 and #2461 )

@roblad
Copy link

roblad commented Apr 23, 2018

Hi,

Is it possible to add rule on Serialreceived or SSerialreceived with the received serial %value% for usage as in example Rule

on button1#state do publish cmnd/ring2/power %value% endon on button2#state do publish cmnd/strip1/power %value% endon ?

Maybe I do not know haw the Event#Anyname when command Event Anyname is executed works, maybe there is already prepared.

@stale
Copy link

stale bot commented Jun 10, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale Action - Issue left behind - Used by the BOT to call for attention label Jun 10, 2018
@stale
Copy link

stale bot commented Jun 25, 2018

This issue will be auto-closed because there hasn't been any activity for a few months. Feel free to open a new one if you still experience this problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Action - Issue left behind - Used by the BOT to call for attention
Projects
None yet
Development

No branches or pull requests

4 participants