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.
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.
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.