23.12.2021, 09:32
You will need two scripts for this.
1. Event script mapped to control or status object if the load:
2. Scheduled script that runs every minute:
32/1/5 is the object that shows the load ON time, set data type to 250 byte string. If you need multiple status outputs then use a unique storage key for each load (ontime in this example).
1. Event script mapped to control or status object if the load:
Code:
value = event.getvalue()
key = 'ontime'
out = '32/1/5'
if value then
if not storage.get(key) then
storage.set(key, os.time())
grp.update(out, '0m')
end
else
storage.delete(key)
grp.update(out, '')
end
2. Scheduled script that runs every minute:
Code:
key = 'ontime'
out = '32/1/5'
time = storage.get(key)
if time then
delta = os.time() - time
minutes = math.floor(delta / 60)
hours = math.floor(minutes / 60)
minutes = minutes % 60
if hours > 0 then
res = hours .. 'h '
else
res = ''
end
res = res .. minutes .. 'm'
grp.update(out, res)
end
32/1/5 is the object that shows the load ON time, set data type to 250 byte string. If you need multiple status outputs then use a unique storage key for each load (ontime in this example).