-- ** Staircase logic with external time object and retriggering on input object Version 3.2 ** ---- ****************************** Created by Erwin van der Zwart **************************** ---- ************************************** SET PARAMETERS ************************************ ---- Set input addressAddressInput = '32/1/20 '-- 01. 1 bit (boolean)-- Set output addressAddressOutput = '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 MinutesSetSec = true-- Set to false for Minutes-- Set factor delay (Multiplies Delay)SetFac = 1-- Logic can be turned of by value 0Off_by_Value_Zero = false-- ************************************** END PARAMETERS ************************************ ---- *************************** DON'T CHANGE ANYTHING UNDER THIS LINE ************************ --Input_Value = event.getvalue()
ifOff_by_Value_Zero == falseand (Input_Value == falseorInput_Value == 0) thenreturnelsetpid = storage.get('PID:' .. _SCRIPTNAME)
iftpid == nilthenpid = os.getpid()
storage.set('PID:' .. _SCRIPTNAME, pid)
elsepid = os.getpid()
storage.set('PID:' .. _SCRIPTNAME, pid)
os.kill(tpid, signal.SIGKILL)
endfunctionCalculate_Time(StairCaseTime)
ifStairCaseTime > (86400 -1) thenStairCaseTime = (86400 -1)
endlocalhours = math.floor(StairCaseTime / 3600 % 24)
localminutes = math.floor(StairCaseTime / 60 % 60)
localseconds = 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)
returntimeendifInput_Value == trueorInput_Value == 1thenValueExternalTime = grp.getvalue(AddressExternalTime) orSetDelayifSetSec == truethenMultiply_Seconds = 1elseMultiply_Seconds = 60endStairCaseTime = ValueExternalTime * Multiply_Seconds * SetFacValueOutput = grp.getvalue(AddressOutput)
ifValueOutput == falsethengrp.write(AddressOutput, true)
endifUseTimeLeft == truethenifStairCaseTime > 0thentime = Calculate_Time(StairCaseTime)
grp.update(AddressTimeLeft, time)
repeatStairCaseTime = StairCaseTime - 1time = Calculate_Time(StairCaseTime)
grp.update(AddressTimeLeft, time)
os.sleep(1)
untilStairCaseTime == 0endelseos.sleep(StairCaseTime)
endgrp.write(AddressOutput, false)
elseifInput_Value == falseorInput_Value == 0thenValueOutput = grp.getvalue(AddressOutput)
ifValueOutput == truethenifUseTimeLeft == truethentime = Calculate_Time(0)
grp.update(AddressTimeLeft, time)
endgrp.write(AddressOutput, false)
endendstorage.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.
-- ** Staircase logic with external time object and retriggering on input object Version 3.2 ** ---- ****************************** Created by Erwin van der Zwart **************************** ---- ************************************** SET PARAMETERS ************************************ ---- Set input addressAddressInput = '21/1/40'-- 01. 1 bit (boolean)-- Set output addressAddressOutput = '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 MinutesSetSec = true-- Set to false for Minutes-- Set factor delay (Multiplies Delay)SetFac = 1-- Logic can be turned of by value 0Off_by_Value_Zero = false-- ************************************** END PARAMETERS ************************************ ---- *************************** DON'T CHANGE ANYTHING UNDER THIS LINE ************************ --blocking = grp.getvalue('40/1/40')
ifnotblockingthenreturnendInput_Value = event.getvalue()
ifOff_by_Value_Zero == falseand (Input_Value == falseorInput_Value == 0) thenreturnelsetpid = storage.get('PID:' .. _SCRIPTNAME)
iftpid == nilthenpid = os.getpid()
storage.set('PID:' .. _SCRIPTNAME, pid)
elsepid = os.getpid()
storage.set('PID:' .. _SCRIPTNAME, pid)
os.kill(tpid, signal.SIGKILL)
endfunctionCalculate_Time(StairCaseTime)
ifStairCaseTime > (86400 -1) thenStairCaseTime = (86400 -1)
endlocalhours = math.floor(StairCaseTime / 3600 % 24)
localminutes = math.floor(StairCaseTime / 60 % 60)
localseconds = 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)
returntimeendifInput_Value == trueorInput_Value == 1thenValueExternalTime = grp.getvalue(AddressExternalTime) orSetDelayifSetSec == truethenMultiply_Seconds = 1elseMultiply_Seconds = 60endStairCaseTime = ValueExternalTime * Multiply_Seconds * SetFacValueOutput = grp.getvalue(AddressOutput)
ifValueOutput == falsethengrp.write(AddressOutput, true)
endifUseTimeLeft == truethenifStairCaseTime > 0thentime = Calculate_Time(StairCaseTime)
grp.update(AddressTimeLeft, time)
repeatStairCaseTime = StairCaseTime - 1time = Calculate_Time(StairCaseTime)
grp.update(AddressTimeLeft, time)
os.sleep(1)
untilStairCaseTime == 0endelseos.sleep(StairCaseTime)
endgrp.write(AddressOutput, false)
elseifInput_Value == falseorInput_Value == 0thenValueOutput = grp.getvalue(AddressOutput)
ifValueOutput == truethenifUseTimeLeft == truethentime = Calculate_Time(0)
grp.update(AddressTimeLeft, time)
endgrp.write(AddressOutput, false)
endendstorage.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?
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..
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..
ValueOutput = grp.getvalue(AddressOutput)
ifValueOutput == falsethengrp.write(AddressOutput, true)
end
Into:
Code:
1
grp.write(AddressOutput, true)
This way the output is not checked on state
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
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...
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...
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?