I have a use case for a net ampere sensor (to send the amperages to evcc for loadbalancing purposes).
P1 meter already has a "Current" and a "Current Delivery" sensor. However what i want to add a sensor, which combines the two.
So e.g. Current is (8.6A, 0A, 0A) and Current Delivery is (0A, 2A, 2A) the value of (8.6A, -2A, -2A): Delivery is substract from normal current.
I managed to get it to work with a dzventz script, but since i have to send value every seconds, this gives way too much CPU load.. (already caused me some sync issue, cause net amperage calculated too late due to this)
So since it's holiday and i had some time, i tried to add it to the P1 code (P1meterbase.cpp), and changed the code to:
Code: Select all
if (
(m_voltagel1 != -1)
&& (m_voltagel2 != -1)
&& (m_voltagel3 != -1)
)
{
// The ampere is rounded to whole numbers and therefor not accurate enough
// Therefor we calculate this ourselfs I=P/U, I1=(m_power.m_powerusel1/m_voltagel1)
float I1 = avr_usage[0] / m_voltagel1;
float I2 = avr_usage[1] / m_voltagel2;
float I3 = avr_usage[2] / m_voltagel3;
SendCurrentSensor(0, 255, I1, I2, I3, "Current L1/L2/L3");
Log(LOG_STATUS, "Sending Current L1/L2/L3: %.2f/%.2f/%.2f", I1, I2, I3);
// Calculate net current (usage-delivery)
float net_I1 = I1;
float net_I2 = I2;
float net_I3 = I3;
//Do the same for delivered
if (m_powerdell1 || m_powerdell2 || m_powerdell3)
{
I1 = avr_deliv[0] / m_voltagel1;
I2 = avr_deliv[1] / m_voltagel2;
I3 = avr_deliv[2] / m_voltagel3;
SendCurrentSensor(1, 255, I1, I2, I3, "Delivery Current L1/L2/L3");
Log(LOG_STATUS, "Sending Delivery Current L1/L2/L3: %.2f/%.2f/%.2f", I1, I2, I3);
// calculate net current (usage-delivery)
net_I1 = net_I1 - I1;
net_I2 = net_I2 - I2;
net_I3 = net_I3 - I3;
}
// Send net current sensor
SendCurrentSensor(2, 255, net_I1, net_I2, net_I3, "Net Current L1/L2/L3");
Log(LOG_STATUS, "Sending Net Current L1/L2/L3: %.2f/%.2f/%.2f", net_I1, net_I2, net_I3);
}
When testing, in the code seems to work fine, cause it does exactly what i want it to do:
Code: Select all
2025-08-04 13:04:58.060 Status: Slimme Meter: Sending Current L1/L2/L3: 8.59/0.00/0.00
2025-08-04 13:04:58.060 Status: Slimme Meter: Sending Delivery Current L1/L2/L3: 0.00/1.49/1.18
2025-08-04 13:04:58.060 Status: Slimme Meter: Sending Net Current L1/L2/L3: 8.59/-1.49/-1.18
2025-08-04 13:05:03.062 Status: Slimme Meter: Sending Current L1/L2/L3: 8.68/0.00/0.00
2025-08-04 13:05:03.062 Status: Slimme Meter: Sending Delivery Current L1/L2/L3: 0.00/1.50/1.18
2025-08-04 13:05:03.062 Status: Slimme Meter: Sending Net Current L1/L2/L3: 8.68/-1.50/-1.18