Switch does not switch

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

Moderator: leecollings

Post Reply
vco1
Posts: 29
Joined: Monday 12 September 2016 9:00
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: The Netherlands
Contact:

Switch does not switch

Post by vco1 »

I have a couple of scripts for NodOn Soft Remotes. They basically just switch on/off several lights based on the button pressed on the remote.

For one of these scripts one ZWave switch is not working anymore. That is, the light does not turn on or off based on the button clicked on the remote. Strange thing is that if I assign another switch (lamp) to this event, everything works as expected. And b.t.w. for this particular light it used to work too.

In the script I have my switches/lights defined as follows.

Code: Select all

local lampBalcony = 123
The Id is correct. And the light is functioning properly from the Domoticz UI as well as through the Alexicz skill. It just doesn't get triggered through the dzVents script.

What am I missing here?
Piacco
Posts: 81
Joined: Friday 14 November 2014 9:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Switch does not switch

Post by Piacco »

local lampBalcony = dz.devices(123)
vco1
Posts: 29
Joined: Monday 12 September 2016 9:00
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: The Netherlands
Contact:

Re: Switch does not switch

Post by vco1 »

That's done later in the script.

Problem is that it ain't working for switch with id 123 but it is working for id 456 (a different switch/light).

Id123 does work when testing it through the API, e.g. through Postman.
User avatar
habahabahaba
Posts: 266
Joined: Saturday 18 March 2023 14:44
Target OS: Windows
Domoticz version: 2024.4
Contact:

Re: Switch does not switch

Post by habahabahaba »

So
show the full script
vco1
Posts: 29
Joined: Monday 12 September 2016 9:00
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: The Netherlands
Contact:

Re: Switch does not switch

Post by vco1 »

So

Code: Select all

local lampReading = 123
local lampBookcase = 456
local lampBalcony = 789

return {
	on = {
		devices = {
            '$NodOn Soft Remote Grey_scene_state_scene_001_0',
            '$NodOn Soft Remote Grey_scene_state_scene_001_3',
            '$NodOn Soft Remote Grey_scene_state_scene_002_0',
			'$NodOn Soft Remote Grey_scene_state_scene_003_0',
			'$NodOn Soft Remote Grey_scene_state_scene_004_0'
		},
	},
	execute = function(dz, nodOn)

        local function switchSingle(dzLight)
            if dzLight.state ~= 'On' then
                dzLight.switchOn()
            else
                dzLight.switchOff()
            end
        end
    
        local function switchScene(dzScene)
            if dzScene.state ~= 'On' then
                dzScene.switchOn()
            else
                dzScene.switchOff()
            end
    end

        if nodOn.name == '$NodOn Soft Remote Grey_scene_state_scene_001_0' then
            switchSingle(dz.devices(lampBookcase))
        elseif nodOn.name == '$NodOn Soft Remote Grey_scene_state_scene_001_3' then
            switchScene(dz.groups('Living Room'))
        elseif nodOn.name == '$NodOn Soft Remote Grey_scene_state_scene_002_0' then
            switchSingle(dz.devices(lampBalcony))
        elseif nodOn.name == '$NodOn Soft Remote Grey_scene_state_scene_003_0' then
            switchScene(dz.groups('Living room'))
        elseif nodOn.name == '$NodOn Soft Remote Grey_scene_state_scene_004_0' then
            switchSingle(dz.devices(lampReading))
        end
	end
}
lampBalcony is not working. If I replace the Id from lampBalcony by that of another switch, all is working fine. And the actual switch for lampBalcony is also functioning properly from the Domoticz UI as well as via the API of Alexicz.
User avatar
waltervl
Posts: 6677
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2025.1
Location: NL
Contact:

Re: Switch does not switch

Post by waltervl »

Is device lampBalcony the same type of device as the other switches?

Further to that dzvents has the build in toggleSwitch() or toggleGroup() function, no need to write your own switchSingle() function:
https://wiki.domoticz.com/DzVents:_next ... ctor_etc.)

A Domoticz scene can only be switched on, not toggled. A Domoticz group can be toggled or switched on and off.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
vco1
Posts: 29
Joined: Monday 12 September 2016 9:00
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: The Netherlands
Contact:

Re: Switch does not switch

Post by vco1 »

waltervl wrote: Thursday 23 October 2025 17:04 Is device lampBalcony the same type of device as the other switches?
Yes. They're all on/off switches.
User avatar
habahabahaba
Posts: 266
Joined: Saturday 18 March 2023 14:44
Target OS: Windows
Domoticz version: 2024.4
Contact:

Re: Switch does not switch

Post by habahabahaba »

What if to replace
dz.devices(lampBalcony) - with exact name of that lamp?

dz.devices('name_of_the_lamp') ?
FlyingDomotic
Posts: 463
Joined: Saturday 27 February 2016 0:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Switch does not switch

Post by FlyingDomotic »

Would it be possible to have a screenshoot of lampBalcony device (find it in "switch" tab, click on "Modify" and take the screenshoot)?

What kind of hardware do you have behind it (ZigBee, Wifi,...)?

Do you have some error in log when trying to manually change its state from Domoticz (switch it on and off)?
User avatar
waltervl
Posts: 6677
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2025.1
Location: NL
Contact:

Re: Switch does not switch

Post by waltervl »

habahabahaba wrote: Friday 24 October 2025 6:13 What if to replace
dz.devices(lampBalcony) - with exact name of that lamp?

dz.devices('name_of_the_lamp') ?
Indeed: Dzvents cannot handle 2 devices with exactly the same name. The device name should be unique.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
vco1
Posts: 29
Joined: Monday 12 September 2016 9:00
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: The Netherlands
Contact:

Re: Switch does not switch

Post by vco1 »

waltervl wrote: Friday 24 October 2025 13:12 Indeed: Dzvents cannot handle 2 devices with exactly the same name. The device name should be unique.
And that turned out to be the cause of the issue. I had 2 devices with the same name. Two completely different types of devices - a temperature sensor and a switch - but the same name anyway.

After renaming one, all is fine and dandy again. I thought/hoped that using Id's in scripts would make devices unique. But apparently not.

Thanks for pointing me in the right direction. Problem solved.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest