Page 1 of 1

Remote selector switch works with device but not with group

Posted: Sunday 01 September 2019 23:11
by gerbenvanasselt
I made a simple script for my aqara single button wall switch.

When I use it, Click and Double Click toggles my devices on and off.

When i do the Long Click nothing happens. And i get the error:

2019-09-01 22:55:30.983 Error: dzVents: Error: (2.4.26) An error occurred when calling event handler Dzvents SingleSw woonkamer
2019-09-01 22:55:30.983 Error: dzVents: Error: (2.4.26) ...dzVents/generated_scripts/Dzvents SingleSw woonkamer.lua:15: attempt to index local 'group' (a nil value)

Code: Select all

return {

   on = { 
       devices = {'Switch_Single'}      -- Name of your button
    },           
   execute = function(dz, item, device, group)
        if item.state == 'Click' then
            dz.devices('Plafondspot').toggleSwitch()    -- Name of your light
            dz.log(device.state, dz.LOG_INFO)
        elseif (item.state == 'Double Click') then
            dz.devices('Woonkamer_Lamp2').toggleSwitch()    -- Name of your light
            dz.log(device.state, dz.LOG_INFO)
        elseif  item.state == 'Long Click' then
            dz.groups('Alles_Uit').switchOff()    -- Name of your group
            dz.log(group.state, dz.LOG_INFO) 
            
        end
    end
}


When I put the 'Long Click'part in a single script it works with the same lines.

Code: Select all

return {

   on = { devices = { 'Switch_Single'}        -- Name of your button
    },           
   execute = function(dz, item, group)
        if item.state == 'Long Click' then
            dz.groups('Alles_Uit').switchOff()    -- Name of your group
            dz.log(group.state, dz.LOG_INFO)
        end
   end
}
What am I missing here?

Re: Remote selector switch works with device but not with group

Posted: Sunday 01 September 2019 23:35
by waaren
gerbenvanasselt wrote: Sunday 01 September 2019 23:11 I made a simple script for my aqara single button wall switch.

When I use it, Click and Double Click toggles my devices on and off.

When i do the Long Click nothing happens. And i get the error:

2019-09-01 22:55:30.983 Error: dzVents: Error: (2.4.26) An error occurred when calling event handler Dzvents SingleSw woonkamer
2019-09-01 22:55:30.983 Error: dzVents: Error: (2.4.26) ...dzVents/generated_scripts/Dzvents SingleSw woonkamer.lua:15: attempt to index local 'group' (a nil value)

Code: Select all

  execute = function(dz, item, device, group)

What am I missing here?
The execute function gets max. three parameters:
1. domoticz: The domoticz object. This object gives you access to almost everything in your Domoticz system, including all methods to manipulate them
2. item: Depending on what actually triggered the script, item is either a: device, variable, scene, group, timer, security or httpResponse
3. info: holds information about what triggered the script. The object has 3 attributes: Type, trigger and scriptName

These 3 parms can have different names (like dz for domoticz) but that does not change what is passed using these parms.

So your execute = function(dz, item, device, group)
gets
domoticz object in dz,
the "switch single" device in item,
info in device
and nil in group

You probably want something like:

Code: Select all

return {

   on = { 
       devices = {'Switch_Single'}      -- Name of your button
    },           
   execute = function(dz, item)
        dz.log(item.name .. 'is' .. item.state, dz.LOG_INFO)

        if item.state == 'Click' then
            dz.devices('Plafondspot').toggleSwitch()    -- Name of your light
            dz.log('Plafondspot was ' .. dz.devices('Plafondspot').state .. ' before toggling', dz.LOG_INFO)

		elseif (item.state == 'Double Click') then
            dz.devices('Woonkamer_Lamp2').toggleSwitch()    -- Name of your light
			dz.log('Woonkamer_Lamp2 ' .. dz.devices('Woonkamer_Lamp2').state .. ' before toggling', dz.LOG_INFO)

        elseif  item.state == 'Long Click' then
            dz.groups('Alles_Uit').switchOff()    -- Name of your group
			dz.log('group Alles_uit has been switched Off', dz.LOG_INFO)

        end
    end
}