-
Notifications
You must be signed in to change notification settings - Fork 39
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
Sampling skew for IKEA INSPELNING in ElectricalMeasurement class #388
Comments
Can you record a debug log of the attribute reports? We set up attribute reporting on the device instead of polling and rely on the device to report changes. Ideally it would report both attributes at once but it seems to not be able to do this properly. Is your device running the latest firmware? |
If you tell me how, I'm sure I could?
Where do I find this code?
Yes, this is clearly a race. |
You can enable debug logs on the integration page in HA, click the ZHA integration, then "enable debug logging".
The IKEA plugs will already match this (notice polling is set to zha/zha/application/platforms/sensor/__init__.py Lines 590 to 598 in cb03c2f
All other plugs will be polled, as they'll match this: zha/zha/application/platforms/sensor/__init__.py Lines 661 to 668 in cb03c2f
|
Thanks - will do in the morning.
Oh, interesting, so the plug is supposed to push updates regularly? Does the integration specify which attributes should be pushed, or does the device decide? I guess the other way this could work is if the power attribute is also updated each time a divisor/multiplier update arrives. |
OK, it seems that the device is pushing changes, and usually they arrive in the order
but occasionally they're swizzled like here:
which causes an erroneous sample of 105.2W, rather than 1052W. Would it be reasonable to update the sample value on both |
I was afraid that something like this would be required by the device. It would be best for the device to batch the two into a single attribute report but it seems to sometimes send multiple. What is the maximum difference you see between the two attribute reports? A second or two is totally manageable but if it's much longer this will unfortunately complicate things. |
I would say it usually sends individual updates, but sometimes it does batch them:
I don't have a whole lot of data yet, the one sample I was looking at had a delay of 1.55s. |
Yes, I have automatic firmware updates enabled, the current firmware version is 0x02040045. |
Regarding your second log: 2025-03-05 08:00:35.631 DEBUG (MainThread) [zigpy.zcl] [0xCFE7:1:0x0b04] Attribute report received: active_power=1453, ac_power_divisor=1
2025-03-05 08:00:38.600 DEBUG (MainThread) [zigpy.zcl] [0xCFE7:1:0x0b04] Attribute report received: ac_power_divisor=10 What is the actual power draw of the device when the report is received? Is it 1453W or 145.3W? |
The element consumes around 1500W when it's on, whereas consumption is otherwise around 1.5W, so here the consumption was 1453W. Now that I'm staring at this, I wonder if perhaps this might be more or less working as intended. The problem could be that the duty cycle of the element is approaching the sampling rate of the power sensor? Here's an image of the current and power graphs over 30 minutes or so. ... time passes ... The current graph is clearly also missing samples, but it's not nearly as bad as the power graph. It also doesn't have samples that are off by precisely an order of magnitude. It is odd to see that there is one current sample where the power sample is good. Perhaps the firmware is straddling sampling intervals between current and power in those cases? Apparently the energy metering chip is in INSPELNING is a HLW8110. According to the data sheet the active power register has these possible update rates:
So the sampling rate of the energy metering chip is at least a comfortable factor of 100 faster than the ~30s cycle time of the element. Ideally the firmware would read a consistent set of values at the end of each sampling interval, but maybe that's not what's happening. IDK, I think if the |
K, so I captured a bunch of data, drilled into the logs and what I found was ... unexpected. The incorrect samples correspond to the cases where
Note that it seems the |
#389 should fix this problem. I don't currently have a load for my plug that rapidly switches between 0W and 1000W+ so it's a little difficult to test what the correct timeout should be for waiting before emitting a state change. |
Thanks! Also, time to buy an espresso machine, methinks. Mine is an ancient E61 heat exchange model. In addition to testing smart plugs, it also makes great coffee. |
A hairdryer worked well enough: 0W -> 1700W at the click of a button! Give the above PR a try if you have time and let me know if the timing works for you. I've tuned it to a second above what I see with my device: 2025-03-05 13:45:50.651 DEBUG (MainThread) [zigpy.zcl] [0xD282:1:0x0b04] Attribute report received: active_power=6
2025-03-05 13:45:51.328 DEBUG (MainThread) [zigpy.zcl] [0xD282:1:0x0702] Attribute report received: current_summ_delivered=57356
2025-03-05 13:45:53.220 DEBUG (MainThread) [zigpy.zcl] [0xD282:1:0x0b04] Attribute report received: rms_voltage=1274
2025-03-05 13:45:53.782 DEBUG (MainThread) [zigpy.zcl] [0xD282:1:0x0b04] Attribute report received: rms_current=10
# This has no other update and would be emitted alone
2025-03-05 13:45:55.739 DEBUG (MainThread) [zigpy.zcl] [0xD282:1:0x0b04] Attribute report received: active_power=5
2025-03-05 13:45:58.238 DEBUG (MainThread) [zigpy.zcl] [0xD282:1:0x0b04] Attribute report received: rms_voltage=1275
2025-03-05 13:45:58.754 DEBUG (MainThread) [zigpy.zcl] [0xD282:1:0x0b04] Attribute report received: rms_current=10
# These would be batched together (1.1s apart)
2025-03-05 13:46:00.646 DEBUG (MainThread) [zigpy.zcl] [0xD282:1:0x0b04] Attribute report received: active_power=819
2025-03-05 13:46:01.722 DEBUG (MainThread) [zigpy.zcl] [0xD282:1:0x0b04] Attribute report received: ac_power_divisor=1
2025-03-05 13:46:03.203 DEBUG (MainThread) [zigpy.zcl] [0xD282:1:0x0b04] Attribute report received: rms_voltage=1218
2025-03-05 13:46:03.737 DEBUG (MainThread) [zigpy.zcl] [0xD282:1:0x0b04] Attribute report received: rms_current=13946
# These would be batched together (0.9s apart)
2025-03-05 13:46:04.700 DEBUG (MainThread) [zigpy.zcl] [0xD282:1:0x0b04] Attribute report received: ac_power_divisor=10
2025-03-05 13:46:05.673 DEBUG (MainThread) [zigpy.zcl] [0xD282:1:0x0b04] Attribute report received: active_power=2147
2025-03-05 13:46:08.189 DEBUG (MainThread) [zigpy.zcl] [0xD282:1:0x0b04] Attribute report received: rms_voltage=1272
2025-03-05 13:46:08.782 DEBUG (MainThread) [zigpy.zcl] [0xD282:1:0x0b04] Attribute report received: rms_current=10 This would effectively delay all reports by 2s. Unrelated, but we maybe should change the reporting configuration for |
So I captured nearly 2 hours of reports, and scrubbing through them, I believe I never see the This is obviously only for INSPELNING, I don't know anything about other smart plugs, alas. I see a lot of
but occasionally there are "spurious" divisor updates, like e.g. here
|
|
I'll take your word for it. I don't know the first thing about ZigBee. Does it guarantee delivery? Does it guarantee in-order delivery? |
No for both 😄. The only guarantee we have (somewhat) is that the same packet will not be received twice. From your log:
This sort of timing is not something I accounted for and requires a slight rewrite of the PR, since it may be possible for two |
Ok, then there is no guarantee that a property derived from more than one attribute will be correct, unless all the attributes are reported in a single packet. At least the |
So, I dove into this rathole and it seems the protocol has everything needed to provide in-order and guaranteed delivery (as much as any network protocol does), namely frame sequence numbers and confirmations. I couldn't quickly find any information on whether the standards mandates this for e.g. commands and attribute updates, but it would (IMHO) be odd if it didn't? |
There are two layers of ACKs and we already send the ones we can, the others are handled by the firmware. There's no way to actually signal to a device that a packet has been missed unfortunately. Reordering is something that I didn't really consider, however! Looking at my log, roughly 20 of the last 50,000 packets were received out of order. For the vast majority of devices this has no impact because we match requests to responses via their TSN but I think we could use this information to detect packet loss, do some slight reordering, or inform entities like this one of missed updates. |
I don't suppose you could point me towards the code in question? I'm academically curious about how all of this works now 😃 .
Right, I guess ultimately the only reasonable way to remedy a lost command or attribute update is to start the device over and rebuild all the state?
Interesting. I have a ConBee II and I just skimmed through the serial protocol docs. Somehow I assumed the gateway would do a lot more than what it does. Seems it just passes valid frames right up the chain. I guess a lot of my questions are answered in the logs I already captured... |
Default responses (NWK-level ACKs) are here: https://github.com/zigpy/zigpy/blob/c54c8876e5b1f3fc1ff8a71ba57c25c8bd17436a/zigpy/zcl/__init__.py#L467-L504. Attribute reports set the |
Thanks! |
I have a couple of IKEA INSPELNING smart plugs, one of which is hooked up to my espresso machine. When the element is on, it consumes ~1500W, whereas when it's not on, the consumption is <100W. This causes the
power_divider
value to toggle between 1 and 10 with the elements duty cycle, which is roughly once every 30s.This in turn makes it very noticeable that the
ac_power_divider
/ac_power_multiplier
attributes are not sampled synchronously with theactive_power
attribute as it frequently causes samples that are off by an order of magnitude. This happens when the wrong divider/multiplier (divider in my case) is used to scale the read power value.The only way to fix this that I can think of is to sample the 2 or 3 attributes that define the instantaneous power measurement in a single ZigBee request in the ElectricalMeasurement class. This will probably also help general performance of HA and the ZigBee network.
This issue may apply more generally to the PolledSensor class, though I don't have other examples of the problem.
The text was updated successfully, but these errors were encountered: