Page 1 of 1

Ready scripts for just plain dimming or rgb?

Posted: Sunday 04 August 2019 18:32
by dandanger
I suck at scripting and don't have much time for this now, but I bet people have made tons of these so I'd be very glad if someone posted scripts for dimming. I've searched all sections and could not find even one script that would be for this simple usage. What I want to accomplish is like:

-Ikea tradfri dimmer(puck) -> dimming level -> Ikea tradfri bulb. And would be of course good if the same script could also control the light within domoticz.
-Same thing, rgb bulb for ikea.

I appreciate your help. Also good to see how different scripts I see for same function :).

Re: Ready scripts for just plain dimming or rgb?

Posted: Friday 09 August 2019 15:06
by dandanger
Well, no replys, I thought I'd give it a try myself. Heres what I got in two days(wow):

Code: Select all

return {
	on = {
		devices = {
			'IkeaPuck1'
		}
	},
	execute = function(domoticz, device)
	    local Light = dz.devices('Ikea1000-1')
	    himmennin = dz.variables('Dimmer1')
		domoticz.log('Device ' .. device.name .. ' was changed', domoticz.LOG_INFO)
		if (device.name == 'IkeaPuck1' and device.level >= 0) then
		    domoticz.himmennin.set('device.level')
		    Light.dimTo('himmennin')
        elseif (device.name == 'IkeaPuck1' and device.level == 0) then
		    domoticz.himmennin.set('device.level')
		    Light.switchOff()
		end
	end
}
And it does not work, I get this:

2019-08-09 15:57:12.151 Status: dzVents: Error (2.4.19): ...ticz/scripts/dzVents/generated_scripts/IkeaDimmTest1.lua:8: attempt to index global 'dz' (a nil value)

Dzvents documentation read many many times and cant get any closer than this..

Re: Ready scripts for just plain dimming or rgb?

Posted: Friday 09 August 2019 15:26
by boum
dz should be the first parameter to your execute function

Code: Select all

execute = function(dz, device)
(then you should replace all occurrences of domoticz with dz or the other way around)

Re: Ready scripts for just plain dimming or rgb?

Posted: Friday 09 August 2019 15:36
by boum
I'm not sure what you are trying to do with your "Dimmer1" device, so I would just simplify the script as:

Code: Select all

return {
on = {
	devices = {
		'IkeaPuck1'
	}
},
execute = function(dz, device)
        local light = dz.devices('Ikea1000-1')
	dz.log('Device ' .. device.name .. ' was changed', dz.LOG_INFO)
	if (device.level > 0) then
	    light.dimTo(device.level)
        else
	    light.switchOff()
	end
end
}

Re: Ready scripts for just plain dimming or rgb?

Posted: Friday 09 August 2019 17:14
by dandanger
boum wrote: Friday 09 August 2019 15:26 dz should be the first parameter to your execute function

Code: Select all

execute = function(dz, device)
(then you should replace all occurrences of domoticz with dz or the other way around)
Oh this I didnt know..noobie mistake seems.

Re: Ready scripts for just plain dimming or rgb?  [Solved]

Posted: Friday 09 August 2019 17:16
by dandanger
boum wrote: Friday 09 August 2019 15:36 I'm not sure what you are trying to do with your "Dimmer1" device, so I would just simplify the script as:

Code: Select all

return {
on = {
	devices = {
		'IkeaPuck1'
	}
},
execute = function(dz, device)
        local light = dz.devices('Ikea1000-1')
	dz.log('Device ' .. device.name .. ' was changed', dz.LOG_INFO)
	if (device.level > 0) then
	    light.dimTo(device.level)
        else
	    light.switchOff()
	end
end
}
This works like a dream...thank you very much. I knew this would be a simple task to do, only I suck bad at scripting, more learning needed.

The Dimmer1 is a variable, I thought that I could not perform dimming straight without getting the value to a variable first.