8000 Inspelning negative power values? · Issue #109 · Leggin/dirigera · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Inspelning negative power values? #109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Vetti52 opened this issue Mar 2, 2025 · 14 comments
Open

Inspelning negative power values? #109

Vetti52 opened this issue Mar 2, 2025 · 14 comments

Comments

@Vetti52
Copy link
Vetti52 commented Mar 2, 2025

I was intended to use an Inspelning plug for power measurement at a mini PV panel. Although amps are displayed, there are no values for power (watts). Does this python setup not support negative values or is the plug not suitable for this job? I am wondering, as i have some shelly and tasmota plugs, which could easily display values, no matter, in which direction the power goes. However, at the panel location, there is not and will not be wifi available, but Zigbee is there. So, Inspelning would be the device of choice, if the data could be extracted properly.

@Leggin
Copy link
Owner
Leggin commented Mar 5, 2025

Hey, code-wise negative values are not a problem. Sadly I couldn't get my hands on the inspelning yet so I don't know if they work with negative values.

@h0n24
Copy link
h0n24 commented Mar 5, 2025

My wild guess is that it's not showing constant power reading. So you have to convert it.

I'd try time integral of power formula. And you also need to measure time between two measurements t0 and t1. I'm assuming the initial value you're getting is in amperes.

image

@h0n24
Copy link
h0n24 commented Mar 5, 2025

It seems that they were solving similar issues here, the solution seems to be in the appended zip file in the state_power_division_item, but I can't test it.

dresden-elektronik/deconz-rest-plugin#7948 (comment)

@Vetti52
Copy link
Author
Vetti52 commented Mar 5, 2025

Well, I now started to use the dirigera HACS integration, which is based on this code. So, I know, that there are 7 sensor entities read from Dirigera for the Inspelning plug:

current_active_power (W)
current_amps (A)
current_voltage (V)
energy_consumed_at_last_reset (kWh)
total_energy_consumed (kWh) # which i use in the Energy dashboard
time_energy_consumed_last_updated
time_of_last_energy_reset

The last two i ignore.
So far, all plugs work pretty nice.

But when I tried to measure my PV input, there were no values for (W), but for (kWh). So I currenty get stuck with my powerline connected measuring plug. However, this is old and there is no replacement, when in will be broken somewhen.
The deconz rest plugin may be a good idea, but will need someone, who knows, how to merge it into this solution (and more nicely, adopt to the HACS dirigera integration afterwards). At least, it indicates, that in principle, it should work.

@h0n24
Copy link
h0n24 commented Mar 5, 2025

I've heard some devices were faulty.

If your device isn’t giving the correct total energy readings, one workaround is to compute the instantaneous active power using following formula—provided you have an accurate value for the power factor. Once you have the instantaneous power, you can integrate it over time to get the energy consumed.

If your load is purely resistive, cos(phi) is 1, and the formula simplifies to P = U * I. For reactive loads (inductive or capacitive), cos(phi) will be less than 1.

For example, if you’re sampling every Delta t seconds, the energy in watt‑hours (Wh) over that period is approximately:

image

U is current_voltage in your data
I is current_amps in your data

This integration converts the power (in watts) into energy (in watt‑hours) by accounting for the time factor (since 1 hour = 3600 seconds).

@h0n24
Copy link
h0n24 commented Mar 5, 2025

Here's an example python code (generated by AI, can't test it as I don't have the device) to give you the idea:

import math

def calculate_active_power(current_voltage, current_amps, power_factor=1.0):
    """
    Calculate instantaneous active power (in watts).
    
    Parameters:
        current_voltage (float): Voltage in volts (V)
        current_amps (float): Current in amps (A)
        power_factor (float): Power factor (cos(phi)), defaults to 1.0
        
    Returns:
        float: Active power in watts (W)
    """
    return current_voltage * current_amps * power_factor

# Example readings from the device
current_voltage = 226.0   # in volts
current_amps = 2.5        # in amps (example value)
power_factor = 1.0        # assuming a purely resistive load

# Calculate the instantaneous power
active_power = calculate_active_power(current_voltage, current_amps, power_factor)
print("Calculated Active Power: {:.2f} W".format(active_power))

# Suppose you want to calculate the energy consumption over a time interval.
# Energy (Wh) = Power (W) * Time (h)
# For a time interval given in seconds, you first convert it to hours.
time_interval_seconds = 300  # e.g., 5 minutes
time_interval_hours = time_interval_seconds / 3600

energy_consumed_wh = active_power * time_interval_hours
print("Energy Consumed over {} seconds: {:.4f} Wh".format(time_interval_seconds, energy_consumed_wh))

@Vetti52
Copy link
Author
Vetti52 commented Mar 5, 2025

Some of my Tasmota plugs had to be calibrated using a good old 60W resistive bulb. Others, like those from Athom, were pretty fine precalibrated. I don‘t know, if the Inspelning plugs need calibration.
Nevertheless, when calculating W from V and A, it should result in the same value as shown in W, right?
And, if, in case of a PV input, no W is given, I could try to „recalculate“ it from the data obtained from A and V values?
Well, I don‘t know, if the input from the PV power inverter into the house grid resembles a resistive load environment. So, first, I can not prove, if the data are fine, and, second, I have no idea, how to integrate this calculation into my home assistant setup, because i am not good enough with python like home assistant programming.

@h0n24
Copy link
h0n24 commented Mar 5, 2025

Yeah, as you're saying, it should result the same value as shown in current_active_power (W).

From what youre mentioning, I'd start with the asumption that your house grid resembles a resistive load environment, and set power factor cos(phi) to 1.

Here's the simple way how to integrate your own Python script into Home Assistant: https://www.home-assistant.io/integrations/python_script/

Plus you can always ask in https://github.com/home-assistant/core/issues

PS: another unrelated idea that can hypothetically help - I'd check if the firmware for Inspelning is the latest. Although I dunno how to force update devices in the new Ikea Smart app (it was possible in the old one), it's atleast possible to check if the firmware is the latest in the device info (device info is hidden in the wrench icon on the top right when selecting the device).

@Vetti52
Copy link
Author
Vetti52 commented Mar 10, 2025

My first simple approach was, to create a helper group to calculate the product of two sensors. That works, although i could not add a unit of measurement at the UI.

Well, it looks obvious, that the calculation differs to that of the sensor, just when use the Inspelning plug in a regular output manner:
Actual data retrieved from the sensor:
0.049 A
235 V
4.2 W (this value is the only one shown in the IKEA home smart app also)

Calculated from the helper:
11.5

It looks obvious, that the watts from the sensor are pretty different to the calculated product V*A.

So, now I am somewhat confused.

@h0n24
Copy link
h0n24 commented Mar 10, 2025

It's probably not reflecting the sensor's measured active power because it ignores the power factor.

It could be that the load is highly reactive, and only about 36,5 % of the apparent power.

cos(phi)= P / V*I = 4.2 / 11.5 ~= 0.365

I'd try another calculations with the power factor.

(And of course there's always chance that the device is faulty, but let's not assume that yet)

@Vetti52
Copy link
Author
Vetti52 commented Mar 10, 2025

I am going to perform my calibration routine, which I did for all of my tasmota plugs:
I have a merely good calibrated Voltcraft plug, into which I will plug the Inspelning plug, and with this I use an oldfashioned 60w bulb. I have 60w for good, checked with the Voltcraft plug, Voltage is always very trustful from the Voltcraft, and amps are calculated like P/V=I. A tasmota plug can be corrected for the amp value, so that the power factor (given by tasmota) should be close to 1 afterwards. I don‘t know, if there is a correction routine at Inspelning. Otherwise I should modify my UI helper, if this is possible (I doubt that!). Looong way to get away from my good old powerline plug.

@Vetti52
Copy link
Author
Vetti52 commented Mar 11, 2025

Just to present the result of my plan:
The Inspelning plug performs pretty well with a 60W light bulb. Although, there are slight differences, when comparing V*A versus W values. So, it would not result in a Power Factor if 1, but pretty close to.
I addition, I have seen, that besides of Watts, the total energy consumption (kWh) is also displayed in the Ikea Home Smart app. This value is also displayed, when the plug is used inversely as an inlet measuring device for my mini PV panel, when watts equal to zero. The kWh value does not need any conversion, to be taken as power input source in the HA Energy dashboard. Thus, having the Watts, is nice to see, but not necessary for Energy monitoring, finally.
Curious, why Ikea using Inspelning in reverse mode shows Volts and Amps and kWh, but not Watts. May be an issue?
It would moreover be nice to correct the power factor as well.

But I do not have any connection to Ikea, to offer these suggestions.

@h0n24
Copy link
h0n24 commented Mar 12, 2025

Here's another idea:

It is possible to download APK version of Ikea's Home Smart app from:

https://www.apkmirror.com/apk/inter-ikea-systems-b-v/ikea-home-smart/

Then it's possible to unpack it, then because the code will be obfuscated, it would have to be deobfuscated, and after that it would be possible to check what formula directly IKEA uses.

But it's very tedious work.

Communication wise - the Inspelning sensor only sends data that you've seen in this repository.

@Vetti52
Copy link
Author
Vetti52 commented Mar 12, 2025

For me it is beyond of my skills even to write python code. I can hardly read it and understand only parts of it. So, deobfuscation will be a no go.
In addition, I think, that the power factor and the calculation of the data is not done in the home smart app but in the device firmware. I had heard of a firmware update for Inspelning plugs, which corrected wrongly calculated data previously. This was cured with the actual firmware 2.4.45, which is installed at all of my Inspelning devices. I still doubt, that this firmware is ok now. At least, when looking at the calculatd V*A values compared to the regular watts, provided in regular output mode, I see differences. The differences increase, the lower the amps are. So, I can currently see 11W calculated vs. 9W displayed.
Thus, I hesitate to trust in the power consumption data of Inspelning currently. Maybe, further updates will improve the devices. If not, it is 10€ garbage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
0