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
#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:
-- ** 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


Messages In This Thread
Remaining time or counter - by Tokatubs - 15.12.2018, 21:29
RE: Remaining time or counter - by Tokatubs - 16.12.2018, 00:51
RE: Remaining time or counter - by AlexLV - 16.12.2018, 16:09
RE: Remaining time or counter - by AlexLV - 16.12.2018, 20:59
RE: Remaining time or counter - by Tokatubs - 18.12.2018, 19:35
RE: Remaining time or counter - by AlexLV - 19.12.2018, 22:14
RE: Remaining time or counter - by Thomas - 20.12.2018, 10:13
RE: Remaining time or counter - by admin - 20.12.2018, 10:54
RE: Remaining time or counter - by Tokatubs - 20.12.2018, 22:27
RE: Remaining time or counter - by Daniel - 21.12.2018, 08:42
RE: Remaining time or counter - by Tokatubs - 21.12.2018, 09:28
RE: Remaining time or counter - by Daniel - 21.12.2018, 12:18
RE: Remaining time or counter - by Daniel - 21.12.2018, 13:11
RE: Remaining time or counter - by Tokatubs - 21.12.2018, 22:54
RE: Remaining time or counter - by AlexLV - 24.12.2018, 17:00
RE: Remaining time or counter - by CHOUAIBOU - 25.12.2018, 13:24
RE: Remaining time or counter - by AlexLV - 26.12.2018, 09:05
RE: Remaining time or counter - by AlexLV - 06.01.2019, 23:05
RE: Remaining time or counter - by admin - 29.01.2020, 11:28
RE: Remaining time or counter - by admin - 29.01.2020, 13:34
RE: Remaining time or counter - by AlexLV - 30.01.2020, 07:14
RE: Remaining time or counter - by victor.back - 09.05.2020, 09:20
RE: Remaining time or counter - by AlexLV - 30.01.2020, 12:41
RE: Remaining time or counter - by admin - 09.08.2022, 08:20
RE: Remaining time or counter - by admin - 09.08.2022, 10:09
RE: Remaining time or counter - by Novodk - 26.05.2023, 19:46
RE: Remaining time or counter - by Novodk - 27.05.2023, 07:02
RE: Remaining time or counter - by admin - 27.05.2023, 06:59
RE: Remaining time or counter - by admin - 27.05.2023, 07:06
RE: Remaining time or counter - by Novodk - 27.05.2023, 07:18
RE: Remaining time or counter - by admin - 29.05.2023, 08:29
RE: Remaining time or counter - by Novodk - 29.05.2023, 08:52
RE: Remaining time or counter - by FatMax - 29.05.2023, 09:04
RE: Remaining time or counter - by Novodk - 01.06.2023, 16:26
RE: Remaining time or counter - by admin - 11.09.2024, 13:40

Forum Jump: