Logic Machine Forum
Comapration of hours - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Comapration of hours (/showthread.php?tid=2443)



Comapration of hours - juanbautista@domoviri.es - 28.01.2020

Hi

I am a little novice in this programming through lua.

I need to compare the current time with a specific time to start a device.

How can 3-byte communication objects be compared?

The code used but does not work for me is the following:


Code:
hora = grp.getvalue('33/0/1')--,dt.time)

log (hora)
value = grp.getvalue('33/1/21')--,dt.time)

log (value)

if hora == value then
  log ("esto funciona")
  total = hora + value
  log (total)
else
  log("ERROR")
end
 and I get the following error


Code:
Event for Hora Actual (33/0/1) 28.01.2020 16:00:34
* table:
[day]
  * number: 2
[minute]
  * number: 0
[second]
  * number: 0
[hour]
  * number: 0
[min]
  * number: 0
[sec]
  * number: 0
Event for Hora Actual (33/0/1) 28.01.2020 16:00:34
* table:
[day]
  * number: 2
[minute]
  * number: 0
[second]
  * number: 0
[hour]
  * number: 0
[min]
  * number: 0
[sec]
  * number: 0
Event for Hora Actual (33/0/1) 28.01.2020 16:00:34
* string: ERROR
Can someone please help me?

Thank you


RE: Comapration of hours - Daniel - 28.01.2020

Hi
Can you explain what problem are trying to solve? It is easier to compare os.time() You can easily read object update time and compare it with os.time.
BR


RE: Comapration of hours - juanbautista@domoviri.es - 28.01.2020

Hello Daniel
I am trying to compare the current time with a specific time to be able to perform a series of tasks.

Please, can you help me?

Thank you


RE: Comapration of hours - Daniel - 28.01.2020

Current time with what? There is a lot of different time formats so you need to be more specific.


RE: Comapration of hours - juanbautista@domoviri.es - 28.01.2020

I want to compare the current time that is type 10. 3 Byte time / day with another time (it would also be type 10. 3 Byte time / day) that the user can put on a page of the visualization to be able to start a pump.

Thank you


RE: Comapration of hours - Daniel - 28.01.2020

OK then you should compare all individual values from the table. hora.day == value.day etc..


RE: Comapration of hours - admin - 28.01.2020

Why not use schedulers for this?


RE: Comapration of hours - juanbautista@domoviri.es - 28.01.2020

I don't use the planner because the time I want to calculate comes from a formula that has a delay or advance of a preset time depending on the pump.

Thanks a lot


RE: Comapration of hours - admin - 29.01.2020

You can convert date/time table to minutes and then compare using <, > and ==
Code:
minutes = value.hour * 60 + value.min