Broke my script
Posted: Friday 19 July 2019 17:35
Hello,
I have been working on a script to control my devices with a IKEA trådfri remote.
I can't see where I'm doing wrong, I get different result each time I trigger the script.
Group 7 works just fin,
But group 6 fail.
Group 1 looks strange as well as it loops the control table and not the nested table.
Logs
error
I have been working on a script to control my devices with a IKEA trådfri remote.
I can't see where I'm doing wrong, I get different result each time I trigger the script.
Group 7 works just fin,
But group 6 fail.
Group 1 looks strange as well as it loops the control table and not the nested table.
Code: Select all
--
-- Creater Varazir ( And big help from waaren and others on domotiz forum )
-- e-mail: varazir .. gmail.com
-- Version: 1.2
--
groups = {'group1', 'group2', 'group3', 'group4', 'group5', 'group6', 'group7' }
return {
on = {
devices = { 'IKEA Remote*' }},
logging = {
level = domoticz.LOG_DEBUG,
marker = "IKEARemote"
},
data = {
currentGroup = { initial = 1 }
},
execute = function(dz, item)
control =
{
group1 =
{
IKEAlamp = { idx = 13, toggle = true, blink = true, dimmer = true}
},
group2 =
{
Blinder = { idx = 59, toggle = true, blinder = true },
group3 =
{
IKEAlamp = { idx = 40, blink = true },
IKEAlampGroup = { idx = 65, toggle = true, dimmer = true},
},
group4 =
{
IKEAlamp = { idx = 73, toggle = true, blink = true, dimmer = true}
},
group5 =
{
IKEAlampGroup = { idx = 36, toggle = true, dimmer = true, blink = true}
},
group6 =
{
Lamp = { idx = 42, toggle = true, blink = true},
TvGroup = { idx = 2, toggle = true, group = true}
},
},
group7 =
{
Blinder = { idx = 83, toggle = true, blinder = true },
},
}
local function logWrite(str,level)
dz.log(tostring(str),level or dz.LOG_DEBUG)
end
local selectedGroupNumber = dz.data.currentGroup
logWrite("Current Group " .. selectedGroupNumber)
local maxGroup = #groups
local dummyDimmer = dz.devices(82)
local function doAction(action, direction)
logWrite("10 Current group number........" .. selectedGroupNumber)
selectedGroup = groups[selectedGroupNumber]
logWrite("11 Current selected group is..." .. selectedGroup)
selectedControlGroup = control[selectedGroup]
logWrite("12 Selected Control Group is a." .. type(control[selectedGroup]))
logWrite("13 Chaning the the switchSelector ")
dz.devices('IKEA Remote Groups').switchSelector(selectedGroupNumber).silent()
for device, attributes in pairs(selectedControlGroup) do
logWrite("20 Current device is........." .. device)
logWrite("21 Attribute type is........." .. type(attributes))
logWrite("22 IDX is...................." .. attributes["idx"])
currentIDx = attributes["idx"]
if attributes["group"] then
logWrite("24 Current Device is group......." .. dz.groups(currentIDx).name)
currentDevice = dz.groups(currentIDx)
else
logWrite("25 Current Device is device......" .. dz.devices(currentIDx).name)
currentDevice = dz.devices(currentIDx)
end
for attribute, value in pairs(attributes) do
logWrite("30 Current attribute is......" .. device)
if attribute == action then
logWrite("31 Current acction is......" .. action)
-- Blinking
if action == 'blink' then
local blinkDevice = dz.devices(currentIDx)
local blinkLevel = currentDevice.level
logWrite("Device " .. blinkDevice.name .. " will blink")
--if blinkDevice.state == "Off" then
-- blinkDevice.switchOn()
-- blinkDevice.switchOff().afterSec(0.5)
--else
-- blinkDevice.switchOff()
-- blinkDevice.switchOn().afterSec(0.5)
--end
elseif action == 'dimmer' then
local dimDevice = dz.devices(currentDevice)
local dimLevel = dimDevice.level
local delay = 0
logWrite(dimDevice.name .. " direction is " .. direction)
if direction == "stop" then
dimDevice.cancelQueuedCommands()
logWrite('Stop dimming of ' .. dimDevice.name .. ' at ' .. dimLevel ..'%')
elseif direction == 'down' then
repeat
delay = delay + 0.1
if direction == "down" then dimLevel = dimLevel - 1 else dimLevel = dimLevel + 1 end
logWrite('Set ' .. dimDevice.name .. ' to dimLevel '.. dimLevel .. '%, after ' .. delay .. ' seconds')
dimDevice.dimTo(dimLevel).afterSec(delay)
until dimLevel <= 0
elseif direction == 'up' then
repeat
delay = delay + 0.1
dimLevel = dimLevel + 1
logWrite('Set ' .. dimDevice.name .. ' to dimLevel '.. dimLevel .. '%, after ' .. delay .. ' seconds')
dimDevice.dimTo(dimLevel).afterSec(delay)
until dimLevel >= 100
end
elseif action == 'toggle' then
local toggleDevice = currentDevice
if attributes["group"] then
toggleDevice.toggleGroup()
else
toggleDevice.toggleSwitch()
end
end
end
end
end
end
local action = 'blink'
local direction = 'up'
if item.state == 'Click' and item.name == 'IKEA Remote Left' then
selectedGroupNumber = selectedGroupNumber - 1
if selectedGroupNumber == 0 then selectedGroupNumber = maxGroup end
-- dz.notify("Aktuell grupp",control[selectedGroupNumber],dz.PRIORITY_NORMAL,dz.NSS_HTTP)
elseif item.state == 'Click' and item.name == 'IKEA Remote Right' then
selectedGroupNumber = selectedGroupNumber + 1
if selectedGroupNumber > maxGroup then selectedGroupNumber = 1 end
-- dz.notify("Aktuell grupp",control[selectedGroupNumber],dz.PRIORITY_NORMAL,dz.NSS_HTTP)
elseif item.name == 'IKEA Remote' then
action = 'toggle'
elseif item.state == 'Hold' and item.name == "IKEA Remote Up" then
action = 'dimmer'
elseif item.state == 'Hold' and item.name == 'IKEA Remote Down' then
action = 'dimmer'
direction = 'down'
elseif item.state == 'Release' and item.name == 'IKEA Remote Down' or item.name == 'IKEA Remote Up' then
action = 'dimmer'
direction = 'stop'
elseif item.name == 'IKEA Remote Groups' then
selectedGroupNumber = item.level
else
logWrite('Unknown action requested; ignored', dz.LOG_INFO )
return
end
if item.state == 'Click' then
logWrite('Turning off ' .. item.name)
dz.devices(item.name).switchOff().silent()
end
dz.data.currentGroup = selectedGroupNumber
logWrite("Next Group " .. dz.data.currentGroup)
doAction(action, direction)
end
}Code: Select all
2019-07-19 17:25:00.658 Status: dzVents: Info: IKEARemote: ------ Start internal script: IKEARemote: Device: "IKEA Remote Right (zigbee2mqtt)", Index: 79
2019-07-19 17:25:00.659 Status: dzVents: Debug: IKEARemote: Current Group 1
2019-07-19 17:25:00.661 Status: dzVents: Debug: IKEARemote: Processing device-adapter for RemoteDummyDimmer: Switch device adapter
2019-07-19 17:25:00.662 Status: dzVents: Debug: IKEARemote: Turning off IKEA Remote Right
2019-07-19 17:25:00.662 Status: dzVents: Debug: IKEARemote: Constructed timed-command: Off
2019-07-19 17:25:00.662 Status: dzVents: Debug: IKEARemote: Constructed timed-command: Off NOTRIGGER
2019-07-19 17:25:00.662 Status: dzVents: Debug: IKEARemote: Next Group 2
2019-07-19 17:25:00.662 Status: dzVents: Debug: IKEARemote: 10 Current group number........2
2019-07-19 17:25:00.662 Status: dzVents: Debug: IKEARemote: 11 Current selected group is...group2
2019-07-19 17:25:00.662 Status: dzVents: Debug: IKEARemote: 12 Selected Control Group is a.table
2019-07-19 17:25:00.663 Status: dzVents: Debug: IKEARemote: 13 Chaning the the switchSelector
2019-07-19 17:25:00.665 Status: dzVents: Debug: IKEARemote: Processing device-adapter for IKEA Remote Groups: Switch device adapter
2019-07-19 17:25:00.665 Status: dzVents: Debug: IKEARemote: Constructed timed-command: Set Level 0
2019-07-19 17:25:00.665 Status: dzVents: Debug: IKEARemote: Constructed timed-command: Set Level 0 NOTRIGGER
2019-07-19 17:25:00.666 Status: dzVents: Debug: IKEARemote: 20 Current device is.........group4
2019-07-19 17:25:00.666 Status: dzVents: Debug: IKEARemote: 21 Attribute type is.........table
2019-07-19 17:25:00.666 Status: dzVents: Debug: IKEARemote: 20 Current device is.........group5
2019-07-19 17:25:00.666 Status: dzVents: Debug: IKEARemote: 21 Attribute type is.........table
2019-07-19 17:25:00.666 Status: dzVents: Debug: IKEARemote: 20 Current device is.........group3
2019-07-19 17:25:00.666 Status: dzVents: Debug: IKEARemote: 21 Attribute type is.........table
2019-07-19 17:25:00.666 Status: dzVents: Debug: IKEARemote: 20 Current device is.........Blinder
2019-07-19 17:25:00.666 Status: dzVents: Debug: IKEARemote: 21 Attribute type is.........table
2019-07-19 17:25:00.666 Status: dzVents: Debug: IKEARemote: 20 Current device is.........group6
2019-07-19 17:25:00.666 Status: dzVents: Debug: IKEARemote: 21 Attribute type is.........table
2019-07-19 17:25:00.668 Status: dzVents: Info: IKEARemote: ------ Finished IKEARemote
2019-07-19 17:25:09.268 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2019-07-19 17:25:44.899 Status: EventSystem: reset all events...
2019-07-19 17:25:44.901 Status: dzVents: Write file: /home/pi/domoticz/scripts/dzVents/generated_scripts/IKEARemote.lua
2019-07-19 17:26:14.088 Status: dzVents: Info: IKEARemote: ------ Start internal script: IKEARemote: Device: "IKEA Remote Left (zigbee2mqtt)", Index: 78
2019-07-19 17:26:14.089 Status: dzVents: Debug: IKEARemote: Current Group 2
2019-07-19 17:26:14.092 Status: dzVents: Debug: IKEARemote: Processing device-adapter for RemoteDummyDimmer: Switch device adapter
2019-07-19 17:26:14.092 Status: dzVents: Debug: IKEARemote: Turning off IKEA Remote Left
2019-07-19 17:26:14.092 Status: dzVents: Debug: IKEARemote: Constructed timed-command: Off
2019-07-19 17:26:14.092 Status: dzVents: Debug: IKEARemote: Constructed timed-command: Off NOTRIGGER
2019-07-19 17:26:14.093 Status: dzVents: Debug: IKEARemote: Next Group 1
2019-07-19 17:26:14.093 Status: dzVents: Debug: IKEARemote: 10 Current group number........1
2019-07-19 17:26:14.093 Status: dzVents: Debug: IKEARemote: 11 Current selected group is...group1
2019-07-19 17:26:14.093 Status: dzVents: Debug: IKEARemote: 12 Selected Control Group is a.table
2019-07-19 17:26:28.726 Status: dzVents: Info: IKEARemote: ------ Start internal script: IKEARemote: Device: "IKEA Remote Left (zigbee2mqtt)", Index: 78
2019-07-19 17:26:28.726 Status: dzVents: Debug: IKEARemote: Current Group 1
2019-07-19 17:26:28.728 Status: dzVents: Debug: IKEARemote: Processing device-adapter for RemoteDummyDimmer: Switch device adapter
2019-07-19 17:26:28.729 Status: dzVents: Debug: IKEARemote: Turning off IKEA Remote Left
2019-07-19 17:26:28.729 Status: dzVents: Debug: IKEARemote: Constructed timed-command: Off
2019-07-19 17:26:28.729 Status: dzVents: Debug: IKEARemote: Constructed timed-command: Off NOTRIGGER
2019-07-19 17:26:28.729 Status: dzVents: Debug: IKEARemote: Next Group 7
2019-07-19 17:26:28.729 Status: dzVents: Debug: IKEARemote: 10 Current group number........7
2019-07-19 17:26:28.729 Status: dzVents: Debug: IKEARemote: 11 Current selected group is...group7
2019-07-19 17:26:28.729 Status: dzVents: Debug: IKEARemote: 12 Selected Control Group is a.table
2019-07-19 17:26:28.729 Status: dzVents: Debug: IKEARemote: 13 Chaning the the switchSelector
2019-07-19 17:26:28.731 Status: dzVents: Debug: IKEARemote: Processing device-adapter for IKEA Remote Groups: Switch device adapter
2019-07-19 17:26:28.731 Status: dzVents: Debug: IKEARemote: Constructed timed-command: Set Level 10
2019-07-19 17:26:28.732 Status: dzVents: Debug: IKEARemote: Constructed timed-command: Set Level 10 NOTRIGGER
2019-07-19 17:26:28.732 Status: dzVents: Debug: IKEARemote: 20 Current device is.........Blinder
2019-07-19 17:26:28.732 Status: dzVents: Debug: IKEARemote: 21 Attribute type is.........table
2019-07-19 17:26:28.732 Status: dzVents: Debug: IKEARemote: 22 IDX is....................83
2019-07-19 17:26:28.733 Status: dzVents: Debug: IKEARemote: Processing device-adapter for Rullgardin Vardagsrum: Switch device adapter
2019-07-19 17:26:28.734 Status: dzVents: Debug: IKEARemote: 25 Current Device is device......Rullgardin Vardagsrum
2019-07-19 17:26:28.734 Status: dzVents: Debug: IKEARemote: 30 Current attribute is......Blinder
2019-07-19 17:26:28.734 Status: dzVents: Debug: IKEARemote: 30 Current attribute is......Blinder
2019-07-19 17:26:28.734 Status: dzVents: Debug: IKEARemote: 30 Current attribute is......Blinder
2019-07-19 17:26:28.736 Status: dzVents: Info: IKEARemote: ------ Finished IKEARemote
2019-07-19 17:26:28.739 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2019-07-19 17:26:37.243 Status: dzVents: Info: IKEARemote: ------ Start internal script: IKEARemote: Device: "IKEA Remote Left (zigbee2mqtt)", Index: 78
2019-07-19 17:26:37.244 Status: dzVents: Debug: IKEARemote: Current Group 7
2019-07-19 17:26:37.246 Status: dzVents: Debug: IKEARemote: Processing device-adapter for RemoteDummyDimmer: Switch device adapter
2019-07-19 17:26:37.247 Status: dzVents: Debug: IKEARemote: Turning off IKEA Remote Left
2019-07-19 17:26:37.247 Status: dzVents: Debug: IKEARemote: Constructed timed-command: Off
2019-07-19 17:26:37.247 Status: dzVents: Debug: IKEARemote: Constructed timed-command: Off NOTRIGGER
2019-07-19 17:26:37.249 Status: dzVents: Debug: IKEARemote: Next Group 6
2019-07-19 17:26:37.250 Status: dzVents: Debug: IKEARemote: 10 Current group number........6
2019-07-19 17:26:37.250 Status: dzVents: Debug: IKEARemote: 11 Current selected group is...group6
2019-07-19 17:26:37.250 Status: dzVents: Debug: IKEARemote: 12 Selected Control Group is a.nil
2019-07-19 17:26:37.250 Status: dzVents: Debug: IKEARemote: 13 Chaning the the switchSelector
2019-07-19 17:26:37.252 Status: dzVents: Debug: IKEARemote: Processing device-adapter for IKEA Remote Groups: Switch device adapter
2019-07-19 17:26:37.252 Status: dzVents: Debug: IKEARemote: Constructed timed-command: Set Level 10
2019-07-19 17:26:37.252 Status: dzVents: Debug: IKEARemote: Constructed timed-command: Set Level 10 NOTRIGGER
2019-07-19 17:26:37.253 Status: dzVents: Info: IKEARemote: ------ Finished IKEARemote
2019-07-19 17:26:37.256 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.luaCode: Select all
2019-07-19 17:04:06.991 Error: dzVents: Error: (2.4.26) IKEARemote: An error occurred when calling event handler IKEARemote
2019-07-19 17:04:06.991 Error: dzVents: Error: (2.4.26) IKEARemote: ...omoticz/scripts/dzVents/generated_scripts/IKEARemote.lua:96: attempt to concatenate a table value
2019-07-19 17:04:37.610 Error: dzVents: Error: (2.4.26) IKEARemote: An error occurred when calling event handler IKEARemote
2019-07-19 17:04:37.610 Error: dzVents: Error: (2.4.26) IKEARemote: ...omoticz/scripts/dzVents/generated_scripts/IKEARemote.lua:96: attempt to concatenate a table value
2019-07-19 17:14:03.794 Error: dzVents: Error: (2.4.26) IKEARemote: An error occurred when calling event handler IKEARemote
2019-07-19 17:14:03.794 Error: dzVents: Error: (2.4.26) IKEARemote: ...omoticz/scripts/dzVents/generated_scripts/IKEARemote.lua:92: attempt to concatenate field 'group' (a nil value)
2019-07-19 17:18:12.579 Error: dzVents: Error: (2.4.26) IKEARemote: An error occurred when calling event handler IKEARemote
2019-07-19 17:18:12.579 Error: dzVents: Error: (2.4.26) IKEARemote: ...omoticz/scripts/dzVents/generated_scripts/IKEARemote.lua:96: attempt to concatenate a table value
2019-07-19 17:20:33.511 Error: dzVents: Error: (2.4.26) IKEARemote: An error occurred when calling event handler IKEARemote
2019-07-19 17:20:33.511 Error: dzVents: Error: (2.4.26) IKEARemote: ...omoticz/scripts/dzVents/generated_scripts/IKEARemote.lua:89: attempt to concatenate field 'idx' (a nil value)
2019-07-19 17:21:55.211 Error: dzVents: Error: (2.4.26) IKEARemote: An error occurred when calling event handler IKEARemote
2019-07-19 17:21:55.211 Error: dzVents: Error: (2.4.26) IKEARemote: ...omoticz/scripts/dzVents/generated_scripts/IKEARemote.lua:89: attempt to concatenate field 'idx' (a nil value)
2019-07-19 17:22:15.057 Error: dzVents: Error: (2.4.26) IKEARemote: An error occurred when calling event handler IKEARemote
2019-07-19 17:22:15.058 Error: dzVents: Error: (2.4.26) IKEARemote: ...omoticz/scripts/dzVents/generated_scripts/IKEARemote.lua:85: bad argument #1 to 'pairs' (table expected, got nil)
2019-07-19 17:25:09.263 Error: dzVents: Error: (2.4.26) IKEARemote: An error occurred when calling event handler IKEARemote
2019-07-19 17:25:09.263 Error: dzVents: Error: (2.4.26) IKEARemote: ...omoticz/scripts/dzVents/generated_scripts/IKEARemote.lua:85: bad argument #1 to 'pairs' (table expected, got nil)
2019-07-19 17:26:37.253 Error: dzVents: Error: (2.4.26) IKEARemote: An error occurred when calling event handler IKEARemote
2019-07-19 17:26:37.253 Error: dzVents: Error: (2.4.26) IKEARemote: ...omoticz/scripts/dzVents/generated_scripts/IKEARemote.lua:85: bad argument #1 to 'pairs' (table expected, got nil)