Problem toggle switch  [SOLVED]

Moderator: leecollings

Post Reply
Damealas
Posts: 6
Joined: Thursday 10 May 2018 14:35
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Problem toggle switch

Post 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
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Problem toggle switch

Post 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
}

Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Damealas
Posts: 6
Joined: Thursday 10 May 2018 14:35
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Problem toggle switch

Post 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
User avatar
boum
Posts: 130
Joined: Friday 18 January 2019 11:31
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: France
Contact:

Re: Problem toggle switch

Post 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
}
Damealas
Posts: 6
Joined: Thursday 10 May 2018 14:35
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Problem toggle switch

Post 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
Damealas
Posts: 6
Joined: Thursday 10 May 2018 14:35
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Problem toggle switch  [SOLVED]

Post 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
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest