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.

Display time of object
#15
(23.12.2021, 09:32)admin Wrote: You will need two scripts for this.
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).

I have a question, i try to use this script more times
i change the names value, key and out on both of the script on all places.
so both scripts use different names.

but if i trigger the seconds action, the first timer start for 0 again, some know what i do wrong?

my first event script for Laptop Table
Code:
Laptop_Table = event.getvalue()        --'0 WCD Woonkamer - laptoplader eettafel (tm)'
ontime_Laptop_Table = 'ontime'
output_Laptop_Table = '32/1/201'    --'Laptop eettafel [timer on]'        

if Laptop_Table then
  if not storage.get(ontime_Laptop_Table) then
    storage.set(ontime_Laptop_Table, os.time())
    grp.update(output_Laptop_Table, '0 m')
  end
else
  storage.delete(ontime_Laptop_Table)
  grp.update(output_Laptop_Table, '')
end


my first Resident script for Laptop Table
Code:
ontime_Laptop_Table = 'ontime'
output_Laptop_Table = '32/1/201'            --'Laptop eettafel [timer on]'    

time = storage.get(ontime_Laptop_Table)
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 .. ' minuten'
  grp.update(output_Laptop_Table, res)
end

my second event script for Kitchen
Code:
Kitchen = grp.getvalue('1/4/4')            --'0 Verl. Kitchen (tm)'
ontime_Kitchen = 'ontime'
output_Kitchen = '32/1/202'            --'Kitchen [timer on]'    

if Kitchen then
  if not storage.get(ontime_Kitchen) then
    storage.set(ontime_Kitchen, os.time())
    grp.update(output_Kitchen, '0 m')
  end
else
  storage.delete(ontime_Kitchen)
  grp.update(output_Kitchen, '')
end

my first Resident script for Kitchen
Code:
ontime_Kitchen = 'ontime'
output_Kitchen = '32/1/202'            --'Kitchen [timer on]'

time = storage.get(ontime_Kitchen)
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 .. minutes2 .. ' minuten'
  grp.update(output_Kitchen, res)
end


another thing,
for me it looks like line 1 and line 4 of the Resident script look like do the same thing, or m i wrong?
Reply


Messages In This Thread
Display time of object - by Nir70 - 22.12.2021, 17:50
RE: Display time of object - by admin - 23.12.2021, 08:41
RE: Display time of object - by Nir70 - 23.12.2021, 08:47
RE: Display time of object - by admin - 23.12.2021, 09:32
RE: Display time of object - by Nir70 - 23.12.2021, 11:22
RE: Display time of object - by Dré - 27.12.2021, 15:03
RE: Display time of object - by admin - 23.12.2021, 11:46
RE: Display time of object - by Nir70 - 23.12.2021, 12:21
RE: Display time of object - by admin - 23.12.2021, 12:30
RE: Display time of object - by Dré - 24.12.2021, 15:49
RE: Display time of object - by khalil - 26.12.2021, 08:28
RE: Display time of object - by Nir70 - 23.12.2021, 14:49
RE: Display time of object - by admin - 23.12.2021, 14:52
RE: Display time of object - by Nir70 - 23.12.2021, 16:50
RE: Display time of object - by admin - 24.12.2021, 08:51
RE: Display time of object - by Nir70 - 27.12.2021, 20:25
RE: Display time of object - by admin - 28.12.2021, 08:31
RE: Display time of object - by Dré - 28.12.2021, 12:34
Display time of object - PCU heat - by Nir70 - 29.12.2021, 15:59
RE: Display time of object - by admin - 29.12.2021, 16:04
RE: Display time of object - by Nir70 - 29.12.2021, 16:19
RE: Display time of object - by admin - 29.12.2021, 16:35
RE: Display time of object - by Dré - 30.12.2021, 13:24
RE: Display time of object - by admin - 05.04.2022, 13:02
RE: Display time of object - by Rauschentofft - 03.11.2022, 23:35
RE: Display time of object - by admin - 04.11.2022, 08:26
RE: Display time of object - by Rauschentofft - 04.11.2022, 09:26
RE: Display time of object - by nmedalacabeza - 01.01.2023, 18:31
RE: Display time of object - by admin - 02.01.2023, 08:47
RE: Display time of object - by nmedalacabeza - 02.01.2023, 19:21
RE: Display time of object - by Daniel - 03.01.2023, 08:58
RE: Display time of object - by nmedalacabeza - 04.01.2023, 08:54
RE: Display time of object - by admin - 04.01.2023, 08:56
RE: Display time of object - by nmedalacabeza - 04.01.2023, 10:50
RE: Display time of object - by admin - 05.01.2023, 08:13
RE: Display time of object - by nmedalacabeza - 07.01.2023, 17:28
RE: Display time of object - by nmedalacabeza - 21.01.2023, 20:35
RE: Display time of object - by admin - 23.01.2023, 08:16
RE: Display time of object - by nmedalacabeza - 23.01.2023, 16:28
RE: Display time of object - by admin - 23.01.2023, 16:32
RE: Display time of object - by nmedalacabeza - 23.01.2023, 16:54
RE: Display time of object - by admin - 24.01.2023, 07:10

Forum Jump: