Group switch the lights

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

Moderator: leecollings

Post Reply
misko903
Posts: 51
Joined: Thursday 27 September 2018 22:58
Target OS: Raspberry Pi / ODroid
Domoticz version: Latest
Location: Trencin, Slovakia
Contact:

Group switch the lights

Post by misko903 »

Hi, I have created an event:

Code: Select all

return {

   on = { devices = { 18, 20, 25 }},                -- Spalna Tlacidla: 18-Spálňa Posteľ Tlačidlo, 20-Spálňa Von Tlačidlo, 25-Matusik
--   on = { scenes = { 'AllLights' }},
   
   execute = function(dz, item )
        if item.state == "Click" then
            dz.devices(49).toggleSwitch()           -- Spalna Pasik Hore
        elseif item.state == "Double Click" then
            dz.devices(33).toggleSwitch()           -- Spalna Pasik Dole
        elseif item.state == "Long Click" then
            dz.scenes('AllLights').switchOff()     -- Všetky svetlá Group
        end
	domoticz.log('Device ' .. device.name .. ' was changed', domoticz.LOG_INFO)
   end
   
}

Everything works, except the Long Click - Group switching. In Scenes I have created group called AllLights - manually switching it on or off always work. but not through the button dzVents script.
What is wrong in my script?
Thank you!
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Group switch the lights

Post by waaren »

misko903 wrote: Thursday 20 December 2018 7:06 Hi, I have created an event:
Everything works, except the Long Click - Group switching. In Scenes I have created group called AllLights - manually switching it on or off always work. but not through the button dzVents script.
My guess is that you created AllLights as a group. If that is the case you should use

Code: Select all

dz.groups('AllLights').switchOff()     -- Všetky svetlá Group
If that does not solve your issue you should turn on debug logging on the script level and look at the relevant loglines.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
misko903
Posts: 51
Joined: Thursday 27 September 2018 22:58
Target OS: Raspberry Pi / ODroid
Domoticz version: Latest
Location: Trencin, Slovakia
Contact:

Re: Group switch the lights

Post by misko903 »

Thanks, partially works, but it has ended with error:

Code: Select all

2018-12-30 15:41:41.249 Status: User: Admin initiated a switch command (18/Spálňa Posteľ Tlačidlo/Set Level)
2018-12-30 15:41:41.421 Status: dzVents: Info: Handling events for: "Spálňa Posteľ Tlačidlo", value: "Long Click"
2018-12-30 15:41:41.421 Status: dzVents: Info: ------ Start internal script: Spalna Tlacidla: Device: "Spálňa Posteľ Tlačidlo (Xiaomi Gateway)", Index: 18
2018-12-30 15:41:41.422 Status: dzVents: Error (2.4.9): An error occured when calling event handler Spalna Tlacidla
2018-12-30 15:41:41.422 Status: dzVents: Error (2.4.9): ...cz/scripts/dzVents/generated_scripts/Spalna Tlacidla.lua:14: attempt to index global 'domoticz' (a nil value)
2018-12-30 15:41:41.422 Status: dzVents: Info: ------ Finished Spalna Tlacidla
2018-12-30 15:41:41.516 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2018-12-30 15:41:42.035 (Xiaomi Gateway) Color Switch (Gateway Svetlo)
2018-12-30 15:41:42.090 Activating Scene/Group Device: Vianočné Zásuvka (Off)
2018-12-30 15:41:42.250 (Xiaomi Gateway) Light/Switch (Vianočné Zásuvka)
2018-12-30 15:41:42.302 Activating Scene/Group Device: Obývačka Polička (Off)
2018-12-30 15:41:42.362 (Yeelight Controller) Color Switch (Obývačka Polička)
2018-12-30 15:41:42.420 Activating Scene/Group Device: Obývačka Stena 1 (Off)
2018-12-30 15:41:44.869 (Xiaomi Gateway) General/kWh (Pivnica Zasuvka Spotreba)
2018-12-30 15:41:45.569 Activating Scene/Group Device: Obývačka Stena 2 (Off)
2018-12-30 15:41:45.519 Error: YeeLight: Exception: connect: No route to host
2018-12-30 15:41:48.770 Activating Scene/Group Device: Pivnica Zásuvka (Off)
2018-12-30 15:41:48.934 (Xiaomi Gateway) Light/Switch (Pivnica Zásuvka)
2018-12-30 15:41:48.986 Activating Scene/Group Device: Spálňa Pásik Dole (Off)
2018-12-30 15:41:48.719 Error: YeeLight: Exception: connect: No route to host
2018-12-30 15:41:49.055 (Yeelight Controller) Color Switch (Spálňa Pásik Dole)
2018-12-30 15:41:49.107 Activating Scene/Group Device: Spálňa Pasik Hore (Off)
2018-12-30 15:41:49.171 (Yeelight Controller) Color Switch (Spálňa Pasik Hore)
2018-12-30 15:41:49.223 Activating Scene/Group Device: Technická Stena (Off)
2018-12-30 15:41:49.284 (Yeelight Controller) Color Switch (Technická Stena)
I pressed the button in domoticz, not the HW button.
Error on line 14 is probably something with logging/debugging?
The Exception Errors - no route to host seems to be lights which have no power.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Group switch the lights

Post by waaren »

misko903 wrote: Sunday 30 December 2018 15:49 Thanks, partially works, but it has ended with error:
You hand over "dz" to the function in line 6 but refer to "domoticz" in line 14.
Change both "domoticz" to "dz" in line 14 to get rid of this error.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
misko903
Posts: 51
Joined: Thursday 27 September 2018 22:58
Target OS: Raspberry Pi / ODroid
Domoticz version: Latest
Location: Trencin, Slovakia
Contact:

Re: Group switch the lights

Post by misko903 »

thanks again waaren,
I have also --ed the logging line
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 1 guest