Page 1 of 1
Multiply on/off switch change
Posted: Thursday 03 May 2018 13:40
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¶m=switchlight&idx=1&switchcmd=On&idx=2&switchcmd=Off&idx=3&switchcmd=Off&idx=4&switchcmd=On
How can I do that?
Pawel
Re: Multiply on/off switch change
Posted: Thursday 03 May 2018 18:05
by SweetPants
Put your json commands in a script using curl and fire the script? You can only switch one per command
Re: Multiply on/off switch change
Posted: Thursday 03 May 2018 19:45
by waaren
Or put the switches in a group and use a json to switch the group
Re: Multiply on/off switch change
Posted: Thursday 03 May 2018 19:57
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
Re: Multiply on/off switch change
Posted: Thursday 03 May 2018 20:01
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
Re: Multiply on/off switch change
Posted: Thursday 03 May 2018 20:34
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
Re: Multiply on/off switch change
Posted: Thursday 03 May 2018 20:53
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
Re: Multiply on/off switch change
Posted: Thursday 03 May 2018 21:24
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
}
Re: Multiply on/off switch change
Posted: Sunday 06 May 2018 14:24
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
Re: Multiply on/off switch change
Posted: Sunday 06 May 2018 14:51
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