Remote selector switch works with device but not with group

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
gerbenvanasselt
Posts: 74
Joined: Friday 07 September 2018 14:46
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta 4.1
Location: Netherlands
Contact:

Remote selector switch works with device but not with group

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

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

Post 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
}
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: No registered users and 1 guest