Synchronizing multiple graph times

I have a DS18B20 and a DHT11 logging the temperature of my fish tank and room temp/humidity in 3 graphs. How do I synchronize the graphs (set for a 1 day X axis) so that they all update at the same time?TelePeriod is set for 300 on both sensors.

You could store all values in context, then every minute (or hour or whatever), using an inject node, gather all values from context into a single object - tada

I was hoping that some magic parameter could be set to keep the times the same, not doing more gyrations to get what I want. Maybe I'll try to run both sensors off the same WemosD1 mini and see what that does. Thanks for the response.

That'll work too - however, much more work than simply writing a little code.

I mean, literally something like...

Store current values by topic name in flow context...

let thisSensorID = msg.topic;
let sensorValueCache = flow.get("sensorValueCache") || {};
let sensor = sensorValueCache[thisSensorID] || {}
sensor.value = msg.payload;
sensor.time = new Date();
sensorValueCache[thisSensorID] = sensor;
flow.set("sensorValueCache", sensorValueCache);

When inject fires - get values out of cache & send to graph

let sensorValueCache = flow.get("sensorValueCache") || {};
let sensor1 = sensorValueCache["my/sensors/DS18B20"] || {};
let sensor2 = sensorValueCache["my/sensors/DHT11"] || {};
//build object...
let msgForGraph = {
  payload: [sensor1.value, sensor2.value]
}
return msgForGraph 

Of course i have no idea what format you need the data (this demo would output the values as an array in msg.payload.

Steve - the delay node - when set into rate limit mode - can be set to handle multiple topics - then send all of them in one go every x seconds... so as long as each input has it's own topic you will get the latest value of each that has arrived at every "tick". No coding necessary.

1 Like

I'm no programmer, so the delay node idea seems the best way to go if I can figure out how to implement it. As for the software approach being faster, I'm a 70 year old hardware guy and it would take 30 seconds after the soldering iron heats up to change it to one Wemos. I'll revisit this after I let it run for 24 hours and see what my graphs look like then. I'm in no hurry - trapped here like most of you.

Hey Mike, each to their own. :+1:

I'm like the opposite - I can do the code off the top of my head quicker than it takes the soldering iron heat up :smiley:

@dceejay - hadn't even considered a solution like that. Good to know.

Do you really want to delay the output to one graph for up to five minutes just so they all stay in sync? Why?

to reduce the number of point in the chart for the day ? It's only temperature after all...

here is a simple example using the delay node.

[{"id":"f036159.0db89e8","type":"inject","z":"3ead5d77.6a6672","name":"","topic":"air-temp","payload":"20","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":730,"y":280,"wires":[["b35d675.a1fd698"]]},{"id":"b35d675.a1fd698","type":"delay","z":"3ead5d77.6a6672","name":"","pauseType":"timed","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"minute","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"x":930,"y":320,"wires":[["8efe4516.02e1f8"]]},{"id":"8efe4516.02e1f8","type":"debug","z":"3ead5d77.6a6672","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1110,"y":320,"wires":[]},{"id":"2929d95a.9ae816","type":"inject","z":"3ead5d77.6a6672","name":"","topic":"air-hum","payload":"68","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":720,"y":320,"wires":[["b35d675.a1fd698"]]},{"id":"34b1a727.981f68","type":"inject","z":"3ead5d77.6a6672","name":"","topic":"tank-temp","payload":"12","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":730,"y":360,"wires":[["b35d675.a1fd698"]]}]

The requirement I thought is not to reduce the number of points, just to delay the one that gets its data point first so that both charts are updated at the same moment. They are coming in at 5 minute intervals but not synced.

Two ways to sync
a) delay all until whole set of data is collected and send
b) store all incoming always and fire on every input where last incoming is updated, others have stored data.

Version a creates graph with synced data points but timing is wrong. Also amount of data is reduced to minimum.
Version b has correct timing but creates many additional data points which may harm performance.

I put a fixed delay node of 5 minutes on all graph flows. Now the times match, so thanks to all. The displayed values are a bit squirrely though, so I may have a flaky sensor. I just found another one in my stash so I'll wire it up and see if gives a more stable output.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.