Page 1 of 1
Problem toggle switch
Posted: Wednesday 08 April 2020 9:09
by Damealas
Hi, I'm trying to make a toggle switch, I have a switch with a light and another switch, I want the two switches to turn on the light, but I can't, I've tried a lot of things and it drives me crazy
Code: Select all
return {
on = {
devices = {
98, 48
}
},
execute = function (domoticz, device)
local L1 = domoticz.devices (98)
local L2 = domoticz.devices (48)
if (L1.state == 'Click' or L2.state == 'Click') then
L1.toggleSwitch ()
L2.toggleSwitch ()
end
end
}
Thank you very much in advance
Re: Problem toggle switch
Posted: Wednesday 08 April 2020 9:41
by waaren
Damealas wrote: ↑Wednesday 08 April 2020 9:09
Hi, I'm trying to make a toggle switch, I have a switch with a light and another switch, I want the two switches to turn on the light, but I can't, I've tried a lot of things and it drives me crazy
First please explain what device 48 and device 98 are. Which one is the switch and which is the light ?
Then add some logging to the script so you can see in the logfile what happens (see below)
if L1 and L2 are Xiaomi selector switches the toggle won't work. Domoticz would not know where to toggle to from 'click'
Code: Select all
return
{
on =
{
devices =
{
98, 48,
},
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = 'Toggle',
},
execute = function (domoticz, device)
local L1 = domoticz.devices(98)
local L2 = domoticz.devices(48)
domoticz.log('state of L1 ' .. L1.state, domoticz.LOG_DEBUG )
domoticz.log('state of L2 ' .. L2.state, domoticz.LOG_DEBUG )
if L1.state == 'Click' or L2.state == 'Click' then
L1.toggleSwitch ().silent()
L2.toggleSwitch ().silent()
end
end
}
Re: Problem toggle switch
Posted: Wednesday 08 April 2020 10:04
by Damealas
They are both Light / Switch Switch, the light is in 98
2020-04-08 10:03:00.067 Status: User: Admin initiated a switch command (48/Presencia Carlos/On)
2020-04-08 10:03:00.212 Status: dzVents: Info: Toggle: ------ Start internal script: Script #3: Device: "Presencia Carlos (Presencia)", Index: 48
2020-04-08 10:03:00.213 Status: dzVents: Debug: Toggle: Processing device-adapter for Banda ancha: Switch device adapter
2020-04-08 10:03:00.213 Status: dzVents: Debug: Toggle: state of L1 Off
2020-04-08 10:03:00.213 Status: dzVents: Debug: Toggle: state of L2 On
2020-04-08 10:03:00.213 Status: dzVents: Info: Toggle: ------ Finished Script #3
Re: Problem toggle switch
Posted: Wednesday 08 April 2020 10:58
by boum
Then you should probably try:
Code: Select all
return
{
on =
{
devices =
{
98, 48,
},
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = 'Toggle',
},
execute = function (domoticz, device)
local L1 = domoticz.devices(98)
local L2 = domoticz.devices(48)
domoticz.log('state of L1 ' .. L1.state, domoticz.LOG_DEBUG )
domoticz.log('state of L2 ' .. L2.state, domoticz.LOG_DEBUG )
if device.active then
L1.switchOn().checkFirst().silent()
L2.switchOn().checkFirst().silent()
else
L1.switchOff().checkFirst().silent()
L2.switchOff().checkFirst().silent()
end
end
}
Re: Problem toggle switch
Posted: Wednesday 08 April 2020 11:30
by Damealas
no, it's what happens to me, it loops on off
2020-04-08 11:29:06.672 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2020-04-08 11:29:07.294 (Presencia) Light/Switch (Switch/bombilla)
2020-04-08 11:29:07.665 (Presencia) Light/Switch (Switch/Conmutado)
2020-04-08 11:29:07.288 Status: User: Admin initiated a switch command (98/Switch/bombilla/Toggle)
2020-04-08 11:29:07.427 Status: dzVents: Info: Toggle: ------ Start internal script: Script #5: Device: "Switch/bombilla (Presencia)", Index: 98
2020-04-08 11:29:07.428 Status: dzVents: Debug: Toggle: Processing device-adapter for Switch/Conmutado: Switch device adapter
2020-04-08 11:29:07.428 Status: dzVents: Debug: Toggle: state of L1 On
2020-04-08 11:29:07.428 Status: dzVents: Debug: Toggle: state of L2 Off
2020-04-08 11:29:07.428 Status: dzVents: Debug: Toggle: Constructed timed-command: On
2020-04-08 11:29:07.429 Status: dzVents: Debug: Toggle: Constructed timed-command: On
2020-04-08 11:29:07.429 Status: dzVents: Debug: Toggle: Constructed timed-command: On
2020-04-08 11:29:07.429 Status: dzVents: Debug: Toggle: Constructed timed-command: On NOTRIGGER
2020-04-08 11:29:07.429 Status: dzVents: Info: Toggle: ------ Finished Script #5
Re: Problem toggle switch [SOLVED]
Posted: Wednesday 08 April 2020 11:33
by Damealas
boum wrote: ↑Wednesday 08 April 2020 10:58
Then you should probably try:
- Spoiler: show
Code: Select all
return
{
on =
{
devices =
{
98, 48,
},
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = 'Toggle',
},
execute = function (domoticz, device)
local L1 = domoticz.devices(98)
local L2 = domoticz.devices(48)
domoticz.log('state of L1 ' .. L1.state, domoticz.LOG_DEBUG )
domoticz.log('state of L2 ' .. L2.state, domoticz.LOG_DEBUG )
if device.active then
L1.switchOn().checkFirst().silent()
L2.switchOn().checkFirst().silent()
else
L1.switchOff().checkFirst().silent()
L2.switchOff().checkFirst().silent()
end
end
}
It seems to work excuse me, but with so many tests .....
Thank you very much, I appreciate the help