Page 1 of 1

negative counting

Posted: Friday 16 February 2018 12:01
by poudenes
Hi All,

Again its me.. :) i have a great script for a morning scene (Thanks Danny) but now i want it other way around.
Instead of domTo from 1 to 100 i want from 100 to 1.

This is the current script for the morning:

Code: Select all

local Version               = '18.01.24'
local SwitchMorning		    = 64
local SwitchEvening		    = 59
local MasterBedroom		    = 7

return {
    active = true,
	on = {
		devices = {SwitchMorning},
	},
	logging = {marker = 'SCENE MORNING ' .. Version..'..........'},
	execute = function(domoticz, device)
		local light = domoticz.devices(MasterBedroom)
		if  (device.active)  then
			light.dimTo(1)
			light.setKelvin(5000)
			for i = 2,120 do
				light.dimTo(i).afterSec(i)
			end
            		domoticz.devices(SwitchMorning).switchOff()
			domoticz.log('---------------------------------------------------------------------', domoticz.LOG_FORCE)
			domoticz.log('--------------------==<[ SCENE MORNING IS ON ]>==--------------------', domoticz.LOG_FORCE)
			domoticz.log('---------------------------------------------------------------------', domoticz.LOG_FORCE)
			os.execute('/home/pi/domoticz/scripts/Peter/speech.sh "The scene morning is activated"&')
		end
	end
}

Re: negative counting

Posted: Friday 16 February 2018 15:33
by dannybloe
for i = 120,2,-1 do...
See the docs

Re: negative counting

Posted: Friday 16 February 2018 21:47
by poudenes
Thanks. Go read that website. Lots of info :)

Re: negative counting

Posted: Monday 12 March 2018 17:35
by poudenes
Can someone tell me if this is a correct way to do? So known im learn it correctly :)

Code: Select all

local Version                   = '18.03.05'
local testswitch                = 316

return {
    active = true,
	on = {
		devices = {testswitch},
	},
	execute = function(domoticz, device)
	    
    local BulbDressoir              = domoticz.devices(23)

	if  (device.active)  then
	    BulbDressoir.dimTo(1)
		BulbDressoir.setKelvin(5000)

		for i = 1,100 do
			BulbDressoir.dimTo(i).afterSec(i)
			print(i)
			end
		
	elseif (not device.active)  then
	    		BulbDressoir.dimTo(100)
			BulbDressoir.setKelvin(5000)

        local a = 1
		for i = 100,1,-1 do
		    	a = a +1 
			BulbDressoir.dimTo(i).afterSec(a)
		end
	end
end
}

Re: negative counting

Posted: Monday 12 March 2018 20:35
by waaren
Script should work. Do you have any specific reason to doubt that this is a correct way ?

Personally I would prefer to use devicenames over devicenumbers because it improves readability / maintainability but it is not incorrect.

Re: negative counting

Posted: Tuesday 13 March 2018 8:10
by poudenes
waaren wrote: Monday 12 March 2018 20:35 Script should work. Do you have any specific reason to doubt that this is a correct way ?

Personally I would prefer to use devicenames over devicenumbers because it improves readability / maintainability but it is not incorrect.
It is working. But if when there is a better way then i can learn from it. :)