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

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

Moderator: leecollings

Post Reply
dandanger
Posts: 9
Joined: Thursday 23 August 2018 13:22
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Ready scripts for just plain dimming or rgb?

Post 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 :).
dandanger
Posts: 9
Joined: Thursday 23 August 2018 13:22
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Ready scripts for just plain dimming or rgb?

Post 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..
User avatar
boum
Posts: 135
Joined: Friday 18 January 2019 11:31
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: France
Contact:

Re: Ready scripts for just plain dimming or rgb?

Post 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)
User avatar
boum
Posts: 135
Joined: Friday 18 January 2019 11:31
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: France
Contact:

Re: Ready scripts for just plain dimming or rgb?

Post 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
}
dandanger
Posts: 9
Joined: Thursday 23 August 2018 13:22
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Ready scripts for just plain dimming or rgb?

Post 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.
dandanger
Posts: 9
Joined: Thursday 23 August 2018 13:22
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post 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.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest