switchOn() or switchOff() HUE light doesn't work

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

Moderator: leecollings

Post Reply
Freemann
Posts: 94
Joined: Thursday 24 November 2016 14:55
Target OS: Linux
Domoticz version: >=Béta
Location: Netherlands
Contact:

switchOn() or switchOff() HUE light doesn't work

Post by Freemann »

Struggling some hours now with my new Tradfri Hue light.
When I switch the Tradfri light through the "light icon" on the Devices page, the light switch as expected.
When I use the following in dzVents, it doesn't work;

Code: Select all

domoticz.devices('WCTradfri').switchOn()
I see, corresponding to the line number of the above line in de scripts, error in my Logging page;

Code: Select all

2018-11-26 08:33:01.779 Status: dzVents: Error (2.4.7): ...-domoticz/scripts/dzVents/generated_scripts/WC-Licht.lua:18: attempt to index a nil value
And device 'WCTradfri' exists, double , triple checked, copied name from devices page.

The following code is working;

Code: Select all

WCSceneAan = 'curl --request PUT --data "{\\"scene\\": \\"6kLEoMrcZGjSbGP\\", \\"on\\":\"false\"}" "http://'..hueBridgeIP..'/api/'..hueApiKey..'/groups/2/action"'
os.execute(WCSceneAan)
So Switching on the device page and the above os.execute works, but the switchOn() or switchOff() commands don't work.

Any help would be appreciated.
Domotica/graphs "freak" :)
NUC8i3BEH(8gb/250gb),
Lubuntu 19.04,
Aeotec Z-Stick S2(Gen5)
HarmonyElite
HUE(5 bulbs, 2 blooms)
NetAtmo(complete setup)
MiLight iboxV6(2 MiLightBulbs)
IP-Cam

https://www.frijduurzaam.nl
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: switchOn() or switchOff() HUE light doesn't work

Post by waaren »

Freemann wrote: Monday 26 November 2018 8:31 Struggling some hours now with my new Tradfri Hue light.
From your curl command it looks like 'WCTradfri' is a group or scene but you refer in dzVents to it as a device.
try domoticz.scenes('WCTradfri').switchOn() or domoticz.groups('WCTradfri').switchOn()
if that does not work Can you add (before line 18) the line

Code: Select all

domoticz.devices('WCTradfri').dump()
in your code and report all the loglines created by the script after an execution ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Freemann
Posts: 94
Joined: Thursday 24 November 2016 14:55
Target OS: Linux
Domoticz version: >=Béta
Location: Netherlands
Contact:

Re: switchOn() or switchOff() HUE light doesn't work

Post by Freemann »

os.execute is really calling a scene, this because in the future there will be more then one light in this room.

The WCTradfri device is really existing, see screenshot below;
Screenshot - 26_11_2018 , 10_21_48.png
Screenshot - 26_11_2018 , 10_21_48.png (36.86 KiB) Viewed 545 times
Above devices were generated automatically by Domoticz after adding the light to my Hue Bridge.

This is my script;

Code: Select all

return {
	on = {
		devices = {'WC licht schakelaar2'}
	},
	execute = function(domoticz, device)
	    domoticz.devices('WCTradfri').dump()

	    hueApiKey = domoticz.variables('hueApiKey').value
	    hueBridgeIP = domoticz.variables('hueBridgeIP').value
	    
	    WCSceneAan = 'curl --request PUT --data "{\\"scene\\": \\"6kLEoMrcZGjSbGP\\", \\"on\\":\"false\"}" "http://'..hueBridgeIP..'/api/'..hueApiKey..'/groups/2/action"'
        WCSceneUit = 'curl --request PUT --data "{\\"on\\":false}" "http://'..hueBridgeIP..'/api/'..hueApiKey..'/groups/2/action"'
        
		if (device.state == 'On') then
			domoticz.devices('WCTradfri').switchOn()
			os.execute(WCSceneAan)
		elseif (device.state == 'Off') then
			domoticz.devices('WCTradfri').switchOn()
			os.execute(WCSceneUit)
		end
	end
}
This is the error log for this script call;

Code: Select all

2018-11-26 10:17:48.344 (Zwave) Light/Switch (WC licht schakelaar2)
2018-11-26 10:17:48.315 Status: User: Admin initiated a switch command (317/WC licht schakelaar2/Off)
2018-11-26 10:17:48.807 Status: dzVents: Error (2.4.7): There is no device with that name or id: WCTradfri
2018-11-26 10:17:48.807 Status: dzVents: Error (2.4.7): An error occured when calling event handler WC-Licht2
2018-11-26 10:17:48.807 Status: dzVents: Error (2.4.7): ...domoticz/scripts/dzVents/generated_scripts/WC-Licht2.lua:6: attempt to index a nil value
So dzVents isn't seeing the 'WCTradfri' device...
Domotica/graphs "freak" :)
NUC8i3BEH(8gb/250gb),
Lubuntu 19.04,
Aeotec Z-Stick S2(Gen5)
HarmonyElite
HUE(5 bulbs, 2 blooms)
NetAtmo(complete setup)
MiLight iboxV6(2 MiLightBulbs)
IP-Cam

https://www.frijduurzaam.nl
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: switchOn() or switchOff() HUE light doesn't work

Post by waaren »

Freemann wrote: Monday 26 November 2018 10:19 The WCTradfri device is really existing
So dzVents isn't seeing the 'WCTradfri' device...
It exists but have not been added to domoticz. Press the green Arrow and add it to domoticz
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Freemann
Posts: 94
Joined: Thursday 24 November 2016 14:55
Target OS: Linux
Domoticz version: >=Béta
Location: Netherlands
Contact:

Re: switchOn() or switchOff() HUE light doesn't work

Post by Freemann »

O i'm so stupid...

Thanks men, that solved it!!
Domotica/graphs "freak" :)
NUC8i3BEH(8gb/250gb),
Lubuntu 19.04,
Aeotec Z-Stick S2(Gen5)
HarmonyElite
HUE(5 bulbs, 2 blooms)
NetAtmo(complete setup)
MiLight iboxV6(2 MiLightBulbs)
IP-Cam

https://www.frijduurzaam.nl
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest