Getting smooth values from onewire to calculate correct difference from two onewire-measurements

i have 2 temperature sensors “vorlauf” and “ruecklauf” which delivering nice smooth graphs as green and orange shown. All values were “onchange” saved to influxdb Persistence.

I dont want to sample faster than 60s
The blue curve is my problem. This is the calculated difference between the first two values which is calculated by rule triggered if one of both values changes.
Because it is sampling the values not on same time this is like saw teeth. Both valuemeasurements can differ until 30 seconds…

Is there a methode to sync both measurements? Or any other idea to get more correct calculations? As better the difference is calculated as better then the from that calculated cop from heatpump.

This is going to be tricky.

One approach could be to trigger on one sensor, create a timer and in that timer wait for the second sensor to change and only then calculate the difference.

It might work to not base the calculation on the two values changing but on a cron schedule. Every minute it calculates the delta no matter how the sensor values have changed.

If you notice one sensor is always reported first, trigger the rule to do the calculation only on the second sensor.

You could adjust it so that both sensor values and the calculation are saved always at the same time. You’d have to remove those sensors from your persistence config and create a rule that runs periodically to save the current values and delta using the .persist action.

Hi Rich,
i switched off the persistence of one item HeizungVorlauf_Temperature to test it. Then i entered a javascript for testing the persist methode:
i started manually a view times, but no new values are saved to persistence. Is this the right way i tried it?


oh yes, this works now :slight_smile: Thanks for the hint.
I got the wrong hint from Persistence | openHAB and <item>.persist

the solution now by methode suggested by @rlkoshak makes the calculated difference really better usable for cop calculation:

if someone needs a code-snippet for calculating difference temperature in heating and saving values synchronous:

//remember switch off persistence for items
var now =;
vorlaufpersist  =items.HeizungVorlauf_Temperature.history.historicState(now.minusSeconds(1)).numericState;
vorlauf         =items.HeizungVorlauf_Temperature.numericState;
ruecklauf       =items.HeizungRuecklauf_Temperature.numericState;

if (vorlauf!=vorlaufpersist || ruecklauf!=ruecklaufpersist){//onchange?? then persist items by function synchron
 (spreizung<15)?items.heizung_spreizung.sendCommandIfDifferent (spreizung + " K"):null;//write only plausible values


You shouldn’t need the parseFloat. .numericState is already a float.

1 Like

…i tested without and it works fine, correct.