Time-shift to synchronize two sensors

Dear community,

Is there a way (e.g. like using sensor-type filter) to delay one sensor e.g. 20 seconds to get it synchronized with another sensor?

I’m trying to figure out my home power usage by subtracting the power produced by my solar panels (SolarEdge Modbus integration) from the power used/delivered to the grid (DSMR integration). This works quite well, except that there is an offset between the two sensors of about 10~20 seconds. On a clear day with some clouds, there are large fluctuations in

I tried to use the low pass filter integration and this smoothens out the largest spikes, but it would much better if I could first synchronize the two sensors. Is there a way to apply a filter or so such that I can combine two signals of which one is 20 seconds ago?

I attached a plot of what I have now. The red line is unfiltered total power usage, the blue line with low-pass filter. The green is measured by DSMR and the yellow the solar production from SolarEdge. Ideally the red line is quite smooth with some steps caused by apparatus switching.

You could try creating an SQL sensor to query the database for the state 20 seconds ago:

I can’t help with the actual SQL query syntax.

Hi Tom,

Thanks for the suggestion. Although this might indeed be possible to work, it sounds to me that it would be highly inefficient. Every datapoint then means running a separate SQL query to fetch it from, or should I not be worried about that? Anyway I will try it out. Perhaps a filter-like solution is more like a feature request?

A time shifted filter would have to store and retrieve data points for the length of the time offset as well, though I suppose that could be done in memory rather than in the recorder.

Do feel free to raise a feature request.

I think you can try this work around. You need to create a mqtt sensor in HA. Then you have to install nodered. In node red you can offset the response of the sensor or sync the sensor value with the other sensor using the message queue node.

image

In the first flow we have to give the bypass interval of the simple queue node as 20000 milliseconds for it fire after 20s but this doesn’t guarantee syncing.
With the second flow, the payload is released only when the solar sensor value is updated. For this we have to use the trigger payload.

Hope this works for you. If you have any questions please do ask.

2 Likes

I know this is an old thread, but I had this same issue and came across a useful lovelace-compatible chart card:

I’ve got two sources for monitoring power around the house - one from my inverter which uses serial over TCP to RTU and a shelly EM sensor. The Shelly sensors are super quick and there’s a ~12 second disparity with the timestamps from the serial interface. This chart lets you add an offset to data directly within the YAML, as shown below. No more additional template sensors / MQTT / node red for what should be a pretty straight-forward ask.