Issue looping through the devices of a scene  [Solved]

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

Moderator: leecollings

Post Reply
georon
Posts: 13
Joined: Friday 23 February 2018 14:09
Target OS: Raspberry Pi / ODroid
Domoticz version: Bèta
Location: Netherlands
Contact:

Issue looping through the devices of a scene

Post by georon »

Hi all,

I am trying to dim all the devices in a specific scene by using the method .devices() as per the documentation at https://www.domoticz.com/wiki/DzVents:_ ... ting#Scene
Maybe I am doing this one wrong, but I always receive the error that I am trying to call a nil value with the foreach.

Can someone point out to me what I am doing wrong?

Code: Select all

--[[
	Prerequisites
	==================================
	Domoticz v3.8837 or later (dzVents version 2.4 or later)
	User Variable named UV_ToonIP type string, that holds the internal Toon IP
    Dummy switches that match the variables beneath

	CHANGE LOG: See https://github.com/Geo-Ron/dzVents/commits/master/dzToon.lua


]] --

local scriptVersion         = '1.0.1'

return {
    active = true,
	logging = {
		 level = domoticz.LOG_DEBUG, -- Uncomment to override the dzVents global logging setting
		marker = 'dzIkeaSwitch1 '..scriptVersion
	},
    on = {
        devices = {
            'Zigbee2MQTT - 0x842e14fffe45b570 (Left Arrow)',
            'Zigbee2MQTT - 0x842e14fffe45b570 (Right Arrow)'
            }
    },
    execute = function(domoticz, item)
        --item.dump()
        if (item.name == 'Zigbee2MQTT - 0x842e14fffe45b570 (Left Arrow)' and item.levelName == 'Click') then
            domoticz.scenes('TV Kijken').switchOn()
        end
        if (item.name == 'Zigbee2MQTT - 0x842e14fffe45b570 (Left Arrow)' and item.levelName == 'Hold') then
            domoticz.scenes('TV Kijken').dump()
            domoticz.scenes('TV Kijken').devices().foreach(
                function(device)
                    domoticz.log('dimming the light.'..device.name..' to '.. device.level/2, domoticz.LOG_DEBUG)
                    device.dump()
                end
            )
        end
    end
}

User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Issue looping through the devices of a scene  [Solved]

Post by waaren »

georon wrote: Wednesday 30 September 2020 20:06 Maybe I am doing this one wrong, but I always receive the error that I am trying to call a nil value with the foreach.
Try changing

Code: Select all

domoticz.scenes('TV Kijken').devices().foreach(
to

Code: Select all

domoticz.scenes('TV Kijken').devices().forEach(
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
georon
Posts: 13
Joined: Friday 23 February 2018 14:09
Target OS: Raspberry Pi / ODroid
Domoticz version: Bèta
Location: Netherlands
Contact:

Re: Issue looping through the devices of a scene

Post by georon »

Doh... Thanks!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest