unexpected symbol near '}'  [Solved]

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

Moderator: leecollings

Post Reply
User avatar
Varazir
Posts: 487
Joined: Friday 20 February 2015 22:23
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

unexpected symbol near '}'

Post 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.
Raspberry PI 4 with RaZberry Controller 2016 ZWave+ and CC2531(zigbee)
Several IKEA devices/z-wave devices
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: unexpected symbol near '}'

Post 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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
Varazir
Posts: 487
Joined: Friday 20 February 2015 22:23
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: unexpected symbol near '}'

Post 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
}
Raspberry PI 4 with RaZberry Controller 2016 ZWave+ and CC2531(zigbee)
Several IKEA devices/z-wave devices
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: unexpected symbol near '}'  [Solved]

Post 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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
Varazir
Posts: 487
Joined: Friday 20 February 2015 22:23
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: unexpected symbol near '}'

Post 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'
Raspberry PI 4 with RaZberry Controller 2016 ZWave+ and CC2531(zigbee)
Several IKEA devices/z-wave devices
User avatar
Varazir
Posts: 487
Joined: Friday 20 February 2015 22:23
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: unexpected symbol near '}'

Post by Varazir »

I'm removing line 17
Raspberry PI 4 with RaZberry Controller 2016 ZWave+ and CC2531(zigbee)
Several IKEA devices/z-wave devices
User avatar
Varazir
Posts: 487
Joined: Friday 20 February 2015 22:23
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: unexpected symbol near '}'

Post 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')
Raspberry PI 4 with RaZberry Controller 2016 ZWave+ and CC2531(zigbee)
Several IKEA devices/z-wave devices
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: unexpected symbol near '}'

Post 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
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
Varazir
Posts: 487
Joined: Friday 20 February 2015 22:23
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: unexpected symbol near '}'

Post 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
Raspberry PI 4 with RaZberry Controller 2016 ZWave+ and CC2531(zigbee)
Several IKEA devices/z-wave devices
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest