Page 1 of 1
unexpected symbol near '}'
Posted: Thursday 02 July 2020 14:38
by Varazir
Hello,
I get the greatest error of them all 24: unexpected symbol near '}'
The last line of the script.
Only think I'm not sure about is the array.
Code: Select all
return {
on = {
devices = {
'IKEA - Sensor Hall',
}
},
execute = function(dz, item)
local function logWrite(str,level)
dz.log(tostring(str),level or dz.LOG_MODULE_EXEC_INFO)
end
local lampgroup = devices(203)
local lamparray = { 172, 180, 182, 186 }
if (time.isDayTime) then
for device in lamparray do
device.dimto(60)
end
else
for device in lamparray do
device.dimto(100)
end
end
}
I need to add if ON and if OFF as well.
Re: unexpected symbol near '}'
Posted: Thursday 02 July 2020 15:12
by waaren
Varazir wrote: Thursday 02 July 2020 14:38
I get the greatest error of them all 24: unexpected symbol near '}'
Could look like
Code: Select all
return
{
on =
{
devices =
{
'IKEA - Sensor Hall',
},
},
execute = function(dz, item)
local function logWrite(str,level)
dz.log(tostring(str),level or dz.LOG_MODULE_EXEC_INFO)
end
local lampgroup = dz.devices(203)
local lamparray = { 172, 180, 182, 186 }
local dimLevel = 100
if dz.time.isDayTime then
dimLevel = 60
end
for _, idx in ipairs(lamparray) do
dz.devices(idx).dimTo(dimLevel)
end
end
}
Re: unexpected symbol near '}'
Posted: Thursday 02 July 2020 16:00
by Varazir
waaren wrote: Thursday 02 July 2020 15:12
Varazir wrote: Thursday 02 July 2020 14:38
I get the greatest error of them all 24: unexpected symbol near '}'
Could look like
Code: Select all
return
{
on =
{
devices =
{
'IKEA - Sensor Hall',
},
},
execute = function(dz, item)
local function logWrite(str,level)
dz.log(tostring(str),level or dz.LOG_MODULE_EXEC_INFO)
end
local lampgroup = dz.devices(203)
local lamparray = { 172, 180, 182, 186 }
local dimLevel = 100
if dz.time.isDayTime then
dimLevel = 60
end
for _, idx in ipairs(lamparray) do
dz.devices(idx).dimTto(dimLevel)
end
end
}
Thanks
I added a ON and OFF if statement as well.
No errors so I hope it will work.
Code: Select all
return
{
on =
{
devices =
{
'IKEA - Sensor Hall',
},
},
execute = function(dz, device)
local function logWrite(str,level)
dz.log(tostring(str),level or dz.LOG_MODULE_EXEC_INFO)
end
local lampgroup = dz.devices(203)
local lamparray = { 172, 180, 182, 186 }
local dimLevel = 100
if dz.time.isDayTime then
dimLevel = 60
end
if device.state == 'ON' then
for _, idx in ipairs(lamparray) do
dz.devices(idx).dimTo(dimLevel)
end
else
for _, idx in ipairs(lamparray) do
dz.devices(idx).switchOff()
end
end
end
}
Re: unexpected symbol near '}' [Solved]
Posted: Thursday 02 July 2020 16:10
by waaren
Varazir wrote: Thursday 02 July 2020 16:00
No errors so I hope it will work.
Probably not because state 'ON' is not likely to happen. (most devices report either 'On' or 'Off')
because dimTo(0) is an implicit switchOff() you could do
Code: Select all
return
{
on =
{
devices =
{
'IKEA - Sensor Hall',
},
},
execute = function(dz, device)
local function logWrite(str,level)
dz.log(tostring(str),level or dz.LOG_MODULE_EXEC_INFO)
end
local lampgroup = dz.devices(203)
local lamparray = { 172, 180, 182, 186 }
local dimLevel = 100
if device.state ~= 'On' then
dimLevel = 0
elseif dz.time.isDayTime then
dimLevel = 60
end
for _, idx in ipairs(lamparray) do
dz.devices(idx).dimTo(dimLevel)
end
end
}
Re: unexpected symbol near '}'
Posted: Thursday 02 July 2020 17:22
by Varazir
waaren wrote: Thursday 02 July 2020 16:10
Varazir wrote: Thursday 02 July 2020 16:00
No errors so I hope it will work.
Probably not because state 'ON' is not likely to happen. (most devices report either 'On' or 'Off')
because dimTo(0) is an implicit switchOff() you could do
Code: Select all
return
{
on =
{
devices =
{
'IKEA - Sensor Hall',
},
},
execute = function(dz, device)
local function logWrite(str,level)
dz.log(tostring(str),level or dz.LOG_MODULE_EXEC_INFO)
end
local lampgroup = dz.devices(203)
local lamparray = { 172, 180, 182, 186 }
local dimLevel = 100
if device.state ~= 'On' then
dimLevel = 0
elseif dz.time.isDayTime then
dimLevel = 60
end
for _, idx in ipairs(lamparray) do
dz.devices(idx).dimTo(dimLevel)
end
end
}
I'm getting
Code: Select all
2020-07-02 17:21:41.597 (zigbee2mqtt) MQTT message: zigbee2mqtt/IKEA - Sensor Sovrum {'requested_brightness_level': 254, 'requested_brightness_percent': 100, 'linkquality': 68, 'occupancy': True, 'update_available': False}
2020-07-02 17:21:44.354 (zigbee2mqtt) MQTT message: zigbee2mqtt/IKEA - Sensor Hall {'occupancy': True, 'linkquality': 39, 'update_available': False, 'battery': 47}
2020-07-02 17:21:44.588 Error: dzVents: Error: (3.0.9) An error occurred when calling event handler IKEA - Sensor Hall
2020-07-02 17:21:44.588 Error: dzVents: Error: (3.0.9) ...scripts/dzVents/generated_scripts/IKEA - Sensor Hall.lua:17: attempt to call a nil value (global 'devices'
Re: unexpected symbol near '}'
Posted: Thursday 02 July 2020 17:24
by Varazir
I'm removing line 17
Re: unexpected symbol near '}'
Posted: Thursday 02 July 2020 19:42
by Varazir
I'm getting
2020-07-02 19:41:15.233 Error: dzVents: Error: (3.0.9) An error occurred when calling event handler IKEA - Sensor Hall
2020-07-02 19:41:15.233 Error: dzVents: Error: (3.0.9) ...scripts/dzVents/generated_scripts/IKEA - Sensor Hall.lua:30: attempt to call a nil value (field 'dimto')
Re: unexpected symbol near '}'
Posted: Thursday 02 July 2020 19:43
by waaren
Varazir wrote: Thursday 02 July 2020 19:42
I'm getting
2020-07-02 19:41:15.233 Error: dzVents: Error: (3.0.9) An error occurred when calling event handler IKEA - Sensor Hall
2020-07-02 19:41:15.233 Error: dzVents: Error: (3.0.9) ...scripts/dzVents/generated_scripts/IKEA - Sensor Hall.lua:30: attempt to call a nil value (field 'dimto')
it's dimTo
Re: unexpected symbol near '}'
Posted: Thursday 02 July 2020 19:47
by Varazir
I think I found it, typo on the variable, it was dimlevel in the daytime and dimLevel in the rest of the script