Open ajcollett opened 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.
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.
I don't know why this is happening. I don't have these devices.
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.
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?
Old devices support only cloud updates. Some new devices support local updates. You can see all of them in the code above
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.
It always prints out True.
So I'm now going to force local communication and see what happens...
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?
Looks like you right. There is code for detecting local mode in another function:
Unfortunately I don't have this devices for local test.
Reopen issue if this fix not helps https://github.com/AlexxIT/SonoffLAN/releases/tag/v3.7.0
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!
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.
I can just turn off local updates for this device. That would be the easiest way
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.
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.
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?
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?
Duration while reports are active
@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!
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.
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