negative counting

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

Moderator: leecollings

Post Reply
poudenes
Posts: 667
Joined: Wednesday 08 March 2017 9:42
Target OS: Linux
Domoticz version: 3.8993
Location: Amsterdam
Contact:

negative counting

Post 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
}
RPi3 B+, Debain Stretch, Domoticz, Homebridge, Dashticz, RFLink, Milight, Z-Wave, Fibaro, Nanoleaf, Nest, Harmony Hub, Now try to understand pass2php
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: negative counting

Post by dannybloe »

for i = 120,2,-1 do...
See the docs
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
poudenes
Posts: 667
Joined: Wednesday 08 March 2017 9:42
Target OS: Linux
Domoticz version: 3.8993
Location: Amsterdam
Contact:

Re: negative counting

Post by poudenes »

Thanks. Go read that website. Lots of info :)
RPi3 B+, Debain Stretch, Domoticz, Homebridge, Dashticz, RFLink, Milight, Z-Wave, Fibaro, Nanoleaf, Nest, Harmony Hub, Now try to understand pass2php
poudenes
Posts: 667
Joined: Wednesday 08 March 2017 9:42
Target OS: Linux
Domoticz version: 3.8993
Location: Amsterdam
Contact:

Re: negative counting

Post 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
}
RPi3 B+, Debain Stretch, Domoticz, Homebridge, Dashticz, RFLink, Milight, Z-Wave, Fibaro, Nanoleaf, Nest, Harmony Hub, Now try to understand pass2php
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: negative counting

Post 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.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
poudenes
Posts: 667
Joined: Wednesday 08 March 2017 9:42
Target OS: Linux
Domoticz version: 3.8993
Location: Amsterdam
Contact:

Re: negative counting

Post 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. :)
RPi3 B+, Debain Stretch, Domoticz, Homebridge, Dashticz, RFLink, Milight, Z-Wave, Fibaro, Nanoleaf, Nest, Harmony Hub, Now try to understand pass2php
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest