Synthetic Variables & Math with Timestamps

Hi,

For tracking the power on time of our machine, we are sending a time on variable that injects initially upon startup, and then just prior to a routine shutdown, it sends a time off variable. These are simply true values or just 1 in Ubidots. I would like to then proceed to take the difference (Time Off - Time On) to add up the total runtime of the machine. Is there a way to create a synthetic variable and do that math with the timestamp? Or does the value sent have to be a timestamp? When I send a timestamp value its in UNIX/Epoch time I believe and is in the hundreds of thousands. Looking for the best way to do this, I am sending from Node-Red btw.

Thank you,
Paul

Hello Paul,

Yes, there is a way to do math with the timestamp of the Dots through Synthetic Variables. to obtain the timestamp of the value in the synthetic variable expression editor, use:
{VAR_LABEL}.timestamp
This is explained in this article from our Help Center. Also, it’s important to note that the value given is in milliseconds.

I’d recommend that the machine sends a 1 upon startup and a 0 before the shutdown, so that you may follow the example of the section “2. Creating a Synthetic Variable using timestamp” within the mentioned article, as it is exactly what you are requesting.

I’ll be attentive in case you have any questions.

Best regards,
Sebastián

1 Like