Page 1 of 1

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

Posted: Monday 26 November 2018 8:31
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.

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

Posted: Monday 26 November 2018 9:12
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 ?

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

Posted: Monday 26 November 2018 10:19
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 548 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...

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

Posted: Monday 26 November 2018 14:42
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

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

Posted: Thursday 06 December 2018 19:48
by Freemann
O i'm so stupid...

Thanks men, that solved it!!