Use variable for dimming  [Solved]

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

Moderator: leecollings

Post Reply
jberinga
Posts: 67
Joined: Tuesday 11 August 2015 14:20
Target OS: NAS (Synology & others)
Domoticz version: 2024.7
Location: The Netherlands
Contact:

Use variable for dimming

Post by jberinga »

Can I and how can I use a variable for dimming?
I created the script belows that works like a wake up light, but somehow I get the followin error when executing the script: : line 19: attempt to call field 'dimTo' (a nil value)

Code: Select all

return {
        on = { 
            timer = { 'between 6:50 and 7:10' }
		},
		data = {
			dimmerSet = { initial = 1 }
		},
        execute = function(domoticz, device)
		   --Donker, Wekker aan = Dimmer aan & dimmen + 1
        if 
				domoticz.devices('IsDonker').state == 'On' and
				domoticz.devices('WekkerAlarm').state == 'On' and			    
	then
                domoticz.devices(DimmerKeukenTafel).dimTo(domoticz.data.dimmerSet)
                domoticz.log('Slaapkamer dimmer gaat omhoog. Nu: '.. domoticz.data.dimmerSet, domoticz.LOG_INFO)
		domoticz.data.dimmerSet = domoticz.data.dimmerSet + 1		 
		    end
	end
 }
Any help is (again) much appreciated!
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Use variable for dimming

Post by waaren »

jberinga wrote: Sunday 09 June 2019 20:54 Can I and how can I use a variable for dimming?
I created the script belows that works like a wake up light, but somehow I get the followin error when executing the script: : line 19: attempt to call field 'dimTo' (a nil value)
Any help is (again) much appreciated!
Strange as this line 19 is only }

Can you try this one? And please check the domoticz log to see what happens.

Code: Select all

local startTime = '6:50'
local endTime = '7:10'

return 
{
    on = 
    { 
        timer = { 'between ' .. startTime .. ' and ' .. endTime }
    },
    
    data = 
    {  
        dimmerSet = { initial = 1 } 
    },
    
    execute = function(domoticz, device)
        if domoticz.time.matchesRule('at ' .. startTime) then 
            domoticz.data.dimmerSet = 1  -- reset to initial value
        end 

        if domoticz.devices('IsDonker').state == 'On' and 	domoticz.devices('WekkerAlarm').state == 'On' then
            domoticz.devices('DimmerKeukenTafel').dimTo(domoticz.data.dimmerSet)
            domoticz.log('Slaapkamer dimmer gaat omhoog. Nu: '.. domoticz.data.dimmerSet, domoticz.LOG_INFO)
            domoticz.data.dimmerSet = domoticz.data.dimmerSet + 1
        end
    end
 }
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
jberinga
Posts: 67
Joined: Tuesday 11 August 2015 14:20
Target OS: NAS (Synology & others)
Domoticz version: 2024.7
Location: The Netherlands
Contact:

Re: Use variable for dimming  [Solved]

Post by jberinga »

I feel stupid :oops: I forgot the quotes (' ') between the domotic.devices. Now it works!
And I like the way you reset the dimmerSet. Thanks for that!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest