Logic Machine Forum
Display time of object - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Visualization (https://forum.logicmachine.net/forumdisplay.php?fid=9)
+--- Thread: Display time of object (/showthread.php?tid=3769)

Pages: 1 2 3


Display time of object - Nir70 - 22.12.2021

Hello

Is it possible to display the operation time of an object (lamp, air conditioner) in minutes on screen  Cry . Thanks


RE: Display time of object - admin - 23.12.2021

Do you mean the time since the last ON command or the overall running time?


RE: Display time of object - Nir70 - 23.12.2021

(23.12.2021, 08:41)admin Wrote: Do you mean the time since the last ON command or the overall running time?

Hello

yes, the time since the last ON command . Thanks


RE: Display time of object - admin - 23.12.2021

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


RE: Display time of object - Nir70 - 23.12.2021

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

Small request Can I display seconds? Thanks


RE: Display time of object - admin - 23.12.2021

Yes, set display mode to value or icon/value.


RE: Display time of object - Nir70 - 23.12.2021

(23.12.2021, 11:46)admin Wrote: Yes, set display mode to value or icon/value.

Hello

It works, but it shows me the time only after shutdown ( send 0) , is it possible to view the time in real time?


RE: Display time of object - admin - 23.12.2021

The scheduled script should update the value each minute, check that it is set up correctly


RE: Display time of object - Nir70 - 23.12.2021

I checked does not update in real time, only I send a shutdown (0) it displays.


RE: Display time of object - admin - 23.12.2021

What is the data type of control object that is mapped to an event script?


RE: Display time of object - Nir70 - 23.12.2021

1 bit lamp, what do you mean?


RE: Display time of object - admin - 24.12.2021

1 bit is ok because it won't work correctly for non-Boolean values. Are you sure the value is not inverted because sending Off should put an empty string as the run-time value. Check if you have modified the scripts in any way.


RE: Display time of object - Dré - 24.12.2021

(23.12.2021, 12:30)admin Wrote: The scheduled script should update the value each minute, check that it is set up correctly

I tried this scipt too and use it now for 28 minutes and it is counting.

did you post the seconds script in a 'scheduled script' ?


RE: Display time of object - khalil - 26.12.2021

Thanks admin
The Script work fine for me and I add last run interval when value become false instead of nothing 
Code:
value = event.getvalue()
key = 'ontime'
out = '40/1/7'

if value then
  if not storage.get(key) then
    storage.set(key, os.time())
    grp.update(out, '0m')
  end
else
  Last_Run = grp.getvalue(out)
  time = os.date(' %a, %d/%m',time)
  grp.update(out, 'Last Run: '..Last_Run..' In'..time)
  storage.delete(key)
end



RE: Display time of object - Dré - 27.12.2021

(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?


RE: Display time of object - Nir70 - 27.12.2021

Hello Thank you for the help It also works with the last time it was activated. Heart


RE: Display time of object - admin - 28.12.2021

@Dré, you need to change the storage key ('ontime'), not the variable name:
Code:
Kitchen = grp.getvalue('1/4/4')            --'0 Verl. Kitchen (tm)'
ontime_Kitchen = 'ontime_kitchen'
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

Code:
ontime_Kitchen = 'ontime_kitchen'
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

If using multiple timers you can combine the scheduled/resident scripts into one.


RE: Display time of object - Dré - 28.12.2021

Thanks Admin & khalil.

i update the script so i have now a time like '00:05' and i also use the last time actived, what Khalil added.


My updated Resident script, thanks for both of you, without i could't make it.
Code:
ontime_Laptop_Table = 'ontime_Laptop_Table'
output_Laptop_Table = '32/1/201'            --'Laptop tafel [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
  minutes = string.format("%02d", minutes)
       
  if hours > 0 then
    res = hours -- .. ': '
  else
    res = '00:'
  end
  hours = string.format("%02d", hours)
  time_online = hours ..':'..minutes
      
  grp.update(output_Laptop_Table, time_online)
end

Yes and i also can use now more timers of this.


Display time of object - PCU heat - Nir70 - 29.12.2021

Hello

I noticed whan  scrap is working. The processor is working hard, and the heat in the processor is rising a lot, is this a normal condition? Why is this happening? Best regards


RE: Display time of object - admin - 29.12.2021

Make sure you use a scheduled script that runs every minute not a resident script with low or 0 sleep time.