Push button switch with multiple pushed combinations providing multiple commands

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
iz8mbw
Normal user
Posts: 35
Joined: 14 Apr 2023, 08:43
Location: Napoli, Italy

Push button switch with multiple pushed combinations providing multiple commands

#1 Post by iz8mbw » 11 Sep 2023, 14:19

Hello.
I'm using a push button switch connected to ESPEasy in order to send HTTP commands with two combinations, in my case now I have:
1. push button switch -> close rolling shutter.
2. push (again) button switch -> open rolling shutter

and this combinations is in loop (1,2 1,2 1,2....).


This is the Rule:

Code: Select all

On System#Boot do
  TimerSet,1,3 //set timer #1 to 3 seconds
Endon

On Rules#Timer=1 Do
  Let,1,1 //set variable 1 to 1 after the 3 seconds of the timer
Endon

On Sw#State Do //on push button press
  If %eventvalue%=0 And [var#1]=1
    SendToHTTP 192.168.1.12,80,/roller/0?go=close //command to close rolling shutter as example
   Endif
  If %eventvalue%=1 And [var#1]=1
  SendToHTTP 192.168.1.12,80,/roller/0?go=open  //command to open rolling shutter as example
    Endif
 Endon
What now I would like to have is multiple combinations (so multiple commands) on every push, example with 4 combinations:

1. push button switch -> close rolling shutter
2. push (again) button switch -> stop closing rolling shutter
3. push (again) button switch -> open rolling shutter
4. push (again) button switch -> stop opening rolling shutter

and this combinations (of 4 push) in loop, so after arriving to combination 4 next is to return to combination 1 (1,2,3,4 1,2,3,4 1,2,3,4...).

Is it possible?

Thanks.

User avatar
chromo23
Normal user
Posts: 827
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Push button switch with multiple pushed combinations providing multiple commands

#2 Post by chromo23 » 12 Sep 2023, 14:59

iz8mbw wrote: 11 Sep 2023, 14:19 Is it possible?
There are many ways to accomplish that.
For example:

Code: Select all


On System#Boot do
  TimerSet,1,3 //set timer #1 to 3 seconds
Endon

On Rules#Timer=1 Do
  Let,1,1 //set variable 1 to 1 after the 3 seconds of the timer
Endon

On Sw#State Do //on push button press
  If %eventvalue%=1 And [var#1]=1
    If [var#2] < 4
      Let,2,[var#2]+1
    Else 
      Let,2,1
    Endif
    If [var#2] = 1
      SendToHTTP 192.168.1.12,80,/roller/0?go=close //command to close rolling shutter as example
    Elseif [var#2] = 2
      //command to stop rolling shutter as example
    Elseif [var#2] = 3
      //command to open
    Elseif [var#2] = 4
      // command to stop
    Endif
  Endif
 Endon
Untested and written on my mobile phone so there might be mistakes…

iz8mbw
Normal user
Posts: 35
Joined: 14 Apr 2023, 08:43
Location: Napoli, Italy

Re: Push button switch with multiple pushed combinations providing multiple commands

#3 Post by iz8mbw » 15 Sep 2023, 21:25

Hello and thanks @chromo23.

I have tried the code but it works like as expected only every two push, so:
push 1 -> nothing
push 2 -> command 1
push 3 -> nothing
push 4 -> command 2
push 5 -> nothing
push 6 -> command 3
push 7 -> nothing
push 8 -> command 4

so I have modified the Rule removing the

Code: Select all

If %eventvalue%=1
and it works.
This is the code:

Code: Select all

On System#Boot do
  TimerSet,1,3 //set timer #1 to 3 seconds
Endon

On Rules#Timer=1 Do
  Let,1,1 //set variable 1 to 1 after the 3 seconds of the timer
Endon

On Sw#State Do //on push button press
  If  [var#1]=1
    If [var#2] < 4
      Let,2,[var#2]+1
    Else 
      Let,2,1
    Endif
    If [var#2] = 1
      SendToHTTP 192.168.1.12,80,/roller/0?go=close //command to close rolling shutter as example
    Elseif [var#2] = 2
      //command to stop rolling shutter as example
    Elseif [var#2] = 3
      //command to open
    Elseif [var#2] = 4
      // command to stop
    Endif
  Endif
 Endon
Still thanks for your support!

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests