| 
		
	
	
	
		
	Posts: 76 
	Threads: 12 
	Joined: Jan 2016
	
 Reputation: 
1 
	
		
		
		25.12.2018, 13:24 
(This post was last modified: 26.12.2018, 02:47 by CHOUAIBOU.)
		
	 
		 (24.12.2018, 17:00)AlexLV Wrote:  I think above just copy of previous post... 
 Guys, can you please post here final script?? I tried to make changes mentioned but not work for me..
 
Hi AlexLV, 
Please find bellow the working script. There was an error in the time string format. 
Merry Christmas
 
B.R, 
Chouaibou.
 Code: -- ** Staircase logic with external time object and retriggering on input object Version 3.2 ** ---- ****************************** Created by Erwin van der Zwart **************************** --
 -- ************************************** SET PARAMETERS ************************************ --
 
 -- Set output address
 AddressOutput = '32/1/21'  -- 01. 1 bit (boolean)
 
 -- Set external time address (optional)
 AddressExternalTime = '32/1/22' -- 07. 2 byte unsigned integer
 
 -- Use time left indication
 UseTimeLeft = true -- Set to false if no time left indication is used
 
 -- Set feedback adress of time left indication (optional)
 AddressTimeLeft = '32/1/23' -- 255 byte string
 
 -- Set time delay (Used when external time is not available)
 SetDelay = 120 -- 2 minutes
 
 -- Seconds or Minutes
 SetSec = true -- Set to false for Minutes
 
 -- Set factor delay (Multiplies Delay)
 SetFac = 1
 
 -- Logic can be turned of by value 0
 Off_by_Value_Zero = false
 
 -- ************************************** END PARAMETERS ************************************ --
 -- *************************** DON'T CHANGE ANYTHING UNDER THIS LINE ************************ --
 Input_Value = event.getvalue()
 if Off_by_Value_Zero == false and (Input_Value == false or Input_Value == 0) then
 return
 else
 tpid = storage.get('PID:' .. _SCRIPTNAME)
 if tpid == nil then
 pid = os.getpid()
 storage.set('PID:' .. _SCRIPTNAME, pid)
 else
 pid = os.getpid()
 storage.set('PID:' .. _SCRIPTNAME, pid)
 os.kill(tpid, signal.SIGKILL)
 end
 function Calculate_Time(StairCaseTime)
 if StairCaseTime > (86400 -1) then
 StairCaseTime = (86400 -1)
 end
 local hours = math.floor(StairCaseTime / 3600 % 24)
 local minutes = math.floor(StairCaseTime / 60 % 60)
 local seconds = math.floor(StairCaseTime % 60)
 time = {
 day = 0,
 hour = hours,
 minute = minutes,
 second = seconds,
 }
 time =string.format('%02d:%02d:%02d',time.hour,time.minute,time.second)
 return time
 end
 if Input_Value == true or Input_Value == 1 then
 ValueExternalTime = grp.getvalue(AddressExternalTime) or SetDelay
 if SetSec == true then
 Multiply_Seconds = 1
 else
 Multiply_Seconds = 60
 end
 StairCaseTime = ValueExternalTime * Multiply_Seconds * SetFac
 ValueOutput = grp.getvalue(AddressOutput)
 if ValueOutput == false then
 grp.write(AddressOutput, true)
 end
 if UseTimeLeft == true then
 if StairCaseTime > 0 then
 time = Calculate_Time(StairCaseTime)
 grp.update(AddressTimeLeft, time)
 repeat
 StairCaseTime = StairCaseTime - 1
 time = Calculate_Time(StairCaseTime)
 grp.update(AddressTimeLeft, time)
 os.sleep(1)
 until StairCaseTime == 0
 end
 else
 os.sleep(StairCaseTime)
 end
 grp.write(AddressOutput, false)
 elseif Input_Value == false or Input_Value == 0 then
 ValueOutput = grp.getvalue(AddressOutput)
 if ValueOutput == true then
 if UseTimeLeft == true then
 time = Calculate_Time(0)
 grp.update(AddressTimeLeft, time)
 end
 grp.write(AddressOutput, false)
 end
 end
 storage.delete('PID:' .. _SCRIPTNAME)
 end
 
		
	 
	
	
	
		
	Posts: 394 
	Threads: 84 
	Joined: Jun 2017
	
 Reputation: 
9 
	
		
		
		26.12.2018, 09:05 
(This post was last modified: 26.12.2018, 09:06 by AlexLV.)
		
	 
		Chouaibou, BIG THANKS    
Now it finally working!!! You just forgot insert input address, so below all should work fine   
I wish to all Happy New Year    
Alex
 Code: -- ** Staircase logic with external time object and retriggering on input object Version 3.2 ** ---- ****************************** Created by Erwin van der Zwart **************************** --
 -- ************************************** SET PARAMETERS ************************************ --
 
 -- Set input address
 AddressInput = '32/1/20 ' -- 01. 1 bit (boolean)
 -- Set output address
 AddressOutput = '32/1/21'  -- 01. 1 bit (boolean)
 
 -- Set external time address (optional)
 AddressExternalTime = '32/1/22' -- 07. 2 byte unsigned integer
 
 -- Use time left indication
 UseTimeLeft = true -- Set to false if no time left indication is used
 
 -- Set feedback adress of time left indication (optional)
 AddressTimeLeft = '32/1/23' -- 255 byte string
 
 -- Set time delay (Used when external time is not available)
 SetDelay = 120 -- 2 minutes
 
 -- Seconds or Minutes
 SetSec = true -- Set to false for Minutes
 
 -- Set factor delay (Multiplies Delay)
 SetFac = 1
 
 -- Logic can be turned of by value 0
 Off_by_Value_Zero = false
 
 -- ************************************** END PARAMETERS ************************************ --
 -- *************************** DON'T CHANGE ANYTHING UNDER THIS LINE ************************ --
 Input_Value = event.getvalue()
 if Off_by_Value_Zero == false and (Input_Value == false or Input_Value == 0) then
 return
 else
 tpid = storage.get('PID:' .. _SCRIPTNAME)
 if tpid == nil then
 pid = os.getpid()
 storage.set('PID:' .. _SCRIPTNAME, pid)
 else
 pid = os.getpid()
 storage.set('PID:' .. _SCRIPTNAME, pid)
 os.kill(tpid, signal.SIGKILL)
 end
 function Calculate_Time(StairCaseTime)
 if StairCaseTime > (86400 -1) then
 StairCaseTime = (86400 -1)
 end
 local hours = math.floor(StairCaseTime / 3600 % 24)
 local minutes = math.floor(StairCaseTime / 60 % 60)
 local seconds = math.floor(StairCaseTime % 60)
 time = {
 day = 0,
 hour = hours,
 minute = minutes,
 second = seconds,
 }
 time =string.format('%02d:%02d:%02d',time.hour,time.minute,time.second)
 return time
 end
 if Input_Value == true or Input_Value == 1 then
 ValueExternalTime = grp.getvalue(AddressExternalTime) or SetDelay
 if SetSec == true then
 Multiply_Seconds = 1
 else
 Multiply_Seconds = 60
 end
 StairCaseTime = ValueExternalTime * Multiply_Seconds * SetFac
 ValueOutput = grp.getvalue(AddressOutput)
 if ValueOutput == false then
 grp.write(AddressOutput, true)
 end
 if UseTimeLeft == true then
 if StairCaseTime > 0 then
 time = Calculate_Time(StairCaseTime)
 grp.update(AddressTimeLeft, time)
 repeat
 StairCaseTime = StairCaseTime - 1
 time = Calculate_Time(StairCaseTime)
 grp.update(AddressTimeLeft, time)
 os.sleep(1)
 until StairCaseTime == 0
 end
 else
 os.sleep(StairCaseTime)
 end
 grp.write(AddressOutput, false)
 elseif Input_Value == false or Input_Value == 0 then
 ValueOutput = grp.getvalue(AddressOutput)
 if ValueOutput == true then
 if UseTimeLeft == true then
 time = Calculate_Time(0)
 grp.update(AddressTimeLeft, time)
 end
 grp.write(AddressOutput, false)
 end
 end
 storage.delete('PID:' .. _SCRIPTNAME)
 end
		
	 
	
	
	
		
	Posts: 394 
	Threads: 84 
	Joined: Jun 2017
	
 Reputation: 
9 
	
		
		
		06.01.2019, 23:05 
(This post was last modified: 06.01.2019, 23:06 by AlexLV.)
		
	 
		Hi. How correctly reset this timer in taster key is pressed before timer finished?? If use this from script:
 
 -- Logic can be turned of by value 0
 Off_by_Value_Zero = true
 
 timer just stopped not resetted. If I press input key again timer just starting again. How change script?
 Thank you for help.
 Alex
 
		
	 
	
	
	
		
	Posts: 301 
	Threads: 39 
	Joined: Apr 2019
	
 Reputation: 
4 
	
	
		Code: blocking = grp.read('0/0/1')Out01 = '0/0/2'
 
 if AddressOutput == true and (blocking == true or blocking == 1) then grp.write (out01, true)
 else
 if AddressOutput == false and (blocking == true or blocking == 1) then grp.write (out01, false)
 end
 end
Hello, if possible I would like to include in this script one more function, it would be a block. But I can't make it work.
	 
		
	 
	
	
	
		
	Posts: 8410 
	Threads: 45 
	Joined: Jun 2015
	
 Reputation: 
481 
	
	
		This script is incorrect. grp.read sends read request but does not return current value. You need to use grp.getvalue instead. 
It can also be simplified like this:
 Code: value = event.getvalue()blocking = grp.getvalue('0/0/1')
 
 if blocking then
 grp.write('0/0/2', value)
 end
In FBeditor there's Select switch > Lock out block that can be used.
	
		
	 
	
	
	
		
	Posts: 301 
	Threads: 39 
	Joined: Apr 2019
	
 Reputation: 
4 
	
	
		Code: -- ** Staircase logic with external time object and retriggering on input object Version 3.2 ** ---- ****************************** Created by Erwin van der Zwart **************************** --
 -- ************************************** SET PARAMETERS ************************************ --
 
 -- Set input address
 AddressInput = '32/1/20 ' -- 01. 1 bit (boolean)
 -- Set output address
 AddressOutput = '32/1/21'  -- 01. 1 bit (boolean)
 
 -- Set external time address (optional)
 AddressExternalTime = '32/1/22' -- 07. 2 byte unsigned integer
 
 -- Use time left indication
 UseTimeLeft = true -- Set to false if no time left indication is used
 
 -- Set feedback adress of time left indication (optional)
 AddressTimeLeft = '32/1/23' -- 255 byte string
 
 -- Set time delay (Used when external time is not available)
 SetDelay = 120 -- 2 minutes
 
 -- Seconds or Minutes
 SetSec = true -- Set to false for Minutes
 
 -- Set factor delay (Multiplies Delay)
 SetFac = 1
 
 -- Logic can be turned of by value 0
 Off_by_Value_Zero = false
 
 -- ************************************** END PARAMETERS ************************************ --
 -- *************************** DON'T CHANGE ANYTHING UNDER THIS LINE ************************ --
 Input_Value = event.getvalue()
 if Off_by_Value_Zero == false and (Input_Value == false or Input_Value == 0) then
 return
 else
 tpid = storage.get('PID:' .. _SCRIPTNAME)
 if tpid == nil then
 pid = os.getpid()
 storage.set('PID:' .. _SCRIPTNAME, pid)
 else
 pid = os.getpid()
 storage.set('PID:' .. _SCRIPTNAME, pid)
 os.kill(tpid, signal.SIGKILL)
 end
 function Calculate_Time(StairCaseTime)
 if StairCaseTime > (86400 -1) then
 StairCaseTime = (86400 -1)
 end
 local hours = math.floor(StairCaseTime / 3600 % 24)
 local minutes = math.floor(StairCaseTime / 60 % 60)
 local seconds = math.floor(StairCaseTime % 60)
 time = {
 day = 0,
 hour = hours,
 minute = minutes,
 second = seconds,
 }
 time =string.format('%02d:%02d:%02d',time.hour,time.minute,time.second)
 return time
 end
 if Input_Value == true or Input_Value == 1 then
 ValueExternalTime = grp.getvalue(AddressExternalTime) or SetDelay
 if SetSec == true then
 Multiply_Seconds = 1
 else
 Multiply_Seconds = 60
 end
 StairCaseTime = ValueExternalTime * Multiply_Seconds * SetFac
 ValueOutput = grp.getvalue(AddressOutput)
 if ValueOutput == false then
 grp.write(AddressOutput, true)
 end
 if UseTimeLeft == true then
 if StairCaseTime > 0 then
 time = Calculate_Time(StairCaseTime)
 grp.update(AddressTimeLeft, time)
 repeat
 StairCaseTime = StairCaseTime - 1
 time = Calculate_Time(StairCaseTime)
 grp.update(AddressTimeLeft, time)
 os.sleep(1)
 until StairCaseTime == 0
 end
 else
 os.sleep(StairCaseTime)
 end
 grp.write(AddressOutput, false)
 elseif Input_Value == false or Input_Value == 0 then
 ValueOutput = grp.getvalue(AddressOutput)
 if ValueOutput == true then
 if UseTimeLeft == true then
 time = Calculate_Time(0)
 grp.update(AddressTimeLeft, time)
 end
 grp.write(AddressOutput, false)
 end
 end
 storage.delete('PID:' .. _SCRIPTNAME)
 end
Hi admin, thanks for your response, I need to include it in the script itself. I have tried your script and it only activates the output if the block is true, but I need if the block is true that it activates and deactivates me at the end of the time.
	 
		
	 
	
	
	
		
	Posts: 8410 
	Threads: 45 
	Joined: Jun 2015
	
 Reputation: 
481 
	
	
		If you don't want to run script if blocking is set to true then simply add this to the start of your script: Code: blocking = grp.getvalue('0/0/1')
 if not blocking then
 return
 end
		
	 
	
	
	
		
	Posts: 301 
	Threads: 39 
	Joined: Apr 2019
	
 Reputation: 
4 
	
		
		
		29.01.2020, 15:47 
(This post was last modified: 29.01.2020, 16:25 by davidchispas.)
		
	 
		 (29.01.2020, 13:34)admin Wrote:  If you don't want to run script if blocking is set to true then simply add this to the start of your script:
 Code: blocking = grp.getvalue('0/0/1')
 if not blocking then
 return
 end
 Thanks Admin, it works perfectly!    
 Code: -- ** Staircase logic with external time object and retriggering on input object Version 3.2 ** ---- ****************************** Created by Erwin van der Zwart **************************** --
 -- ************************************** SET PARAMETERS ************************************ --
 
 -- Set input address
 AddressInput = '21/1/40' -- 01. 1 bit (boolean)
 -- Set output address
 AddressOutput = '1/1/40' -- 01. 1 bit (boolean)
 
 -- Set external time address (optional)
 AddressExternalTime = '55/1/4' -- 07. 2 byte unsigned integer
 
 -- Use time left indication
 UseTimeLeft = true -- Set to false if no time left indication is used
 
 -- Set feedback adress of time left indication (optional)
 AddressTimeLeft = '55/1/5' -- 255 byte string
 
 -- Set time delay (Used when external time is not available)
 SetDelay = 120 -- 2 minutes
 
 -- Seconds or Minutes
 SetSec = true -- Set to false for Minutes
 
 -- Set factor delay (Multiplies Delay)
 SetFac = 1
 
 -- Logic can be turned of by value 0
 Off_by_Value_Zero = false
 
 -- ************************************** END PARAMETERS ************************************ --
 -- *************************** DON'T CHANGE ANYTHING UNDER THIS LINE ************************ --
 
 
 
 
 
 
 
 blocking = grp.getvalue('40/1/40')
 if not blocking then
 return
 end
 
 
 Input_Value = event.getvalue()
 if Off_by_Value_Zero == false and (Input_Value == false or Input_Value == 0) then
 return
 else
 tpid = storage.get('PID:' .. _SCRIPTNAME)
 if tpid == nil then
 pid = os.getpid()
 storage.set('PID:' .. _SCRIPTNAME, pid)
 else
 pid = os.getpid()
 storage.set('PID:' .. _SCRIPTNAME, pid)
 os.kill(tpid, signal.SIGKILL)
 end
 function Calculate_Time(StairCaseTime)
 if StairCaseTime > (86400 -1) then
 StairCaseTime = (86400 -1)
 end
 local hours = math.floor(StairCaseTime / 3600 % 24)
 local minutes = math.floor(StairCaseTime / 60 % 60)
 local seconds = math.floor(StairCaseTime % 60)
 time = {
 day = 0,
 hour = hours,
 minute = minutes,
 second = seconds,
 }
 time =string.format('%02d:%02d:%02d',time.hour,time.minute,time.second)
 return time
 end
 if Input_Value == true or Input_Value == 1 then
 ValueExternalTime = grp.getvalue(AddressExternalTime) or SetDelay
 if SetSec == true then
 Multiply_Seconds = 1
 else
 Multiply_Seconds = 60
 end
 StairCaseTime = ValueExternalTime * Multiply_Seconds * SetFac
 ValueOutput = grp.getvalue(AddressOutput)
 if ValueOutput == false then
 grp.write(AddressOutput, true)
 end
 if UseTimeLeft == true then
 if StairCaseTime > 0 then
 time = Calculate_Time(StairCaseTime)
 grp.update(AddressTimeLeft, time)
 repeat
 StairCaseTime = StairCaseTime - 1
 time = Calculate_Time(StairCaseTime)
 grp.update(AddressTimeLeft, time)
 os.sleep(1)
 until StairCaseTime == 0
 end
 else
 os.sleep(StairCaseTime)
 end
 grp.write(AddressOutput, false)
 elseif Input_Value == false or Input_Value == 0 then
 ValueOutput = grp.getvalue(AddressOutput)
 if ValueOutput == true then
 if UseTimeLeft == true then
 time = Calculate_Time(0)
 grp.update(AddressTimeLeft, time)
 end
 grp.write(AddressOutput, false)
 end
 end
 storage.delete('PID:' .. _SCRIPTNAME)
 end
I have a small error activating the lock. If the timing is already started before blocking ... at the end of that time, send false. Is it possible to correct not send it?
	 
		
	 
	
	
	
		
	Posts: 1807 
	Threads: 7 
	Joined: Jul 2015
	
 Reputation: 
121 
	
		
		
		29.01.2020, 22:05 
(This post was last modified: 29.01.2020, 22:06 by Erwin van der Zwart.)
		
	 
		Hi,
You need to add the blocking after the kill part to make sure the previous script is killed when the new one started.
Code: -- ** Staircase logic with external time object and retriggering on input object Version 3.2 ** ---- ****************************** Created by Erwin van der Zwart **************************** --
 -- ************************************** SET PARAMETERS ************************************ --
 
 -- Set input address
 AddressInput = '21/1/40' -- 01. 1 bit (boolean)
 -- Set output address
 AddressOutput = '1/1/40' -- 01. 1 bit (boolean)
 
 -- Set external time address (optional)
 AddressExternalTime = '55/1/4' -- 07. 2 byte unsigned integer
 
 -- Use time left indication
 UseTimeLeft = true -- Set to false if no time left indication is used
 
 -- Set feedback adress of time left indication (optional)
 AddressTimeLeft = '55/1/5' -- 255 byte string
 
 -- Set blocking address
 AddressBlocking = '40/1/40'
 
 -- Set time delay (Used when external time is not available)
 SetDelay = 120 -- 2 minutes
 
 -- Seconds or Minutes
 SetSec = true -- Set to false for Minutes
 
 -- Set factor delay (Multiplies Delay)
 SetFac = 1
 
 -- Logic can be turned of by value 0
 Off_by_Value_Zero = false
 
 -- ************************************** END PARAMETERS ************************************ --
 -- *************************** DON'T CHANGE ANYTHING UNDER THIS LINE ************************ --
 
 Input_Value = event.getvalue()
 if Off_by_Value_Zero == false and (Input_Value == false or Input_Value == 0) then
 return
 else
 tpid = storage.get('PID:' .. _SCRIPTNAME)
 if tpid == nil then
 pid = os.getpid()
 storage.set('PID:' .. _SCRIPTNAME, pid)
 else
 pid = os.getpid()
 storage.set('PID:' .. _SCRIPTNAME, pid)
 os.kill(tpid, signal.SIGKILL)
 end
 
 blocking = grp.getvalue(AddressBlocking)
 if not blocking then
 return
 end
 
 function Calculate_Time(StairCaseTime)
 if StairCaseTime > (86400 -1) then
 StairCaseTime = (86400 -1)
 end
 local hours = math.floor(StairCaseTime / 3600 % 24)
 local minutes = math.floor(StairCaseTime / 60 % 60)
 local seconds = math.floor(StairCaseTime % 60)
 time = {
 day = 0,
 hour = hours,
 minute = minutes,
 second = seconds,
 }
 time =string.format('%02d:%02d:%02d',time.hour,time.minute,time.second)
 return time
 end
 if Input_Value == true or Input_Value == 1 then
 ValueExternalTime = grp.getvalue(AddressExternalTime) or SetDelay
 if SetSec == true then
 Multiply_Seconds = 1
 else
 Multiply_Seconds = 60
 end
 StairCaseTime = ValueExternalTime * Multiply_Seconds * SetFac
 ValueOutput = grp.getvalue(AddressOutput)
 if ValueOutput == false then
 grp.write(AddressOutput, true)
 end
 if UseTimeLeft == true then
 if StairCaseTime > 0 then
 time = Calculate_Time(StairCaseTime)
 grp.update(AddressTimeLeft, time)
 repeat
 StairCaseTime = StairCaseTime - 1
 time = Calculate_Time(StairCaseTime)
 grp.update(AddressTimeLeft, time)
 os.sleep(1)
 until StairCaseTime == 0
 end
 else
 os.sleep(StairCaseTime)
 end
 grp.write(AddressOutput, false)
 elseif Input_Value == false or Input_Value == 0 then
 ValueOutput = grp.getvalue(AddressOutput)
 if ValueOutput == true then
 if UseTimeLeft == true then
 time = Calculate_Time(0)
 grp.update(AddressTimeLeft, time)
 end
 grp.write(AddressOutput, false)
 end
 end
 storage.delete('PID:' .. _SCRIPTNAME)
 end
BR,
 
Erwin
	 
		
	 
	
	
	
		
	Posts: 394 
	Threads: 84 
	Joined: Jun 2017
	
 Reputation: 
9 
	
	
		Hi Erwin, 
this is super script    As I sent some times ago private mail to you and you recommend to me use it - I used this script, all is working wonderful    Big thanks!!! One thing is absent in your script. We can just stop it if Logic turn off = 1, but can we somehow reset time before it will end by timer? In that case we will have super timer with start/stop/blocking/reset possibilities..
 
BR,
 
Alex
	
		
	 
	
	
	
		
	Posts: 1807 
	Threads: 7 
	Joined: Jul 2015
	
 Reputation: 
121 
	
	
		Hi,
 If you send a 1 again on the trigger object it should reset the time and start counting from start.
 
 BR,
 
 Erwin
 
		
	 
	
	
	
		
	Posts: 394 
	Threads: 84 
	Joined: Jun 2017
	
 Reputation: 
9 
	
	
		Erwin,
 Yes, I thought about such option, but I am using this at visu:
 
 -- Use time left indication
 UseTimeLeft = true -- Set to false if no time left indication is used
 
 So when I stop I see remained time, if I restart it - time starts from the beginning. But I need if I reset timer - timer ends and remain time = zeros and output deactivated, before countdown finished by themselves.. Tried different ways, but not successfully to solve this idea with your script..
 
		
	 
	
	
	
		
	Posts: 301 
	Threads: 39 
	Joined: Apr 2019
	
 Reputation: 
4 
	
	
		 (29.01.2020, 22:05)Erwin van der Zwart Wrote:  Hi,Thank you so much for the correction! Now it works perfectly! It is a great script!
 You need to add the blocking after the kill part to make sure the previous script is killed when the new one started.
 
 BR,Code: -- ** Staircase logic with external time object and retriggering on input object Version 3.2 ** ---- ****************************** Created by Erwin van der Zwart **************************** --
 -- ************************************** SET PARAMETERS ************************************ --
 
 -- Set input address
 AddressInput = '21/1/40' -- 01. 1 bit (boolean)
 -- Set output address
 AddressOutput = '1/1/40' -- 01. 1 bit (boolean)
 
 -- Set external time address (optional)
 AddressExternalTime = '55/1/4' -- 07. 2 byte unsigned integer
 
 -- Use time left indication
 UseTimeLeft = true -- Set to false if no time left indication is used
 
 -- Set feedback adress of time left indication (optional)
 AddressTimeLeft = '55/1/5' -- 255 byte string
 
 -- Set blocking address
 AddressBlocking = '40/1/40'
 
 -- Set time delay (Used when external time is not available)
 SetDelay = 120 -- 2 minutes
 
 -- Seconds or Minutes
 SetSec = true -- Set to false for Minutes
 
 -- Set factor delay (Multiplies Delay)
 SetFac = 1
 
 -- Logic can be turned of by value 0
 Off_by_Value_Zero = false
 
 -- ************************************** END PARAMETERS ************************************ --
 -- *************************** DON'T CHANGE ANYTHING UNDER THIS LINE ************************ --
 
 Input_Value = event.getvalue()
 if Off_by_Value_Zero == false and (Input_Value == false or Input_Value == 0) then
 return
 else
 tpid = storage.get('PID:' .. _SCRIPTNAME)
 if tpid == nil then
 pid = os.getpid()
 storage.set('PID:' .. _SCRIPTNAME, pid)
 else
 pid = os.getpid()
 storage.set('PID:' .. _SCRIPTNAME, pid)
 os.kill(tpid, signal.SIGKILL)
 end
 
 blocking = grp.getvalue(AddressBlocking)
 if not blocking then
 return
 end
 
 function Calculate_Time(StairCaseTime)
 if StairCaseTime > (86400 -1) then
 StairCaseTime = (86400 -1)
 end
 local hours = math.floor(StairCaseTime / 3600 % 24)
 local minutes = math.floor(StairCaseTime / 60 % 60)
 local seconds = math.floor(StairCaseTime % 60)
 time = {
 day = 0,
 hour = hours,
 minute = minutes,
 second = seconds,
 }
 time =string.format('%02d:%02d:%02d',time.hour,time.minute,time.second)
 return time
 end
 if Input_Value == true or Input_Value == 1 then
 ValueExternalTime = grp.getvalue(AddressExternalTime) or SetDelay
 if SetSec == true then
 Multiply_Seconds = 1
 else
 Multiply_Seconds = 60
 end
 StairCaseTime = ValueExternalTime * Multiply_Seconds * SetFac
 ValueOutput = grp.getvalue(AddressOutput)
 if ValueOutput == false then
 grp.write(AddressOutput, true)
 end
 if UseTimeLeft == true then
 if StairCaseTime > 0 then
 time = Calculate_Time(StairCaseTime)
 grp.update(AddressTimeLeft, time)
 repeat
 StairCaseTime = StairCaseTime - 1
 time = Calculate_Time(StairCaseTime)
 grp.update(AddressTimeLeft, time)
 os.sleep(1)
 until StairCaseTime == 0
 end
 else
 os.sleep(StairCaseTime)
 end
 grp.write(AddressOutput, false)
 elseif Input_Value == false or Input_Value == 0 then
 ValueOutput = grp.getvalue(AddressOutput)
 if ValueOutput == true then
 if UseTimeLeft == true then
 time = Calculate_Time(0)
 grp.update(AddressTimeLeft, time)
 end
 grp.write(AddressOutput, false)
 end
 end
 storage.delete('PID:' .. _SCRIPTNAME)
 end
 Erwin
 
		
	 
	
	
	
		
	Posts: 94 
	Threads: 17 
	Joined: Jan 2020
	
 Reputation: 
2 
	
	
		 (30.01.2020, 09:29)Erwin van der Zwart Wrote:  Hi,
 If you send a 1 again on the trigger object it should reset the time and start counting from start.
 
 BR,
 
 Erwin
 
The count starts from begging but the output is not resends 1. 
Is there something more that needs to be done for this?
	 
		
	 
	
	
	
		
	Posts: 1807 
	Threads: 7 
	Joined: Jul 2015
	
 Reputation: 
121 
	
		
		
		02.05.2020, 22:05 
(This post was last modified: 02.05.2020, 22:07 by Erwin van der Zwart.)
		
	 
		Hi, 
Change line 80-83:
 Code: ValueOutput = grp.getvalue(AddressOutput)if ValueOutput == false then
 grp.write(AddressOutput, true)
 end
Into:
 Code: grp.write(AddressOutput, true)
This way the output is not checked on state
 
BR,
 
Erwin
	
		
	 
	
	
	
		
	Posts: 94 
	Threads: 17 
	Joined: Jan 2020
	
 Reputation: 
2 
	
	
		 (02.05.2020, 22:05)Erwin van der Zwart Wrote:  Hi,
 Change line 80-83:
 
 Into:Code: ValueOutput = grp.getvalue(AddressOutput)if ValueOutput == false then
 grp.write(AddressOutput, true)
 end
 This way the output is not checked on stateCode: grp.write(AddressOutput, true)
 BR,
 
 Erwin
 Yeah thanks!  
Now I want to implement a Nightmode that changes the output after nightshift.  
I change the outeput address to "AddressOutputDay" and added these new ones "AddressOutputNight",  "NighMode" and "AddressOutputStatus". 
Then changed the script like this
 Code:    StairCaseTime = ValueExternalTime * Multiply_Seconds * SetFacValueOutput = grp.getvalue(AddressOutputStatus)
 if ValueOutput == false and NightMode == false then
 grp.write(AddressOutputDay, true)
 else
 grp.write(AddressOutputNight, true)
 end
But it just uses "AddressOutputNight" even if NightMode is false or true.  
What is the right way of doing this?
	 
		
	 
	
	
	
		
	Posts: 1807 
	Threads: 7 
	Joined: Jul 2015
	
 Reputation: 
121 
	
		
		
		07.05.2020, 20:33 
(This post was last modified: 07.05.2020, 20:34 by Erwin van der Zwart.)
		
	 
		Hi,
 I need to see the complete script as now there is no way of telling what you do wrong, i can’t see what you have declared for the night mode vars etcetera...
 
 BR,
 
 Erwin
 
		
	 
	
	
	
		
	Posts: 94 
	Threads: 17 
	Joined: Jan 2020
	
 Reputation: 
2 
	
	
		 (07.05.2020, 20:33)Erwin van der Zwart Wrote:  Hi,
 I need to see the complete script as now there is no way of telling what you do wrong, i can’t see what you have declared for the night mode vars etcetera...
 
 BR,
 
 Erwin
 Here it is. 
 Code: -- ** Staircase logic with external time object and retriggering on input object Version 3.2 ** ---- ****************************** Created by Erwin van der Zwart **************************** --
 -- ************************************** SET PARAMETERS ************************************ --
 
 -- Set input address
 AddressInput = '5/4/1' -- 01. 1 bit (boolean)
 -- Set output address
 AddressOutputDay = '32/1/38' -- 01. 1 bit (boolean)
 AddressOutputNight = '32/1/41'
 
 -- Set Status feedback of room controoled lights
 AddressOutputStatus = '5/0/26'
 
 -- Set external time address (optional)
 AddressExternalTime = '5/4/2' -- 07. 2 byte unsigned integer
 
 -- Use time left indication
 UseTimeLeft = true -- Set to false if no time left indication is used
 
 -- Set feedback adress of time left indication (optional)
 AddressTimeLeft = '32/1/39' -- 255 byte string
 
 -- Set Auto address
 AddressAuto = '32/1/40'
 
 -- Set time delay (Used when external time is not available)
 SetDelay = 120 -- 2 minutes
 
 -- Seconds or Minutes
 SetSec = true -- Set to false for Minutes
 
 -- Set factor delay (Multiplies Delay)
 SetFac = 1
 
 -- Logic can be turned of by value 0
 Off_by_Value_Zero = false
 
 --Manuell off when sends a "0" Resets Staircase logic manually
 AddressManOff = '5/0/0'
 
 --Day/Night switchover, Night if value "1"
 NightMode = '0/7/3' --01. 1 bit (boolean)
 
 -- ************************************** END PARAMETERS ************************************ --
 -- *************************** DON'T CHANGE ANYTHING UNDER THIS LINE ************************ --
 
 Input_Value = event.getvalue()
 if Off_by_Value_Zero == false and (Input_Value == false or Input_Value == 0) then
 return
 else
 tpid = storage.get('PID:' .. _SCRIPTNAME)
 if tpid == nil then
 pid = os.getpid()
 storage.set('PID:' .. _SCRIPTNAME, pid)
 else
 pid = os.getpid()
 storage.set('PID:' .. _SCRIPTNAME, pid)
 os.kill(tpid, signal.SIGKILL)
 end
 
 auto = grp.getvalue(AddressAuto)
 if not auto then
 return
 end
 
 function Calculate_Time(StairCaseTime)
 if StairCaseTime > (86400 -1) then
 StairCaseTime = (86400 -1)
 end
 local hours = math.floor(StairCaseTime / 3600 % 24)
 local minutes = math.floor(StairCaseTime / 60 % 60)
 local seconds = math.floor(StairCaseTime % 60)
 time = {
 day = 0,
 hour = hours,
 minute = minutes,
 second = seconds,
 }
 time =string.format('%02d:%02d:%02d',time.hour,time.minute,time.second)
 return time
 end
 if Input_Value == true or Input_Value == 1 then
 ValueExternalTime = grp.getvalue(AddressExternalTime) or SetDelay
 if SetSec == true then
 Multiply_Seconds = 1
 else
 Multiply_Seconds = 60
 end
 StairCaseTime = ValueExternalTime * Multiply_Seconds * SetFac
 ValueOutput = grp.getvalue(AddressOutputStatus)
 if ValueOutput == false and NightMode == false then
 grp.write(AddressOutputDay, true)
 else
 grp.write(AddressOutputNight, true)
 end
 if UseTimeLeft == true then
 if StairCaseTime > 0 then
 time = Calculate_Time(StairCaseTime)
 grp.update(AddressTimeLeft, time)
 repeat
 StairCaseTime = StairCaseTime - 1
 time = Calculate_Time(StairCaseTime)
 grp.update(AddressTimeLeft, time)
 os.sleep(1)
 until StairCaseTime == 0
 end
 else
 os.sleep(StairCaseTime)
 end
 grp.write(AddressOutputDay, false)
 elseif Input_Value == false or Input_Value == 0 then
 ValueOutput = grp.getvalue(AddressOutputStatus)
 if ValueOutput == true then
 if UseTimeLeft == true then
 time = Calculate_Time(0)
 grp.update(AddressTimeLeft, time)
 end
 grp.write(AddressOutputDay, false)
 end
 if AddressManOff == false then
 grp.write(StairCaseTime, 0)
 grp.write(AddressInput, 0)
 AddressTimeLeft:write(0,0,0)
 end
 end
 storage.delete('PID:' .. _SCRIPTNAME)
 end
 
		
	 
	
	
	
		
	Posts: 1807 
	Threads: 7 
	Joined: Jul 2015
	
 Reputation: 
121 
	
	
		Hi,
 You declare NightMode = 'x/x/x' and later you compare NightMode == false, this will not work..
 
 Use: NightMode = grp.getvalue('x/x/x')
 
 BR,
 
 Erwin
 
		
	 
	
	
	
		
	Posts: 94 
	Threads: 17 
	Joined: Jan 2020
	
 Reputation: 
2 
	
	
		 (09.05.2020, 11:44)Erwin van der Zwart Wrote:  Hi,
 You declare NightMode = 'x/x/x' and later you compare NightMode == false, this will not work..
 
 Use: NightMode = grp.getvalue('x/x/x')
 
 BR,
 
 Erwin
 Perfect, it did the trick! Thanks. 
 
Is it possible to implement a script that, after staircase time the light level dims smoothly down instead of switch to 0, without changing the dim parameters in the KNX dimmer?
	 
		
	 |