Page 1 of 1

Use variable for dimming

Posted: Sunday 09 June 2019 20:54
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!

Re: Use variable for dimming

Posted: Sunday 09 June 2019 23:11
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
 }

Re: Use variable for dimming  [Solved]

Posted: Monday 10 June 2019 10:01
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!