Hi folks,
sorry for taking so long to report back - I have been busy with some other things and not had time to investigate this properly until now.
With some tinkering I have managed to do all the processing I needed inside emoncms, as follows:
Inputs (both from inverter data)
- DC Power flow from battery (+ve discharge) in W
- Remaining power left in battery - integer readout measured in 0.1kWh
Processing
DC Power
- Power to kWh → feed (‘frombat_dc_kwh’)
Remaining power left in battery
- Log to feed ‘battpowerleft’
- rate of change (logged to 'powerleft_rate)
- if > -1 skip next
- Absolute Value = 1
- multiply by feed ‘frombat_dc_kwh’
- if ZERO skip next
- Log to feed ‘frombat_dc_kwh_ref’
New virtual feed ‘Battery Capacity Remaining’
- source feed ‘battpowerleft’
- multiply by 0.1
- add source feed ‘frombat_dc_kwh_ref’
- subtract source feed ‘frombat_dc_kwh’
Ok, how does it work?
The DC power from batter converted to kWh allows me to keep a fine track of power flow to/from the battery, but will tend to drift due to losses, etc.
Every time the remaining power left in battery value from the BMS changes (equally, the pecentage left would do here), the rate calculation is not the normal value of zero, instead it is -1 or +1 ( assuming no jumps of more than 1 unit).
If the rate calculation is negative, the combination of ‘if > -1 skip next’ and ‘abs value 1’ sets it to 1 - that means the value is then zero for no change and 1 for the battery power left just changed.
Multiply that by the latest ‘frombat_dc_kwh’ figure, means that the value being processed is either zero if the battery level has not changed, or the latest accumulated kwh value if it has changed. Then we only log to the ref feed if non-zero.
That way we have two feeds - frombat_dc_kwh which is the accumulated power flow to/from the battery, and ‘frombat_dc_kwh_ref’, which is the value of that feed when the battery power level last changed. The difference between the two is the power into (or out of) the battery since the battery power level last changed, so the virtual feed can combine the 3 values to give a more exact estimate of the power in the battery.
I would like to do the rate of change calculation without having to log to a feed, but I can’t see a way to do that (and I also can’t seem to use a memory feed for the rate).
I will also try to tinker with the virtual feed to see if I can limit the offset to between -0.1 and +0.1 kWh, but that’s just fine tuning.
cheers,
Robin