P1 meter, trying to add net ampere sensor

On various Hardware and OS systems: pi / windows / routers / nas, etc

Moderator: leecollings

Post Reply
akamming
Posts: 394
Joined: Friday 17 August 2018 14:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

P1 meter, trying to add net ampere sensor

Post by akamming »

Hi,

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);
					}
(the difference with original code added the loglines for debugging. and added sensor number for calculating the net current)

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
However the real values in the meter are all positive:
currents.jpg
currents.jpg (74.87 KiB) Viewed 199 times
Anyone has a hint how to proceed, so the negative values are shown?
User avatar
waltervl
Posts: 5979
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: P1 meter, trying to add net ampere sensor

Post by waltervl »

Why doing this?
You can just request both ampere devices in your evcc load balancing script?

And also Domoticz (well the hardware it is running on) could be not handling P1 updates every 1 or 5 seconds!
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
akamming
Posts: 394
Joined: Friday 17 August 2018 14:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: P1 meter, trying to add net ampere sensor

Post by akamming »

waltervl wrote: Monday 04 August 2025 13:33 Why doing this?
You can just request both ampere devices in your evcc load balancing script?

And also Domoticz (well the hardware it is running on) could be not handling P1 updates every 1 or 5 seconds!
Nope, that doesn’t work. In evcc I can configurere Only 1 current device and evcc expects this to be combined Delivery and usage current.

Maybe i am wrong, but could you then send me the correct evcc config to make this work with domoticz?

Just the p1 meter every second runs fine om my pi4, I already tested

And every second is a requisite: It is used for loadbalancing, so I really need the latest p1 reading the prevent the loadbalancer kicking in too late in case of overcurrent
User avatar
waltervl
Posts: 5979
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: P1 meter, trying to add net ampere sensor

Post by waltervl »

I do not use evcc what is that?
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
akamming
Posts: 394
Joined: Friday 17 August 2018 14:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: P1 meter, trying to add net ampere sensor

Post by akamming »

waltervl wrote: Monday 04 August 2025 15:16 I do not use evcc what is that?
An energy management system which optimizes for the cheapest or most co2 friendly way of charging your car and/or home battery

https://evcc.io/
User avatar
waltervl
Posts: 5979
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: P1 meter, trying to add net ampere sensor

Post by waltervl »

Perhaps think of connecting your home P1 meter directly to the ecvv application, so without Domoticz. Or buy better hardware that is able to run Domoticz being updated every second with P1 data (20+ devices).
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
akamming
Posts: 394
Joined: Friday 17 August 2018 14:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: P1 meter, trying to add net ampere sensor

Post by akamming »

waltervl wrote: Monday 04 August 2025 16:39 Perhaps think of connecting your home P1 meter directly to the ecvv application, so without Domoticz. Or buy better hardware that is able to run Domoticz being updated every second with P1 data (20+ devices).
As stated hardware is not the issue. Pi 4b is fast enough. I am only missing a net amperage sensor.

Anyway I think I found the spot in the code where the value is made positive again, also already created a fix. Now waiting for the sun to shine to test it 😉

If it works i create a pr
User avatar
gizmocuz
Posts: 2577
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Top of the world
Contact:

Re: P1 meter, trying to add net ampere sensor

Post by gizmocuz »

Changes are adapted in the code
Quality outlives Quantity!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest