Multiply on/off switch change

Moderator: leecollings

Post Reply
optiserw
Posts: 10
Joined: Thursday 03 May 2018 13:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Multiply on/off switch change

Post by optiserw »

Hi,

I have a few switches in my system.
I want to change the status of the switches at the same time using one API command.

I am thinking about somenthing like that:

Code: Select all

/json.htm?type=command&param=switchlight&idx=1&switchcmd=On&idx=2&switchcmd=Off&idx=3&switchcmd=Off&idx=4&switchcmd=On
How can I do that?

Pawel
SweetPants

Re: Multiply on/off switch change

Post by SweetPants »

Put your json commands in a script using curl and fire the script? You can only switch one per command
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Multiply on/off switch change

Post by waaren »

Or put the switches in a group and use a json to switch the group
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
optiserw
Posts: 10
Joined: Thursday 03 May 2018 13:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Multiply on/off switch change

Post by optiserw »

SweetPants wrote: Thursday 03 May 2018 18:05 Put your json commands in a script using curl and fire the script? You can only switch one per command
If I put about 20 singular commands into the script, it will be executed for a long time (>20 seconds).
If I need to use 100 switches, it will be more than 1 minute!

This way isn't right, I think.

Pawel
optiserw
Posts: 10
Joined: Thursday 03 May 2018 13:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Multiply on/off switch change

Post by optiserw »

waaren wrote: Thursday 03 May 2018 19:45 Or put the switches in a group and use a json to switch the group
The state of all the group members must be the same!
In my case, the states of switches are different - not equal.

This solution isn't good.

Pawel
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Multiply on/off switch change

Post by waaren »

Other options:

use a scene -- Also delays when you have many switches
use a script -- Also delays when you have many switches

the delays are not so much in domoticz as in the hardware. For virtual switches the delay is negligible
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
optiserw
Posts: 10
Joined: Thursday 03 May 2018 13:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Multiply on/off switch change

Post by optiserw »

waaren wrote: Thursday 03 May 2018 20:34 For virtual switches the delay is negligible
Could you show me the example code for that?
Language - whatever
idx 01-100

1 pff
2 on
3 off
4 off

state random

Best regards
Pawel
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Multiply on/off switch change

Post by waaren »

code in dzVents: ( find many other examples here )

Code: Select all

--[[
Switch sequence of devices
 ]]

 return {

   on = { devices = { "Your trigger device" }           },
      
   execute = function(dz, trigger )
     
        if trigger.state ~= "Off" then 
            dz.devices(1).switchOff() 
            dz.devices(2).switchOn() 
            dz.devices(3).switchOff()
            dz.devices(100).switchOff()
        else
            dz.devices(1).switchOn() 
            dz.devices(2).switchOn() 
            dz.devices(3).switchOff()
            dz.devices(100).switchOff()
         end
   end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
optiserw
Posts: 10
Joined: Thursday 03 May 2018 13:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Multiply on/off switch change

Post by optiserw »

waaren wrote: Thursday 03 May 2018 21:24 code in dzVents: ( find many other examples here )

Code: Select all

--[[
Switch sequence of devices
 ]]

 return {

   on = { devices = { "Your trigger device" }           },
      
   execute = function(dz, trigger )
     
        if trigger.state ~= "Off" then 
            dz.devices(1).switchOff() 
            dz.devices(2).switchOn() 
            dz.devices(3).switchOff()
            dz.devices(100).switchOff()
        else
            dz.devices(1).switchOn() 
            dz.devices(2).switchOn() 
            dz.devices(3).switchOff()
            dz.devices(100).switchOff()
         end
   end
}


Thank you for your suggestion.

Is it possible with python?
I have some code in python and if it can be done with it I will be grateful.

Pawel
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Multiply on/off switch change

Post by waaren »

I'm sure it can. There is a Python subforum on this board. If you post your question there it might be answered by someone skilled enough in Python
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest