I have voltage and current values from my PV inverter and wanted to calculate the DC power, simple P=V*I template sensor. However, as the sensor values arrive at slightly (mS) different times intermediate calculates are made, see chart. The voltage arrives first (red) and the power template sensor is recalculated (green) then the current arrives (purple) and the power is calculated again.
Now the intermediate calculation is wrong as it’s calculating power from the current voltage against the previous current and can give crazy values. I subsequently went on to calculate Inverter efficiency which uses another sensor (AC power) which you can see arrives after voltage and current so you get even more incorrect intermediate results, in my case data spikes that are over 300% in error…
Now I appreciate everything takes a finite time to arrive and be processed but I’m trying to work out a way to only calculate the value once when both input values have been updated. Is there anyway to synchronise these calculations?
Thanks, so that would mean moving all my template sensors to automations unless there’s a way of achieving the same thing in a template sensor? The big issue I still see is that the next version of the integration may deliver the AC power first, plus I haven’t checked every state change to confirm the arrival order is always the same…Like many sensors the data is sent via wireless so if a packet goes astray and is retransmitted then the order could change yet again. This seems like such a fundamental problem that I can’t believe HA hasn’t already solved it and I’m missing something…
Thanks @tom_l and @koying I knew I must be missing something, I searched on synchronisation rather than trigger and didn’t realise you could trigger a template sensor.
I guess this still doesn’t solve the problem if the sensor data doesn’t always arrive in the same order though. I’m not sure how predictable modbus over Wi-Fi is? I’ll have to try and work out a way of scanning the data arrival times and see if it is consistently in the same order…