This object is in archive! 

Problem with calculations of time values

Takstein shared this question 6 years ago
Need Answer

Hi!


I have made a function for detecting a kitchen extract fan being on for too long, and give a push notification (and switch off power suplly in next step) if we forget it. I have made the function work part from one thing: i cannot seem to be able to subtract time values?


i use the function timeof (now) and add that to a var1 . I then add timeof(now) at a later stage to var2. I then want to use the result of var2-var1 but it is always 0. I see in the push notification that var 1 is e.g. 80000178 anv var2 is 79005367. I assume this is in milliseconds. But when i try to subtract one from the other i always get 0.0....


Any ideas?

Replies (2)

photo
1

wow, thats seems overly complicated to simply run a timer. Why so complex?

Why not just have a rule that is trigger by the fan turning on (or power consumption level if thats what you need), a wait timer, refresh all and check if fan is still on, if so turn it off?

Im not sure if the variables can be added and subtracted etc, like this, their uses arent entirely clear to me.

photo
1

Hi Adrian!


Thanks for your feedback. I am aware it is a little complex, it is merely to have control of the running times in between states (i have programmed like this before in PLC's), and there's more to come in the different section in the code, I just wanted to get it to work first. I will take your idea into consideration though!


I guess my real issue is why i cannot add/subtract two variables.. i think that should work like this, if not why do we have the +- operators?

photo
1

I have a similar problem and I haven't discovered yet how to solve it.


Anyhow, have you tried doing the difference of variables instead on function time(now)-variable?

photo
1

Hi!

yeah, i tried to assign time(now) to a variable, then time(now) later on to another variable, checked I had values i both variables and tried to subtract them, but still no joy..

photo
2

Check out this post.

https://community.zipato.com/topic/a-method-for-creating-manipulable-time-and-date-values


The date-time values in the Zipabox are Unix values and apparently too long to be stored in variables. This is why it never works.


I have found that the largest value variables will accept is a Unix date-time value converted to measure hours rather than seconds (see post).


Wanting to store and do calculations with date-time values is entirely reasonable. It's absurd that we can't do this. I've had the Zipabox for over two years and Zipato has never shown even a glimmer of interest in fixing this glaring deficiency.

photo
1

I use the date-time meter extensively now and it works very well. Ask for more details if you need them.

photo
1

Thanks mate! This definitely explains the reason for the behavior. I tried to pull out only the minute section to test in my code and can confirm it works then.. I agree that this is functionality that should be supported by Zipato, since the variables can hold float values they should be able to calculate with them as well....


I'll take you up on the offer for more details when i (probably) get stuck. BR

photo
1

No problem.

photo
Leave a Comment
 
Attach a file