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.67k stars 414 forks source link

Fix bug in local response from AltoBeam GTWS78 #1160

Closed AutoHome2022 closed 9 months ago

AutoHome2022 commented 1 year ago

Dear Community, Exellent work by the SonoffLAN team I must mention.

I am heavily invested in use of Ewelink and Sonnoff range of products.

I have been having issues with my 1 gang wall switch labelled GTWS78 by AltoBeam Firmware: 1.4.1. Unfortunately, I have several of these switches becuase I used them in a whole house automation project. I have just upgraded my SonoffLAN version to 3.5.1

Please see attached debug snapshots (look at the time Stamps). It takes in some cases up to 30 seconds before the Switch State is correctly updated in Home Assistant. However, actual action of switching ON or OFF happens less than a second. I have reviewed #issue 928 looks like it does not apply to me. Please note this behaviour only happens in LAN mode ONLY. Auto or Cloud Mode works fine.

All other TX3C wall switches by SONOFF work flawlessly in LAN mode without this annoying behaviour.

I will really appreciate any assistance becuase changing all the switches is really not an option plus I cant even find 15A wall switch official sonoff.

LAN MODE

Switch Turned OFF

2023-04-04 14:04:43 [D] 100119e9e5 => Local4 | 192.168.210.63:8080 | {'switches': [{'outlet': 0, 'switch': 'off'}]} <= {'sequence': '1680613483000', 'encrypt': True, 'seq': 2073, 'error': 0, 'iv': 'MTA4MDc1MTQ5NzE5ODE2Ng==', 'data': 'D85ho6GLI5uFX2b1+vohUIb+Xt99f55wxsBsNhqpPQdQ/WNc3ZTlCi1UVFiFU5cnaCPjvXPG6pqfHqXdtCO2fA=='}
2023-04-04 14:04:43 [D] Can't decrypt message|  File "/config/custom_components/sonoff/core/ewelink/__init__.py", line 258, in local_update|    params = self.local.decrypt_msg(msg, device["devicekey"])|json.decoder.JSONDecodeError: Extra data: line 1 column 47 (char 46)|
2023-04-04 14:05:01 [D] 100119e9e5 <= Local3 | 192.168.210.63:8080 | {'switches': [{'outlet': 0, 'switch': 'off'}], 'configure': [{'outlet': 0, 'startup': 'stay'}], 'switch': 'off', 'startup': 'stay', 'pulse': 'off', 'lock': 0, 'sledOnline': 'on'} | 2075

Switch Turned ON

2023-04-04 14:06:54 [D] 100119e9e5 => Local4 | 192.168.210.63:8080 | {'switches': [{'outlet': 0, 'switch': 'on'}]} <= {'sequence': '1680613614000', 'encrypt': True, 'seq': 2079, 'error': 0, 'iv': 'MzExMjYzMjExMjg2NTY5NA==', 'data': 'NHewKeJnfAemTtt0s6L7EgNbEK//e8ldIUUj6WIw45Ctg0OvBTQA3yIEr6R+2kaNVoV//anF8X5xltDaTjM4Tg=='}
2023-04-04 14:06:54 [D] Can't decrypt message|  File "/config/custom_components/sonoff/core/ewelink/__init__.py", line 258, in local_update|    params = self.local.decrypt_msg(msg, device["devicekey"])|json.decoder.JSONDecodeError: Extra data: line 1 column 46 (char 45)|
2023-04-04 14:07:01 [D] 100119e9e5 <= Local3 | 192.168.210.63:8080 | {'switches': [{'outlet': 0, 'switch': 'on'}], 'configure': [{'outlet': 0, 'startup': 'stay'}], 'switch': 'on', 'startup': 'stay', 'pulse': 'off', 'lock': 0, 'sledOnline': 'on'} | 2081

AUTO MODE

Switch Turned OFF

2023-04-04 14:16:09 [D] 100119e9e5 => Local4 | 192.168.210.63:8080 | {'switches': [{'outlet': 0, 'switch': 'off'}]} <= {'sequence': '1680614169000', 'encrypt': True, 'seq': 2101, 'error': 0, 'iv': 'MTQzMzQ2NDkyOTMxOTcyMg==', 'data': '9/bl3peTubDcAPNN+UOUagGyXe+OYP9UTi5shKJdMTui8aXGerIIRQORw/wJrqLZDhZl+yDQ3YOVUYD9ej/H1w=='}
2023-04-04 14:16:09 [D] Can't decrypt message|  File "/config/custom_components/sonoff/core/ewelink/__init__.py", line 258, in local_update|    params = self.local.decrypt_msg(msg, device["devicekey"])|json.decoder.JSONDecodeError: Extra data: line 1 column 47 (char 46)|
2023-04-04 14:16:10 [D] 100119e9e5 <= Cloud3 | {'switches': [{'outlet': 0, 'switch': 'off'}, {'outlet': 1, 'switch': 'off'}, {'outlet': 2, 'switch': 'off'}, {'outlet': 3, 'switch': 'off'}]} | 1680614169000`
AutoHome2022 commented 1 year ago

Device Daignosis Information While SonoffLan in LAN mode

{
  "home_assistant": {
    "installation_type": "Home Assistant OS",
    "version": "2023.3.6",
    "dev": false,
    "hassio": true,
    "virtualenv": false,
    "python_version": "3.10.10",
    "docker": true,
    "arch": "x86_64",
    "timezone": "Africa/Lagos",
    "os_name": "Linux",
    "os_version": "5.15.90",
    "supervisor": "2023.03.3",
    "host_os": "Home Assistant OS 9.5",
    "docker_version": "20.10.22",
    "chassis": "vm",
    "run_as_root": true
  },
  "custom_components": {
    "sonoff": {
      "version": "3.5.1",
      "requirements": [
        "pycryptodome>=3.6.6"
      ]
    },
    "pfsense": {
      "version": "0.1.0",
      "requirements": [
        "mac-vendor-lookup>=0.1.11"
      ]
    },
    "hacs": {
      "version": "1.31.0",
      "requirements": [
        "aiogithubapi>=22.10.1"
      ]
    }
  },
  "integration_manifest": {
    "domain": "sonoff",
    "name": "Sonoff",
    "config_flow": true,
    "documentation": "https://github.com/AlexxIT/SonoffLAN",
    "issue_tracker": "/api/sonoff/67367b53-b7d7-4223-a4a6-42ddc4150d02",
    "codeowners": [
      "@AlexxIT"
    ],
    "dependencies": [
      "http",
      "zeroconf"
    ],
    "requirements": [
      "pycryptodome>=3.6.6"
    ],
    "version": "3.5.1",
    "iot_class": "local_push",
    "is_built_in": false
  },
  "data": {
    "version": "122751c",
    "cloud_auth": true,
    "config": null,
    "options": {
      "mode": "local",
      "debug": true,
      "homes": 1
    },
    "errors": [],
    "device": {
      "uiid": 78,
      "params": {
        "bindInfos": "***",
        "version": 8,
        "switches": [
          {
            "outlet": 0,
            "switch": "on"
          },
          {
            "outlet": 1,
            "switch": "off"
          },
          {
            "outlet": 2,
            "switch": "off"
          },
          {
            "outlet": 3,
            "switch": "off"
          }
        ],
        "configure": [
          {
            "outlet": 0,
            "startup": "stay"
          }
        ],
        "switch": "on",
        "startup": "stay",
        "staMac": "***",
        "fwVersion": "1.4.1",
        "pulse": "off",
        "pulseWidth": 1000,
        "lock": 0,
        "sledOnline": "on",
        "rssi": -70,
        "cmd": "info"
      },
      "model": "GTWS78",
      "online": true,
      "local": true,
      "localtype": "strip",
      "host": "192.168.210.63:8080",
      "deviceid": "100119e9e5"
    }
  }
}
AlexxIT commented 11 months ago

I need your device "devicekey". With it I can decode response and check what is wrong. You can find device key here: /config/.storage/sonoff/...json

AutoHome2022 commented 11 months ago

I need your device "devicekey". With it I can decode response and check what is wrong. You can find device key here: /config/.storage/sonoff/...json

Awesome Thanks for getting back to me. As I have several of them. and it appears they all have different 'devicekey' I have picked 2 of them. Please find below. do let me know if you require the rest.

"name": "##### Heater", "deviceid": "100119e52a", "devicekey": "26e6e7ab-7305-48be-b2ef-2fc08ae64083"

"name": "###### Room AC", "deviceid": "100119e066", "devicekey": "c8ee08b3-457c-4f27-9ccd-21389da27b13",

AlexxIT commented 11 months ago

I need key for device 100119e9e5 from your first msg

AutoHome2022 commented 11 months ago

I need key for device 100119e9e5 from your first msg

Appologies. Please find below as requested "devicekey": "9b0810bc-557a-406c-8266-614767890531"

AlexxIT commented 11 months ago

Fixed. You can use master version before next release

AutoHome2022 commented 11 months ago

Fixed. You can use master version before next release

Wow super awesome. thanks a lot. It appears this patch 'just' missed the v3.5.3 relsease'. Honestly I actually don't know use the raw source code or the master version in HACS.

Will snoop around for how to do this otherwise I will just wait till the next realease with the joy this matter will be laid to rest now. super super happy

Mega Thanks

AutoHome2022 commented 11 months ago

Fixed. You can use master version before next release


2023-10-15 23:09:10 [D] 100119de1a => Local4 | 192.168.210.62:8080 | None <= {'sequence': '1697407750000', 'encrypt': True, 'seq': 4142, 'error': 0, 'iv': 'MjAzOTAyMDQzNDM5MDAzNQ==', 'data': 'ND3KdUF5iUb7RtCPCOUWoCz86+1KvNOON4Q92tFWhoI='}

2023-10-15 23:09:10 [D] Can't decrypt message|  File "/config/custom_components/sonoff/core/ewelink/__init__.py", line 263, in local_update|    params = self.local.decrypt_msg(msg, device["devicekey"])| ```

Ok a little bit of feedback 

Unfortunately the controls are still seriously lagging. I have been able to update to v3.5.3. Also I thought I have used the 'master' version as well. Rebooted. Home assistant still same. if I use cloud or auto everything is fine. 

 Thanks again 
AlexxIT commented 11 months ago

This patch not included to 3.5.3 release

AlexxIT commented 9 months ago

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