This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Remaining time or counter
#21
(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:
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
-- ** 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
Reply
#22
Chouaibou, BIG THANKS Smile

Now it finally working!!! You just forgot insert input address, so below all should work fineSmile

I wish to all Happy New Year Smile

Alex

Code:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
-- ** 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
Reply
#23
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
Reply
#24
Code:
12345678
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.
Reply
#25
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:
123456
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.
Reply
#26
Code:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
-- ** 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.
Reply
#27
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:
12345
blocking = grp.getvalue('0/0/1') if not blocking then   return end
Reply
#28
(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:
12345
blocking = grp.getvalue('0/0/1') if not blocking then   return end
Thanks Admin, it works perfectly! Smile

Code:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
-- ** 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?
Reply
#29
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:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
-- ** 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
Reply
#30
Hi Erwin,

this is super script Smile 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 Smile 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
Reply
#31
Hi,

If you send a 1 again on the trigger object it should reset the time and start counting from start.

BR,

Erwin
Reply
#32
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..
Reply
#33
(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:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
-- ** 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!
Reply
#34
(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?
Reply
#35
Hi,

Change line 80-83:
Code:
1234
ValueOutput = grp.getvalue(AddressOutput) if ValueOutput == false then   grp.write(AddressOutput, true) end
Into:
Code:
1
grp.write(AddressOutput, true)
This way the output is not checked on state

BR,

Erwin
Reply
#36
(02.05.2020, 22:05)Erwin van der Zwart Wrote: Hi,

Change line 80-83:
Code:
1234
ValueOutput = grp.getvalue(AddressOutput) if ValueOutput == false then   grp.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

Code:
1234567
   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?
Reply
#37
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
Reply
#38
(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:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
-- ** 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
Reply
#39
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
Reply
#40
(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?
Reply


Forum Jump: