RE: Remaining time or counter - CHOUAIBOU - 25.12.2018
(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
RE: Remaining time or counter - AlexLV - 26.12.2018
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
RE: Remaining time or counter - AlexLV - 06.01.2019
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
RE: Remaining time or counter - davidchispas - 29.01.2020
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.
RE: Remaining time or counter - admin - 29.01.2020
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.
RE: Remaining time or counter - davidchispas - 29.01.2020
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.
RE: Remaining time or counter - admin - 29.01.2020
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
RE: Remaining time or counter - davidchispas - 29.01.2020
(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?
RE: Remaining time or counter - Erwin van der Zwart - 29.01.2020
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
RE: Remaining time or counter - AlexLV - 30.01.2020
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
RE: Remaining time or counter - Erwin van der Zwart - 30.01.2020
Hi,
If you send a 1 again on the trigger object it should reset the time and start counting from start.
BR,
Erwin
RE: Remaining time or counter - AlexLV - 30.01.2020
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..
RE: Remaining time or counter - davidchispas - 30.01.2020
(29.01.2020, 22:05)Erwin van der Zwart Wrote: 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 Thank you so much for the correction! Now it works perfectly! It is a great script!
RE: Remaining time or counter - victor.back - 02.05.2020
(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?
RE: Remaining time or counter - Erwin van der Zwart - 02.05.2020
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
RE: Remaining time or counter - victor.back - 07.05.2020
(02.05.2020, 22:05)Erwin van der Zwart Wrote: 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 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 * SetFac
ValueOutput = 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?
RE: Remaining time or counter - Erwin van der Zwart - 07.05.2020
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
RE: Remaining time or counter - victor.back - 09.05.2020
(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
RE: Remaining time or counter - Erwin van der Zwart - 09.05.2020
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
RE: Remaining time or counter - victor.back - 10.05.2020
(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?
|