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
#55
Here is my solution for a patio heater, controlled by wall switch but with a widget created in touch so the customer can set the timer as active or not and alter the timer length.

Code:
-- Event script attached to status object --

local state = event.getvalue()

now = os.time()

-- Group adress for time object, 2-byte unsigned
newtimer = grp.getvalue('1/1/1')
updatetimer = newtimer * 60
timer = updatetimer + now

-- Group adress for determining if timer is active or not, 1-bit
activeTimer = grp.getvalue('1/1/2')

if activeTimer == true then
    if state == true then
      storage.set('timerObject1', timer)
      script.enable('timerObject1(res)')
      log('Timer for timerObject1 is activated')
    else
      storage.set('timerObject1', 0)
      script.disable('timerObject1(res)')
    end
else
end


-------------- Script below is a resident script ----------------------------------
-- Resident script, set as inactive and 10 second execution time
-- Name this script the same as above (timerObject1(res))

time = os.time()

endTime = storage.get('timerObject1', 0)

if endTime == 0 then
 
else
    if time > endTime then
    -- Group adress for the SW-objekt
      grp.write('1/1/0', false)
    log('Timer for timerObject1 has expired, is has been turned off')
    end
end

Not as pretty as a simple script for all 10, but with more flexibility. Of course, all variable for storage and resident scripts need to have their named changed for this to work with more than 1 object.

Edit:

Here is what the widget looks like, and also attached. Please translate as needed.

   

Attached Files
.json   widget.json (Size: 1.36 KB / Downloads: 9)
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 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

Forum Jump: