Achieve Device side queuing

17 views
Skip to first unread message

Saurabh Patil

unread,
Apr 30, 2024, 7:55:46 AMApr 30
to TasmotaUsers
Hi Users,
I am using SonOff 4ch with Tasmota 12.4.0.
I wanted to achieve the queuing explained below:
Command1 turn the Channel1 ON 
Command2 tries to turn the same channel1 ON, but as it is already in use then it should hold and wait till Channel1 becomes OFF.
Once Channel1 becomes OFF then it will pick the command2 from the device queue and then turn channel1 ON again after delay.
I want to store/queue only one command at a time.
Here two things can be helpful.
1. How to check if channel 1 is in use? 
2. If the channel1 is in use then how to put the second command(turn channel1 ON) in queue?
3. Channel 1 should turn on with a specified delay.
I have tried to use the rules but it is not helping much.
Thanks in advance.


Justin Adie

unread,
Apr 30, 2024, 9:19:32 AMApr 30
to Saurabh Patil, SonoffUsers
Rules should work for this use case.  Something like this might do

Rule1 
on system#boot do backlog0 power1 0; var1 0; var 2 0; var3 0; var4 0 endon
on system#boot do var5 <<PUT WAIT TIME IN SECONDS HERE>> endon
on event#cmnd1=1 do backlog var1 1; event test endon
on event#cmnd2=1 do backlog var2 2; event test endon
on event#cmnd2=0 do var2 0 endon
on event#cmnd1=0 do event test endon
on power1#state=0 do event test endon
on event#test do backlog0 var4 %var2%; add4 %var1%; var3 %var4% endon
on var3#state=0 do backlog0 power1 0; var1 0; var2 0; endon
on var3#state=1 do power1 1 endon
on var3#state=2 do backlog0 power1 1; var2 0 endon
on var3#state=3 do backlog0 wait %var5%; power1 1; var2 1; var1 0 endon


rule1 1


------------------------------------------------------------------------------
CONFIDENTIALITY:  This e-mail (including any attachments) may contain confidential, proprietary, and privileged information, and unauthorized disclosure or use is prohibited.  If you received this e-mail in error, please notify the sender and delete this e-mail from your system.


--
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/17a9260b-92ed-47e5-ae6f-0481b69a0931n%40googlegroups.com.

Philip Knowles

unread,
Apr 30, 2024, 9:21:33 AMApr 30
to Saurabh Patil, Justin Adie, SonoffUsers
You beat me to it. I was going to suggest a dummy relay to store the request...

From: 'Justin Adie' via TasmotaUsers <sonof...@googlegroups.com>
Sent: 30 April 2024 14:19
To: Saurabh Patil <sau...@codebase.com>
Cc: SonoffUsers <sonof...@googlegroups.com>
Subject: Re: Achieve Device side queuing
 

Philip Knowles

unread,
May 1, 2024, 4:55:01 AMMay 1
to Saurabh Patil, Justin Adie, SonoffUsers
I've not had time to think it through fully but the way I was thinking was to have a dummy relay which you send the 'request' to.
on power1#state do var1 %value% endon //set var1 to relay1 state
on power2#state do var2 %value% endon //set var2 to relay2 state
on power2#state>%var1% do backlog power1 1; power2 0 endon //if relay2 has turned ON and relay1 OFF then turn relay1 ON and turn relay2 OFF else relay2 stays ON (queued)
on power1#state=OFF do backlog wait <delay>; power1 %var2%; power2 0 endon //when relay1 switches OFF then wait and then make relay1 equal to what's stored in relay2 state

Not checked but I think it's right. You can also see the state of the 'queue' in the UI.

From: Saurabh Patil <sau...@codebase.com>
Sent: 30 April 2024 14:57
To: Philip Knowles <knowles...@gmail.com>
Cc: Justin Adie <justi...@adieandco.com>; SonoffUsers <sonof...@googlegroups.com>

Subject: Re: Achieve Device side queuing
 
Thanks Justin, I set the above rule, but It didn't work while I ingest 2 requests at a time.
Please find the below details of how this worked and What I wanted to achieve.
My pulse time is 180 for each request.
I am sending the Power1 ON command through MQTT.
If there is standalone request to run channel1 ON then Channel1 is on for 1.20mins
If the channel1 is on and then I inject another request to turn channel1 ON then it is not waiting to finish the first request but add additional time for channel1 to become ON.
If I send two consecutive request for power on then first request should turn the channel1 on and second request should wait for channel1 to turn off and then start the channel1 again from second request.

Request1 - Power1 Channel1 ON
Request2 - Check if Channel1 is ON -> then wait till Channel1 gets off-> Delay -> turn channel 1 ON

If the rules do not work then Can I check in anyway if the channel is busy?

--
Thanks and Regards,

Email sender photo
Saurabh Patil
Senior Software Developer
+919421613328
codebase.com

Justin Adie

unread,
May 1, 2024, 5:03:16 AMMay 1
to Saurabh Patil, Philip Knowles, SonoffUsers
Apologies for not replying sooner.  Bypassing the rules by using power1 1 directly won't work with the rules.   You asked for a solution that worked with command1 and command2.  So the rules work when you issue an event cmnd1 and event cmnd2 either via mosquitto or the terminal. 



On Tue, 30 Apr 2024, 15:57 Saurabh Patil, <sau...@codebase.com> wrote:
Thanks Justin, I set the above rule, but It didn't work while I ingest 2 requests at a time.
Please find the below details of how this worked and What I wanted to achieve.
My pulse time is 180 for each request.
I am sending the Power1 ON command through MQTT.
If there is standalone request to run channel1 ON then Channel1 is on for 1.20mins
If the channel1 is on and then I inject another request to turn channel1 ON then it is not waiting to finish the first request but add additional time for channel1 to become ON.
If I send two consecutive request for power on then first request should turn the channel1 on and second request should wait for channel1 to turn off and then start the channel1 again from second request.

Request1 - Power1 Channel1 ON
Request2 - Check if Channel1 is ON -> then wait till Channel1 gets off-> Delay -> turn channel 1 ON

If the rules do not work then Can I check in anyway if the channel is busy?


On Tue, Apr 30, 2024 at 6:51 PM Philip Knowles <knowles...@gmail.com> wrote:
--
Thanks and Regards,

Email sender photo
Saurabh Patil
Senior Software Developer
+919421613328
codebase.com

Reply all
Reply to author
Forward
0 new messages