Control of a set of switches By special use of one switch

Hi, everyone
Pretty beginner
But I’ve been running the software for half a year
I wanted to know if there is a possibility to create RULE
That
When I switch on and off a switch at a specified time twice then the other switches will be turned off or on
I have OPENHAB2 on RASPBERRY 3
And a large amount of SONOFF switches
Google translation…
Sorry…

Create a proxy (dummy switch) item and use a rule to trigger the devices on/off. I also have a few sonoff’s and use proxy items to control multiple devices.

Short example

rule "Proxy Switch"
when
	Item Proxy_Switch received command OFF
then
	Sonoff1.sendCommand(OFF)
        Sonoff2.sendCommand(OFF)
        Sonoff3.sendCommand(OFF)
end

What to mean by that? Could you give an example?

Well, what do you mean by “a specific time”? given items:

Switch MyTriggerSwitch "Trigger" ...

Switch MyRegularSwitch1 "Light 1" ...
Switch MyRegularSwitch2 "Light 2" ...
Switch MyRegularSwitch3 "Light 3" ...

Rule:

var Timer myTimer = null
val Number startHour = 8
val Number startMinute = 30
val Number stopHour = 14
val Number stopMinute = 45

rule "trigger"
when
    Item MyTriggerSwitch received command
then
    if(now.getMinuteOfDay >= (startHour * 60 + startMinute) && now.getMinuteOfDay < (stopHour * 60 + stopMinute)) {
        if(myTimer === null) {
            myTimer = createTimer(now.plusMillis(500), [
                myTimer = null
            ])
        } else {
            MyRegularSwitch1.sendCommand(if(MyRegularSwitch1.state != ON) ON else OFF)
            MyRegularSwitch2.sendCommand(if(MyRegularSwitch2.state != ON) ON else OFF)
            MyRegularSwitch3.sendCommand(if(MyRegularSwitch3.state != ON) ON else OFF)
        }
    }
end
1 Like

if I
Turn on
And turn off
Turn on
And turn off
Within five seconds
Command will exit

I do not care if it is defined as turning on or off
I mean if I press the button 4 times
Command will exit
think about it
This allows you to control several devices through one switch
Turn on the light with one click and the fan in two clicks

You could do something like trigger a rule from switch OFF.
Rule checks if a timer is running - if not, starts it running and exits.
But if the timer IS running, this is the second OFF - so now do whatever is needed.
The timer can just null itself if it gets to completion.

Just inform
I’m just using the RULE ENGINE
So I need examples

So the specific time is the time you need to push the button 4 times… even easier :slight_smile:

var Timer myTimer = null
var Number myCounter = 0

rule "trigger"
when
   Item MyTriggerSwitch received command
then
   if(myTimer === null) {                             // no timer started, so startup timer
       myTimer = createTimer(now.plusMillis(5000), [  // timeout is 5 Seconds
           myTimer = null                             // when timer expired, reset timer
           myCounter = 0                              // and counter
       ])
   }
   myCounter += 1                                     // each time a command is received, count up
   if(myCounter == 4) {                               // rule was triggered 4 times within 5 Seconds
       MyRegularSwitch1.sendCommand(if(MyRegularSwitch1.state != ON) ON else OFF)  // toggle Switch
       MyRegularSwitch2.sendCommand(if(MyRegularSwitch2.state != ON) ON else OFF)  // toggle Switch
       MyRegularSwitch3.sendCommand(if(MyRegularSwitch3.state != ON) ON else OFF)  // toggle Switch
   }
end

Maybe toggling switches is not the goal, but then you have to decide which switch should be the “Master” (i.e. which switch state should be used to toggle)

EDIT: some additional information…

2 Likes

The “RULE ENGINE” is an experimental rule engine and you will not be able to achieve this level of complicated rule and logic with it. You will need to write a rule in a text file. The one that @Udo_Hartmann just posted above is brilliant!!. I would really have struggled to come up with that and it is so simple in the end!! Nice rule!!

now.plusMillis?

of course
I realized that this can not be done with a rule engine
I just stressed that I was not so experienced with writing rules
So only if you can explain to me what parts I am supposed to change in the code
And again
I have a switch that turns on a light and I want to turn it into a trigger for more lights if I press it 4 times
And yet I want him to continue to do his work, which is the lighting of the particular light

now plus 5000 milliseconds (Or in 5 seconds time from now)
Equivalent to now.plusSeconds(5)

The code that @Udo_Hartmann provided is very good and should give you a head start.
Copy it. Don’t copy and paste. Copy it, understand it. You will be able to build from that

Actually, I think a better way to say it is that we don’t know how to achieve this level of complicated Rule with it yet. I actually think it is mature enough as is to handle a Rule like this. I just couldn’t tell you how to do it.

Indeed :+1:

The only change I would make is to put the Switches in a Group and forEach over the Group.

1 Like