AlexxIT / SonoffLAN

Control Sonoff Devices with eWeLink (original) firmware over LAN and/or Cloud from Home Assistant
https://github.com/AlexxIT/Blog
MIT License
2.74k stars 416 forks source link

Sonoff SPM - 2nd module not reporting power #1366

Open ajcollett opened 8 months ago

ajcollett commented 8 months ago

Hello @AlexxIT

First off, thanks for the work on this integration!

I see quite a few past issues about power reports and so on, and I hope I've covered my bases here!

I'm using auto mode, and can view everything OK in ewelink.

I have disabled energy, voltage and current entities to cleanup the output, power reporting is the main thing I'm after, and the problem I face.

I have 2 GD32-SM4 modules. The system is on firmware 1.3.0 but the same issues were present on the previous firmware too.

Okay, so the issue is that I only get data from ab300006f7 (f7 from here on). I get very scant replies from ab300006f8 (f8 from here on).

Here, see the below output from "known logs", the integration requests to the cloud, but only f7 responds.

2024-03-21 21:35:02 [D] ab300006f7 <= Local3 | 192.168.8.14:8081 | {'current_00': 12, 'voltage_00': 23920, 'actPow_00': 640, 'reactPow_00': 2715, 'apparentPow_00': 2858} | 28677
2024-03-21 21:35:03 [D] ab300006f7 <= Cloud3 | {'current_00': 12, 'voltage_00': 23920, 'actPow_00': 640, 'reactPow_00': 2715, 'apparentPow_00': 2858} | None
2024-03-21 21:35:06 [D] ab300006f8 => Cloud4 | {'uiActive': {'outlet': 1, 'time': 60}} | 1711049706985
2024-03-21 21:35:07 [D] ab300006f7 => Cloud4 | {'uiActive': {'outlet': 1, 'time': 60}} | 1711049707087
2024-03-21 21:35:08 [D] ab300006f7 <= Local3 | 192.168.8.14:8081 | {'current_01': 0, 'voltage_01': 0, 'actPow_01': 0, 'reactPow_01': 0, 'apparentPow_01': 0} | 28678
2024-03-21 21:35:08 [D] ab300006f7 <= Cloud3 | {'current_01': 0, 'voltage_01': 0, 'actPow_01': 0, 'reactPow_01': 0, 'apparentPow_01': 0} | None
2024-03-21 21:35:11 [D] ab300006f8 => Cloud4 | {'uiActive': {'outlet': 2, 'time': 60}} | 1711049711987
2024-03-21 21:35:12 [D] ab300006f7 => Cloud4 | {'uiActive': {'outlet': 2, 'time': 60}} | 1711049712089
2024-03-21 21:35:12 [D] ab300006f7 <= Local3 | 192.168.8.14:8081 | {'current_02': 0, 'voltage_02': 23951, 'actPow_02': 45, 'reactPow_02': 40, 'apparentPow_02': 84} | 28679
2024-03-21 21:35:13 [D] ab300006f7 <= Cloud3 | {'current_02': 0, 'voltage_02': 23951, 'actPow_02': 45, 'reactPow_02': 40, 'apparentPow_02': 84} | None
2024-03-21 21:35:16 [D] ab300006f8 => Cloud4 | {'uiActive': {'outlet': 3, 'time': 60}} | 1711049716989
2024-03-21 21:35:17 [D] ab300006f7 => Cloud4 | {'uiActive': {'outlet': 3, 'time': 60}} | 1711049717090
2024-03-21 21:35:18 [D] ab300006f7 <= Local3 | 192.168.8.14:8081 | {'current_03': 19, 'voltage_03': 23975, 'actPow_03': 3279, 'reactPow_03': 3268, 'apparentPow_03': 4647} | 28680
2024-03-21 21:35:19 [D] ab300006f7 <= Cloud3 | {'current_03': 19, 'voltage_03': 23975, 'actPow_03': 3279, 'reactPow_03': 3268, 'apparentPow_03': 4647} | None
2024-03-21 21:35:31 [D] ab300006f8 => Cloud4 | {'uiActive': {'outlet': 0, 'time': 60}} | 1711049731985
2024-03-21 21:35:32 [D] ab300006f7 => Cloud4 | {'uiActive': {'outlet': 0, 'time': 60}} | DDoS | 1711049732086
2024-03-21 21:35:32 [D] ab300006f7 <= Local3 | 192.168.8.14:8081 | {'current_00': 12, 'voltage_00': 23930, 'actPow_00': 543, 'reactPow_00': 2711, 'apparentPow_00': 2827} | 28681
2024-03-21 21:35:33 [D] ab300006f7 <= Cloud3 | {'current_00': 12, 'voltage_00': 23930, 'actPow_00': 543, 'reactPow_00': 2711, 'apparentPow_00': 2827} | None
2024-03-21 21:35:36 [D] ab300006f8 => Cloud4 | {'uiActive': {'outlet': 1, 'time': 60}} | 1711049736986
2024-03-21 21:35:37 [D] ab300006f7 => Cloud4 | {'uiActive': {'outlet': 1, 'time': 60}} | 1711049737087
2024-03-21 21:35:38 [D] ab300006f7 <= Local3 | 192.168.8.14:8081 | {'current_01': 0, 'voltage_01': 0, 'actPow_01': 0, 'reactPow_01': 0, 'apparentPow_01': 0} | 28682
2024-03-21 21:35:39 [D] ab300006f7 <= Cloud3 | {'current_01': 0, 'voltage_01': 0, 'actPow_01': 0, 'reactPow_01': 0, 'apparentPow_01': 0} | None
2024-03-21 21:35:41 [D] ab300006f8 => Cloud4 | {'uiActive': {'outlet': 2, 'time': 60}} | 1711049741988
2024-03-21 21:35:42 [D] ab300006f7 => Cloud4 | {'uiActive': {'outlet': 2, 'time': 60}} | 1711049742089
2024-03-21 21:35:42 [D] ab300006f7 <= Local3 | 192.168.8.14:8081 | {'current_02': 0, 'voltage_02': 23971, 'actPow_02': 0, 'reactPow_02': 0, 'apparentPow_02': 0} | 28683
2024-03-21 21:35:42 [D] ab300006f7 <= Local3 | 192.168.8.14:8081 | {'current_02': 0, 'voltage_02': 23971, 'actPow_02': 0, 'reactPow_02': 0, 'apparentPow_02': 0} | 28683
2024-03-21 21:35:43 [D] ab300006f7 <= Cloud3 | {'current_02': 0, 'voltage_02': 23971, 'actPow_02': 0, 'reactPow_02': 0, 'apparentPow_02': 0} | None
2024-03-21 21:35:46 [D] ab300006f8 => Cloud4 | {'uiActive': {'outlet': 3, 'time': 60}} | 1711049746990
2024-03-21 21:35:47 [D] ab300006f7 => Cloud4 | {'uiActive': {'outlet': 3, 'time': 60}} | DDoS | 1711049747091
2024-03-21 21:35:48 [D] ab300006f7 <= Local3 | 192.168.8.14:8081 | {'current_03': 19, 'voltage_03': 23985, 'actPow_03': 3268, 'reactPow_03': 3249, 'apparentPow_03': 4625} | 28684
2024-03-21 21:35:49 [D] ab300006f7 <= Cloud3 | {'current_03': 19, 'voltage_03': 23985, 'actPow_03': 3268, 'reactPow_03': 3249, 'apparentPow_03': 4625} | None
2024-03-21 21:36:01 [D] ab300006f8 => Cloud4 | {'uiActive': {'outlet': 0, 'time': 60}} | 1711049761986
2024-03-21 21:36:02 [D] ab300006f7 => Cloud4 | {'uiActive': {'outlet': 0, 'time': 60}} | DDoS | 1711049762087
2024-03-21 21:36:02 [D] ab300006f7 <= Local3 | 192.168.8.14:8081 | {'current_00': 12, 'voltage_00': 23653, 'actPow_00': 636, 'reactPow_00': 2672, 'apparentPow_00': 2816} | 28685
2024-03-21 21:36:02 [D] ab300006f7 <= Cloud3 | {'current_00': 12, 'voltage_00': 23653, 'actPow_00': 636, 'reactPow_00': 2672, 'apparentPow_00': 2816} | None
2024-03-21 21:36:06 [D] ab300006f8 => Cloud4 | {'uiActive': {'outlet': 1, 'time': 60}} | 1711049766988
2024-03-21 21:36:07 [D] ab300006f7 => Cloud4 | {'uiActive': {'outlet': 1, 'time': 60}} | 1711049767089
2024-03-21 21:36:08 [D] ab300006f7 <= Local3 | 192.168.8.14:8081 | {'current_01': 0, 'voltage_01': 0, 'actPow_01': 0, 'reactPow_01': 0, 'apparentPow_01': 0} | 28686
2024-03-21 21:36:09 [D] ab300006f7 <= Cloud3 | {'current_01': 0, 'voltage_01': 0, 'actPow_01': 0, 'reactPow_01': 0, 'apparentPow_01': 0} | None
2024-03-21 21:36:11 [D] ab300006f8 => Cloud4 | {'uiActive': {'outlet': 2, 'time': 60}} | 1711049771989
2024-03-21 21:36:12 [D] ab300006f7 => Cloud4 | {'uiActive': {'outlet': 2, 'time': 60}} | 1711049772090
2024-03-21 21:36:12 [D] ab300006f7 <= Local3 | 192.168.8.14:8081 | {'current_02': 0, 'voltage_02': 23695, 'actPow_02': 0, 'reactPow_02': 0, 'apparentPow_02': 0} | 28687
2024-03-21 21:36:13 [D] ab300006f7 <= Cloud3 | {'current_02': 0, 'voltage_02': 23695, 'actPow_02': 0, 'reactPow_02': 0, 'apparentPow_02': 0} | None
2024-03-21 21:36:16 [D] ab300006f8 => Cloud4 | {'uiActive': {'outlet': 3, 'time': 60}} | 1711049776990
2024-03-21 21:36:17 [D] ab300006f7 => Cloud4 | {'uiActive': {'outlet': 3, 'time': 60}} | 1711049777091
2024-03-21 21:36:18 [D] ab300006f7 <= Local3 | 192.168.8.14:8081 | {'current_03': 19, 'voltage_03': 23710, 'actPow_03': 3245, 'reactPow_03': 3248, 'apparentPow_03': 4602} | 28688

Please let me know if I can provide any further info. Please also find debug logs from the main unit, and both modules.

sonoff-8d397396bb2885eafc38053d11c44564-Device0006f8-c9586ddd90c6107a6263222ba2394104.json sonoff-8d397396bb2885eafc38053d11c44564-Device0006f7-6d764384adb02074260df635efe21dde.json sonoff-8d397396bb2885eafc38053d11c44564-SPM-Main House-aba1dcf6164b309786758ad5550f1698-1.json

ajcollett commented 8 months ago

So, I have a theory that the SPM main unit only responds to one request in a span of time.

I can sometimes get the f8 module to respond if I restart the integration with new config, or use the ewelink app, or something else that offsets the requests.

I see the integration sends cloud "UI active" messages to f7 and f8 at the same time. Is there a way I can make it wait a half second between requests?

I'm going to try disable f7, and see if f8 then reliably sends data.

ajcollett commented 8 months ago

Okay so even if I disable all the entities related to f7, and the device, and restart HA, the sonoff integration still asks the cloud to ping f7. So I'm not sure what else I can try.

AlexxIT commented 7 months ago

I don't know why this is happening. I don't have these devices.

ajcollett commented 7 months ago

Thanks @AlexxIT for the response. I know it's not easy to debug something you can't actually use!

Is there a way I can disable the integration from polling the one sub-device? Then I can try and see if the behavior changes if there's only f7/f8.

I think that I would be willing to give you remote access too, if you are willing to go to that effort.

AlexxIT commented 7 months ago

Do it in the code

https://github.com/AlexxIT/SonoffLAN/blob/a54bcb8c31107f81d6010e8d6d047d71bf629ef9/custom_components/sonoff/core/ewelink/__init__.py#L320-L354

ajcollett commented 7 months ago

Ah! Thank you for pointing me there. I will have a go and see if I can get any useful results.

I see there is a section for SPM for local queries, but I read in the docs that some devices don't support local update.

Am I correct in saying that the SPM devices don't support local only mode? Is DIY mode supported?

AlexxIT commented 7 months ago

Old devices support only cloud updates. Some new devices support local updates. You can see all of them in the code above

ajcollett commented 7 months ago

Okay @AlexxIT I think I have something.

Looking at the debug logs I attached above, the main SPM unit says local connection is possible.

E.g.

"local": true, "localtype": "meter",

But for the sub devices these values are null. Debug also attached in the original post.

So even though the SPM unit supports LAN communication, it's never used because the sub devices are considered cloud only.

I tested this by adding some logging in above line 361 to print out whether cloud was true or not.

https://github.com/AlexxIT/SonoffLAN/blob/a54bcb8c31107f81d6010e8d6d047d71bf629ef9/custom_components/sonoff/core/ewelink/__init__.py#L360-L364

It always prints out True.

So I'm now going to force local communication and see what happens...

ajcollett commented 7 months ago

Okay, so forcing the code to use LAN doesn't work because host: is also null.

So I forced the host to be the same as the parent device, and it now gives me:

2024-04-09 20:59:18 [W] >>>>>>> Cloud mode is True, setting it to False.
2024-04-09 20:59:18 [W] >>>>>>> Cloud mode is True, setting it to False.
2024-04-09 20:59:18 [D] ab300006f8 => Local4 | 192.168.8.14:8081 | {'uiActive': {'outlet': 0, 'time': 60}} <= {'sequence': '1712689158432', 'encrypt': True, 'seq': 0, 'error': 422}
2024-04-09 20:59:19 [D] ab300006f7 => Local4 | 192.168.8.14:8081 | {'uiActive': {'outlet': 0, 'time': 60}} <= {'sequence': '1712689158433', 'encrypt': True, 'seq': 0, 'error': 422}
2024-04-09 20:59:23 [W] >>>>>>> Cloud mode is False, setting it to False.
2024-04-09 20:59:23 [D] ab300006f8 => Local4 | 192.168.8.14:8081 | {'uiActive': {'outlet': 1, 'time': 60}} <= {'sequence': '1712689163454', 'encrypt': True, 'seq': 0, 'error': 422}
2024-04-09 20:59:24 [W] >>>>>>> Cloud mode is False, setting it to False.
2024-04-09 20:59:24 [D] ab300006f7 => Local4 | 192.168.8.14:8081 | {'uiActive': {'outlet': 1, 'time': 60}} <= {'sequence': '1712689164483', 'encrypt': True, 'seq': 0, 'error': 422}
2024-04-09 20:59:28 [W] >>>>>>> Cloud mode is False, setting it to False.
2024-04-09 20:59:28 [D] ab300006f8 => Local4 | 192.168.8.14:8081 | {'uiActive': {'outlet': 2, 'time': 60}} <= {'sequence': '1712689168474', 'encrypt': True, 'seq': 0, 'error': 422}
2024-04-09 20:59:29 [W] >>>>>>> Cloud mode is False, setting it to False.
2024-04-09 20:59:29 [D] ab300006f7 => Local4 | 192.168.8.14:8081 | {'uiActive': {'outlet': 2, 'time': 60}} <= {'sequence': '1712689169503', 'encrypt': True, 'seq': 0, 'error': 422}
2024-04-09 20:59:33 [W] >>>>>>> Cloud mode is False, setting it to False.
2024-04-09 20:59:33 [D] ab300006f8 => Local4 | 192.168.8.14:8081 | {'uiActive': {'outlet': 3, 'time': 60}} <= {'sequence': '1712689173492', 'encrypt': True, 'seq': 0, 'error': 422}
2024-04-09 20:59:34 [W] >>>>>>> Cloud mode is False, setting it to False.
2024-04-09 20:59:34 [D] ab300006f7 => Local4 | 192.168.8.14:8081 | {'uiActive': {'outlet': 3, 'time': 60}} <= {'sequence': '1712689174524', 'encrypt': True, 'seq': 0, 'error': 422}

So clearly I'm not doing this right. Any ideas? Does the SPM need to be in DIY mode first?

AlexxIT commented 7 months ago

Looks like you right. There is code for detecting local mode in another function:

https://github.com/AlexxIT/SonoffLAN/blob/a54bcb8c31107f81d6010e8d6d047d71bf629ef9/custom_components/sonoff/core/ewelink/__init__.py#L106-L113

Unfortunately I don't have this devices for local test.

AlexxIT commented 7 months ago

Reopen issue if this fix not helps https://github.com/AlexxIT/SonoffLAN/releases/tag/v3.7.0

ajcollett commented 7 months ago

Hello @AlexxIT

Thanks! I appreciate you working blindly with this.

We have progress, it's trying to communicate locally, but we're not there yet:

2024-04-17 20:40:43 [D] ab300006f7 => Cloud4 | {'uiActive': {'outlet': 0, 'time': 60}} | DDoS | 1713379243280
2024-04-17 20:40:45 [D] ab300006f7 <= Local3 | 192.168.8.14:8081 | {'current_00': 10, 'voltage_00': 23368, 'actPow_00': 0, 'reactPow_00': 2265, 'apparentPow_00': 2273} | 101490
2024-04-17 20:40:45 [D] ab300006f7 <= Cloud3 | {'current_00': 10, 'voltage_00': 23368, 'actPow_00': 0, 'reactPow_00': 2265, 'apparentPow_00': 2273} | None
2024-04-17 20:40:48 [E] ab300006f8 => Local4 |  | {'uiActive': {'outlet': 1, 'time': 60}}|  File "/config/custom_components/sonoff/core/ewelink/local.py", line 192, in send|    host = device["host"]|           ~~~~~~^^^^^^^^|KeyError: 'host'|
2024-04-17 20:40:48 [D] ab300006f8 => Cloud4 | {'uiActive': {'outlet': 1, 'time': 60}} | 1713379248182
2024-04-17 20:40:48 [E] ab300006f7 => Local4 |  | {'uiActive': {'outlet': 1, 'time': 60}}|  File "/config/custom_components/sonoff/core/ewelink/local.py", line 192, in send|    host = device["host"]|           ~~~~~~^^^^^^^^|KeyError: 'host'|
2024-04-17 20:40:48 [D] ab300006f7 => Cloud4 | {'uiActive': {'outlet': 1, 'time': 60}} | DDoS | 1713379248283
2024-04-17 20:40:49 [D] ab300006f7 <= Local3 | 192.168.8.14:8081 | {'current_01': 0, 'voltage_01': 0, 'actPow_01': 0, 'reactPow_01': 0, 'apparentPow_01': 0} | 101491
2024-04-17 20:40:49 [D] ab300006f7 <= Cloud3 | {'current_01': 0, 'voltage_01': 0, 'actPow_01': 0, 'reactPow_01': 0, 'apparentPow_01': 0} | None
2024-04-17 20:40:53 [E] ab300006f8 => Local4 |  | {'uiActive': {'outlet': 2, 'time': 60}}|  File "/config/custom_components/sonoff/core/ewelink/local.py", line 192, in send|    host = device["host"]|           ~~~~~~^^^^^^^^|KeyError: 'host'|
2024-04-17 20:40:53 [D] ab300006f8 => Cloud4 | {'uiActive': {'outlet': 2, 'time': 60}} | 1713379253184
2024-04-17 20:40:53 [E] ab300006f7 => Local4 |  | {'uiActive': {'outlet': 2, 'time': 60}}|  File "/config/custom_components/sonoff/core/ewelink/local.py", line 192, in send|    host = device["host"]|           ~~~~~~^^^^^^^^|KeyError: 'host'|
2024-04-17 20:40:53 [D] ab300006f7 => Cloud4 | {'uiActive': {'outlet': 2, 'time': 60}} | DDoS | 1713379253285
2024-04-17 20:40:55 [D] ab300006f7 <= Local3 | 192.168.8.14:8081 | {'current_02': 0, 'voltage_02': 23386, 'actPow_02': 0, 'reactPow_02': 0, 'apparentPow_02': 0} | 101492
2024-04-17 20:40:55 [D] ab300006f7 <= Cloud3 | {'current_02': 0, 'voltage_02': 23386, 'actPow_02': 0, 'reactPow_02': 0, 'apparentPow_02': 0} | None
2024-04-17 20:40:58 [E] ab300006f8 => Local4 |  | {'uiActive': {'outlet': 3, 'time': 60}}|  File "/config/custom_components/sonoff/core/ewelink/local.py", line 192, in send|    host = device["host"]|           ~~~~~~^^^^^^^^|KeyError: 'host'|
2024-04-17 20:40:58 [D] ab300006f8 => Cloud4 | {'uiActive': {'outlet': 3, 'time': 60}} | 1713379258187
2024-04-17 20:40:58 [E] ab300006f7 => Local4 |  | {'uiActive': {'outlet': 3, 'time': 60}}|  File "/config/custom_components/sonoff/core/ewelink/local.py", line 192, in send|    host = device["host"]|           ~~~~~~^^^^^^^^|KeyError: 'host'|

So it looks like the parents host key isn't being copied to the child device. The diagnostics, same as before, show null in those fields.

If you point me where to update that, I can have a go!

Thanks again for the efforts!

AlexxIT commented 7 months ago

https://github.com/AlexxIT/SonoffLAN/releases/tag/v3.7.1

ajcollett commented 7 months ago

Hello @AlexxIT Thanks!

I have pulled and tested. Unfortunately we aren't there yet. Though I might be able to help out a little more now.

This is the new output:

2024-04-19 15:59:09 [D] 10016b70cc => Local4 | 192.168.8.14:8081 | {'uiActive': {'outlet': 1, 'time': 60}, 'subDevId': 'ab300006f8'} <= {'sequence': '1713535149760', 'encrypt': True, 'seq': 177, 'error': 400}
2024-04-19 15:59:09 [D] ab300006f7 => Cloud4 | {'uiActive': {'outlet': 1, 'time': 60}} | 1713535149828
2024-04-19 15:59:10 [D] ab300006f7 <= Local3 | 192.168.8.14:8081 | {'current_01': 0, 'voltage_01': 0, 'actPow_01': 0, 'reactPow_01': 0, 'apparentPow_01': 0} | 177
2024-04-19 15:59:10 [D] 10016b70cc => Local4 | 192.168.8.14:8081 | {'uiActive': {'outlet': 1, 'time': 60}, 'subDevId': 'ab300006f7'} <= {'sequence': '1713535150770', 'encrypt': True, 'seq': 178, 'error': 400}
2024-04-19 15:59:10 [D] ab300006f7 <= Cloud3 | {'current_01': 0, 'voltage_01': 0, 'actPow_01': 0, 'reactPow_01': 0, 'apparentPow_01': 0} | None
2024-04-19 15:59:14 [D] ab300006f8 => Cloud4 | {'uiActive': {'outlet': 2, 'time': 60}} | 1713535154730
2024-04-19 15:59:14 [D] ab300006f7 => Cloud4 | {'uiActive': {'outlet': 2, 'time': 60}} | 1713535154831
2024-04-19 15:59:14 [D] 10016b70cc => Local4 | 192.168.8.14:8081 | {'uiActive': {'outlet': 2, 'time': 60}, 'subDevId': 'ab300006f8'} <= {'sequence': '1713535154800', 'encrypt': True, 'seq': 178, 'error': 400}
2024-04-19 15:59:15 [D] 10016b70cc => Local4 | 192.168.8.14:8081 | {'uiActive': {'outlet': 2, 'time': 60}, 'subDevId': 'ab300006f7'} <= {'sequence': '1713535155811', 'encrypt': True, 'seq': 178, 'error': 400}

From reading the DIY docs here: https://sonoff.tech/sonoff-diy-developer-documentation-spm-main-http-api/ I see that there is supposed to be a "report URL" or something for the device to report back to, assuming we're using the monitoring api?

I'll try dig into the code a little. I'm also not sure if the DIY mode docs have anything to do with the ewelink mode API.

To be clear, I have NOT enabled DIY mode yet, but if I should try that, let me know.

AlexxIT commented 7 months ago

I can just turn off local updates for this device. That would be the easiest way

ajcollett commented 7 months ago

That would take us back to my original issue though, where we only query Cloud and I don't get good stats.

The cloud queries aren't reliable, and I don't get replies often from the one 4channel module.

Let me look some more.

ajcollett commented 7 months ago

Okay, I've got a plan.

I'm going to try block the SPM from connecting to the internet. Then use ewelink to try query the SPM, and see what works and what doesn't.

That should atleast tell us if local mode is possible.

ajcollett commented 7 months ago

Okay, well that answers one questions.

If I stop the SPM from contacting the internet, then I can still control switches and so on from ewelink on local lan, but I cannot retrieve stats for power monitoring.

So, it would seem that unless it's in DIY mode, there is not local mode for power monitoring.

To support DIY mode, it seems one would need to run a server to receive the stats. Which I'm guessing is not simple/possible with this add-on right?

AlexxIT commented 7 months ago

https://github.com/AlexxIT/SonoffLAN/releases/tag/v3.7.2

ajcollett commented 7 months ago

Hello @AlexxIT

Thanks for the update. Though it took me back to the same issue, that is, the one module updates, but the other one does not.

However! I have made some changes to the code, and managed to get some positive initial results. I'll report back tomorrow if they stay consistent:

2024-04-21 21:28:58 [D] ab300006f7 => Cloud4 | {'uiActive': {'outlet': 2, 'time': 60}} | 1713727738308
2024-04-21 21:28:58 [D] ab300006f7 <= Local3 | 192.168.8.14:8081 | {'current_02': 0, 'voltage_02': 23489, 'actPow_02': 0, 'reactPow_02': 0, 'apparentPow_02': 0} | 27491
2024-04-21 21:28:59 [D] ab300006f7 <= Cloud3 | {'current_02': 0, 'voltage_02': 23489, 'actPow_02': 0, 'reactPow_02': 0, 'apparentPow_02': 0} | None
2024-04-21 21:29:00 [D] ab300006f8 => Cloud4 | {'uiActive': {'outlet': 3, 'time': 60}} | 1713727740309
2024-04-21 21:29:00 [D] ab300006f8 <= Local3 | 192.168.8.14:8081 | {'current_03': 23, 'voltage_03': 23533, 'actPow_03': 174, 'reactPow_03': 5498, 'apparentPow_03': 5504} | 27492
2024-04-21 21:29:01 [D] ab300006f8 <= Cloud3 | {'current_03': 23, 'voltage_03': 23533, 'actPow_03': 174, 'reactPow_03': 5498, 'apparentPow_03': 5504} | None
2024-04-21 21:29:03 [D] ab300006f7 => Cloud4 | {'uiActive': {'outlet': 3, 'time': 60}} | 1713727743310
2024-04-21 21:29:04 [D] ab300006f7 <= Local3 | 192.168.8.14:8081 | {'current_03': 24, 'voltage_03': 23513, 'actPow_03': 4058, 'reactPow_03': 4096, 'apparentPow_03': 5790} | 27493
2024-04-21 21:29:05 [D] ab300006f7 <= Cloud3 | {'current_03': 24, 'voltage_03': 23513, 'actPow_03': 4058, 'reactPow_03': 4096, 'apparentPow_03': 5790} | None
2024-04-21 21:29:15 [D] ab300006f8 => Cloud4 | {'uiActive': {'outlet': 0, 'time': 60}} | 1713727755305
2024-04-21 21:29:16 [D] ab300006f8 <= Local3 | 192.168.8.14:8081 | {'current_00': 68, 'voltage_00': 23499, 'actPow_00': 12699, 'reactPow_00': 9777, 'apparentPow_00': 16086} | 27494
2024-04-21 21:29:17 [D] ab300006f8 <= Cloud3 | {'current_00': 68, 'voltage_00': 23499, 'actPow_00': 12699, 'reactPow_00': 9777, 'apparentPow_00': 16086} | None
2024-04-21 21:29:18 [D] ab300006f7 => Cloud4 | {'uiActive': {'outlet': 0, 'time': 60}} | 1713727758309
2024-04-21 21:29:18 [D] ab300006f7 <= Local3 | 192.168.8.14:8081 | {'current_00': 10, 'voltage_00': 23440, 'actPow_00': 0, 'reactPow_00': 2273, 'apparentPow_00': 2281} | 27495
2024-04-21 21:29:19 [D] ab300006f7 <= Cloud3 | {'current_00': 10, 'voltage_00': 23440, 'actPow_00': 0, 'reactPow_00': 2273, 'apparentPow_00': 2281} | None
2024-04-21 21:29:20 [D] ab300006f8 => Cloud4 | {'uiActive': {'outlet': 1, 'time': 60}} | 1713727760307
2024-04-21 21:29:20 [D] ab300006f8 <= Local3 | 192.168.8.14:8081 | {'current_01': 8, 'voltage_01': 23497, 'actPow_01': 1340, 'reactPow_01': 1269, 'apparentPow_01': 1882} | 27496
2024-04-21 21:29:21 [D] ab300006f8 <= Cloud3 | {'current_01': 8, 'voltage_01': 23497, 'actPow_01': 1340, 'reactPow_01': 1269, 'apparentPow_01': 1882} | None
2024-04-21 21:29:23 [D] ab300006f7 => Cloud4 | {'uiActive': {'outlet': 1, 'time': 60}} | 1713727763311
2024-04-21 21:29:24 [D] ab300006f7 <= Local3 | 192.168.8.14:8081 | {'current_01': 0, 'voltage_01': 0, 'actPow_01': 0, 'reactPow_01': 0, 'apparentPow_01': 0} | 27497
2024-04-21 21:29:25 [D] ab300006f7 <= Cloud3 | {'current_01': 0, 'voltage_01': 0, 'actPow_01': 0, 'reactPow_01': 0, 'apparentPow_01': 0} | None
2024-04-21 21:29:25 [D] ab300006f8 => Cloud4 | {'uiActive': {'outlet': 2, 'time': 60}} | 1713727765309
2024-04-21 21:29:26 [D] ab300006f8 <= Local3 | 192.168.8.14:8081 | {'current_02': 382, 'voltage_02': 23490, 'actPow_02': 89510, 'reactPow_02': 3973, 'apparentPow_02': 89601} | 27498
2024-04-21 21:29:27 [D] ab300006f8 <= Cloud3 | {'current_02': 382, 'voltage_02': 23490, 'actPow_02': 89510, 'reactPow_02': 3973, 'apparentPow_02': 89601} | None
2024-04-21 21:29:28 [D] ab300006f7 => Cloud4 | {'uiActive': {'outlet': 2, 'time': 60}} | 1713727768312
2024-04-21 21:29:28 [D] ab300006f7 <= Local3 | 192.168.8.14:8081 | {'current_02': 0, 'voltage_02': 23468, 'actPow_02': 0, 'reactPow_02': 0, 'apparentPow_02': 0} | 27499
2024-04-21 21:29:29 [D] ab300006f7 <= Cloud3 | {'current_02': 0, 'voltage_02': 23468, 'actPow_02': 0, 'reactPow_02': 0, 'apparentPow_02': 0} | None
2024-04-21 21:29:30 [D] ab300006f8 => Cloud4 | {'uiActive': {'outlet': 3, 'time': 60}} | 1713727770310
2024-04-21 21:29:30 [D] ab300006f8 <= Local3 | 192.168.8.14:8081 | {'current_03': 23, 'voltage_03': 23490, 'actPow_03': 175, 'reactPow_03': 5462, 'apparentPow_03': 5467} | 27500
2024-04-21 21:29:31 [D] ab300006f8 <= Cloud3 | {'current_03': 23, 'voltage_03': 23490, 'actPow_03': 175, 'reactPow_03': 5462, 'apparentPow_03': 5467} | None
2024-04-21 21:29:33 [D] ab300006f7 => Cloud4 | {'uiActive': {'outlet': 3, 'time': 60}} | 1713727773313
2024-04-21 21:29:34 [D] ab300006f7 <= Local3 | 192.168.8.14:8081 | {'current_03': 24, 'voltage_03': 23458, 'actPow_03': 4065, 'reactPow_03': 4100, 'apparentPow_03': 5785} | 27501
2024-04-21 21:29:35 [D] ab300006f7 <= Cloud3 | {'current_03': 24, 'voltage_03': 23458, 'actPow_03': 4065, 'reactPow_03': 4100, 'apparentPow_03': 5785} | None

So it seems that if the different modules data is requested at the same time, then only the first one returns data!

The code I changed, obviously not useful beyond testing in my context:

    async def update_spm_pow(self, device: XDevice):
        if device["deviceid"] == "ab300006f7":
            await asyncio.sleep(3)

        for i in range(4):
            if i > 0:
                await asyncio.sleep(5)
            params = {"uiActive": {"outlet": i, "time": 60}}
            await self.cloud.send(device, params, timeout=0)

What does the 'time': 60 param do?

AlexxIT commented 7 months ago

Duration while reports are active

ajcollett commented 2 months ago

@AlexxIT I wanted to give a very quick report back, since I haven't managed to get more info to you yet.

My code changes to create a delay between querying each module has worked really well.

I'll send a longer reply with more details as soon as I can make the time, and hopefully propose a fix. Just know that Cloud querying with a delay between SPM modules works really well!