negative counting

Easy to use, 100% Lua-based event scripting framework.
Post Reply
poudenes
Posts: 545
Joined: Wednesday 08 March 2017 10:42
Target OS: Linux
Domoticz version: 3.8993
Location: Amsterdam
Contact:

negative counting

Post by poudenes » Friday 16 February 2018 13:01

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
}
RPi3 with OSMC - RPi3 with Domoticz - Dashticz - MiLight - Nanolead Aurora - KaKu - Logitech Hamony - Nest - RFLink

dannybloe
Posts: 1473
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi
Domoticz version:
Location: Ermelo
Contact:

Re: negative counting

Post by dannybloe » Friday 16 February 2018 16:33

for i = 120,2,-1 do...
See the docs
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.

poudenes
Posts: 545
Joined: Wednesday 08 March 2017 10:42
Target OS: Linux
Domoticz version: 3.8993
Location: Amsterdam
Contact:

Re: negative counting

Post by poudenes » Friday 16 February 2018 22:47

Thanks. Go read that website. Lots of info :)
RPi3 with OSMC - RPi3 with Domoticz - Dashticz - MiLight - Nanolead Aurora - KaKu - Logitech Hamony - Nest - RFLink

poudenes
Posts: 545
Joined: Wednesday 08 March 2017 10:42
Target OS: Linux
Domoticz version: 3.8993
Location: Amsterdam
Contact:

Re: negative counting

Post by poudenes » Monday 12 March 2018 18:35

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
}
RPi3 with OSMC - RPi3 with Domoticz - Dashticz - MiLight - Nanolead Aurora - KaKu - Logitech Hamony - Nest - RFLink

User avatar
waaren
Posts: 921
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: negative counting

Post by waaren » Monday 12 March 2018 21: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.
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

poudenes
Posts: 545
Joined: Wednesday 08 March 2017 10:42
Target OS: Linux
Domoticz version: 3.8993
Location: Amsterdam
Contact:

Re: negative counting

Post by poudenes » Tuesday 13 March 2018 9:10

waaren wrote:
Monday 12 March 2018 21: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. :)
RPi3 with OSMC - RPi3 with Domoticz - Dashticz - MiLight - Nanolead Aurora - KaKu - Logitech Hamony - Nest - RFLink

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest