nikshriv / cync_lights

Home Assistant Integration for controlling Cync switches, plugs, and bulbs
160 stars 53 forks source link

Delay on/off from HA #6

Closed marc3k18 closed 1 year ago

marc3k18 commented 1 year ago

When on/off a switch from ha, there is a delay of 30 seconds. Dimmer work instantenly. When on/off from cync app or Google Home, it shows directly the action on ha.

marc3k18 commented 1 year ago

Last version of HA and of the integration

nikshriv commented 1 year ago

I will need a little more detail. Are you controlling these switches with the room switch entity or with the individual switch entity in HA? Which device(s) are affected? (Please refer to the name of the switch or group in the configuration information that you posted a few months ago). Is the behavior the same when you attempt to turn off the switch, or does it only occur when turning it on?

nylekyland commented 1 year ago

Hello,

I am also seeing the same issue, a consistent ~30 second delay when turning on & off my lighting group from Home Assistant. I have 4 of the "GE Cync Direct Connect Soft White A19" bulbs (I believe they are these ones), and they are all set to be in a group in the Cync app. In Home Assistant, I am using a simple switch for the group entity to turn all 4 lights on/off at the same time.

Screenshot 2022-09-14 082557

There is a 30 second delay when turning both on and off.

nikshriv commented 1 year ago

Is the basement group switch one of the entities created by the integration? You'll need to run the cync_data.py script and post your results. I really have no idea what could be causing this issue at this point. If you want to try to help solve this problem, consider running a packet capture on an Android device while you are using the Cync app to turn your light bulb group on and off and send me the result. You can use an app called PCAPDroid. Set the app to capture packets from the Cync app and save the result as a file, then send me that file. That's how I've been working out the tcp protocol to control these devices.

nylekyland commented 1 year ago

Is the basement group switch one of the entities created by the integration?

Yes, it's the default entity that was created when setting up through the integration. If it helps, I'm running my Home Assistant through a Docker instance.

I don't have any Android devices so I don't think I can packet capture to check how the calls are being made on a mobile device.

Here is the cbyge_rooms.json output for my configuration (I've omitted some user info):

{
    "data": [
        {
            "device": {
                "subscribe_date": "2022-08-29T11:11:01.526Z",
                "is_active": true,
                "role": 0,
                "last_login": "2022-08-30T01:51:27.374Z",
                "firmware_mod": "1",
                "active_code": "8c0c6769c7a0d6a4b0f20991a900fb20",
                "active_date": "2022-08-29T11:10:59.496Z",
                "groups": "",
                "mcu_version": 28,
                "firmware_version": 10215,
                "source": 1,
                "mac": "786DEB3BBF6B",
                "mcu_mod": "1",
                "product_id": "1607d2bc852800011607d2bc85283801",
                "access_key": 777,
                "name": "786DEB3BBF6B",
                "authorize_code": "1e07d4becc0c9426",
                "id": 247043688,
                "is_online": true,
                "sn": "786DEB3BBF6B"
            },
            "device_info": {
                "error": {
                    "msg": "device property not exists",
                    "code": 4041009
                }
            }
        },
        {
            "device": {
                "subscribe_date": "2022-08-29T11:05:17.724Z",
                "is_active": true,
                "role": 0,
                "last_login": "",
                "active_code": "adaa428c391d75cf4aeedbf1b3a0d547",
                "active_date": "2022-08-29T11:05:17.722Z",
                "groups": "",
                "mcu_version": 0,
                "firmware_version": 0,
                "source": 5,
                "mac": "B90C48C8CF6F",
                "product_id": "1607d2ad150cb2001607d2ad150cb201",
                "access_key": 720118,
                "name": "Basement",
                "authorize_code": "1e07d2c619c77a0c",
                "id": 500113021,
                "is_online": false
            },
            "device_info": {
                "musicShows": [],
                "bulbsArray": [
                    {
                        "occupancyDeactivationPeriod": 0,
                        "lightRingBrightness": 0,
                        "displayName": "Basement Light - Couches",
                        "showOnHome": false,
                        "loadSelection": 0,
                        "lightRingColor": 0,
                        "mac": "786DEB3ABC31",
                        "ambientLightEnable": false,
                        "occupancySensitivity": 0,
                        "firmwareVersion": "1.0.215",
                        "occupancyEnable": false,
                        "followTheSun": false,
                        "deviceType": 128,
                        "fadeOff": 0,
                        "wifiDisconnectIndicatorEnable": false,
                        "switchID": 1156033004,
                        "wifiSsid": "*******",
                        "allowOTAUpdates": true,
                        "deviceID": 500113021001,
                        "fadeOn": 0,
                        "commissionedDate": "2022-08-29T16:07:09Z",
                        "defaultBrightness": 0,
                        "wifiMac": "786DEB3AAB6D",
                        "lightRingMode": 0,
                        "ambientLightSensitivity": 0,
                        "simpleModeEnabled": false,
                        "occupancyTimeoutPeriod": 0
                    },
                    {
                        "occupancyDeactivationPeriod": 0,
                        "lightRingBrightness": 0,
                        "displayName": "Basement Light - Treadmill",
                        "showOnHome": false,
                        "loadSelection": 0,
                        "lightRingColor": 0,
                        "mac": "786DEB3ABE7F",
                        "ambientLightEnable": false,
                        "occupancySensitivity": 0,
                        "firmwareVersion": "1.0.215",
                        "occupancyEnable": false,
                        "followTheSun": false,
                        "deviceType": 128,
                        "fadeOff": 0,
                        "wifiDisconnectIndicatorEnable": false,
                        "switchID": 1156037098,
                        "wifiSsid": "******",
                        "allowOTAUpdates": true,
                        "deviceID": 500113021002,
                        "fadeOn": 0,
                        "commissionedDate": "2022-08-29T16:08:07Z",
                        "defaultBrightness": 0,
                        "wifiMac": "786DEB3AABAF",
                        "lightRingMode": 0,
                        "ambientLightSensitivity": 0,
                        "simpleModeEnabled": false,
                        "occupancyTimeoutPeriod": 0
                    },
                    {
                        "occupancyDeactivationPeriod": 0,
                        "lightRingBrightness": 0,
                        "displayName": "Basement Light - Desk",
                        "showOnHome": false,
                        "loadSelection": 0,
                        "lightRingColor": 0,
                        "mac": "786DEB3BCADE",
                        "ambientLightEnable": false,
                        "occupancySensitivity": 0,
                        "firmwareVersion": "1.0.215",
                        "occupancyEnable": false,
                        "followTheSun": false,
                        "deviceType": 128,
                        "fadeOff": 0,
                        "wifiDisconnectIndicatorEnable": false,
                        "switchID": 247043688,
                        "wifiSsid": "******",
                        "allowOTAUpdates": true,
                        "deviceID": 500113021003,
                        "fadeOn": 0,
                        "commissionedDate": "2022-08-29T16:11:01Z",
                        "defaultBrightness": 0,
                        "wifiMac": "786DEB3BBF6B",
                        "lightRingMode": 0,
                        "ambientLightSensitivity": 0,
                        "simpleModeEnabled": false,
                        "occupancyTimeoutPeriod": 0
                    },
                    {
                        "occupancyDeactivationPeriod": 0,
                        "lightRingBrightness": 0,
                        "displayName": "Basement Light - Lamp",
                        "showOnHome": false,
                        "loadSelection": 0,
                        "lightRingColor": 0,
                        "mac": "786DEB3BC5B1",
                        "ambientLightEnable": false,
                        "occupancySensitivity": 0,
                        "firmwareVersion": "1.0.128",
                        "occupancyEnable": false,
                        "followTheSun": false,
                        "deviceType": 128,
                        "fadeOff": 0,
                        "wifiDisconnectIndicatorEnable": false,
                        "switchID": 247048557,
                        "wifiSsid": "******",
                        "allowOTAUpdates": true,
                        "deviceID": 500113021004,
                        "fadeOn": 0,
                        "commissionedDate": "2022-08-29T21:08:39Z",
                        "defaultBrightness": 0,
                        "wifiMac": "786DEB3BB9ED",
                        "lightRingMode": 0,
                        "ambientLightSensitivity": 0,
                        "simpleModeEnabled": false,
                        "occupancyTimeoutPeriod": 0
                    }
                ],
                "lightShows": [],
                "admin": {
                    "emailAddress": "******",
                    "lastUseDate": "2022-08-29T12:05:17.756Z",
                    "userID": ******,
                    "username": "******",
                    "createDate": "2022-08-29T12:05:17.756Z"
                },
                "lastUseDate": "2022-08-29T12:05:17.762Z",
                "groupsArray": [
                    {
                        "sensorSchedules": [],
                        "displayName": "Basement",
                        "groupID": 32768,
                        "showOnHome": false,
                        "isSubgroup": false,
                        "subgroupIDArray": [
                            32769
                        ],
                        "deviceIDArray": []
                    },
                    {
                        "sensorSchedules": [],
                        "displayName": "Basement Group",
                        "groupID": 32769,
                        "showOnHome": false,
                        "isSubgroup": true,
                        "deviceIDArray": [
                            2,
                            1,
                            3,
                            4
                        ]
                    }
                ],
                "version": "1.0",
                "system": {
                    "app": {
                        "build": "14192",
                        "bundleID": "com.ge.cbyge1",
                        "name": "Cync",
                        "version": "6.8.2"
                    },
                    "ltk": "70830E57C8932CBECFA9852A15BAF087",
                    "timeInfo": {
                        "sunrise": "7:00:00 PM",
                        "sunset": "6:27:49 PM",
                        "timeZone": "******"
                    },
                    "platform": {
                        "os": "iOS",
                        "machine": "N/A",
                        "model": "iPhone",
                        "localizedModel": "iPhone",
                        "version": "16.0"
                    }
                },
                "standaloneDevicesArray": [],
                "geoLocation": {
                    "zipCode": "******",
                    "latitude": ******,
                    "longitude": ******
                },
                "sceneArray": [],
                "schedules": [],
                "createDate": "2022-08-29T12:05:17.762Z"
            }
        },
        {
            "device": {
                "subscribe_date": "2022-08-29T16:08:39.733Z",
                "is_active": true,
                "role": 0,
                "last_login": "2022-08-30T01:04:11.684Z",
                "firmware_mod": "1",
                "active_code": "97970b481bd4acd6d51e1a5de529d661",
                "active_date": "2022-08-29T16:08:37.661Z",
                "groups": "",
                "mcu_version": 28,
                "firmware_version": 10215,
                "source": 1,
                "mac": "786DEB3BB9ED",
                "mcu_mod": "1",
                "product_id": "1607d2bc852800011607d2bc85283801",
                "access_key": 777,
                "name": "786DEB3BB9ED",
                "authorize_code": "1e07d4becc0bbc5f",
                "id": 247048557,
                "is_online": true,
                "sn": "786DEB3BB9ED"
            },
            "device_info": {
                "error": {
                    "msg": "device property not exists",
                    "code": 4041009
                }
            }
        },
        {
            "device": {
                "subscribe_date": "2022-08-29T11:07:09.742Z",
                "is_active": true,
                "role": 0,
                "last_login": "2022-08-30T01:34:29.641Z",
                "firmware_mod": "1",
                "active_code": "e1e582f2ec37865d91556739c07fbd3c",
                "active_date": "2022-08-29T11:07:03.638Z",
                "groups": "",
                "mcu_version": 28,
                "firmware_version": 10215,
                "source": 1,
                "mac": "786DEB3AAB6D",
                "mcu_mod": "1",
                "product_id": "1607d2bc852800011607d2bc85283801",
                "access_key": 777,
                "name": "786DEB3AAB6D",
                "authorize_code": "1e07d4bec66e9a4e",
                "id": 1156033004,
                "is_online": true,
                "sn": "786DEB3AAB6D"
            },
            "device_info": {
                "error": {
                    "msg": "device property not exists",
                    "code": 4041009
                }
            }
        },
        {
            "device": {
                "subscribe_date": "2022-08-29T11:08:07.370Z",
                "is_active": true,
                "role": 0,
                "last_login": "2022-08-30T21:17:04.733Z",
                "firmware_mod": "1",
                "active_code": "456dd1581710cbd318b1e7eb7f2eb13e",
                "active_date": "2022-08-29T11:07:54.821Z",
                "groups": "",
                "mcu_version": 28,
                "firmware_version": 10215,
                "source": 1,
                "mac": "786DEB3AABAF",
                "mcu_mod": "1",
                "product_id": "1607d2bc852800011607d2bc85283801",
                "access_key": 777,
                "name": "786DEB3AABAF",
                "authorize_code": "1e07d2bec66f9e2c",
                "id": 1156037098,
                "is_online": true,
                "sn": "786DEB3AABAF"
            },
            "device_info": {
                "error": {
                    "msg": "device property not exists",
                    "code": 4041009
                }
            }
        }
    ]
}
nikshriv commented 1 year ago

Just released a big update. Pretty sure I have plugs and On/Off bulbs and switches functioning as intended. Delete your old installation and download the updated version and reinstall. Let me know if this works for you.

nylekyland commented 1 year ago

I removed everything from HACS and redownloaded the repo and readded the integration, but still the same result. On/off requests still take roughly 30 seconds to fire. Adjusting the brightness when the lights are on is instant though.

nikshriv commented 1 year ago

I removed everything from HACS and redownloaded the repo and readded the integration, but still the same result. On/off requests still take roughly 30 seconds to fire. Adjusting the brightness when the lights are on is instant though.

I believe the bulbs you have are an older generation and they seem to use a slightly different set of command packets than the ones I have, in particular when turning on and off. All of my bulbs, switches, and plugs now work as expected. I thought I had it worked out, but clearly still having some issues.

If you're unable to do a packet capture, one option would be to allow me to do it remotely. If this isn't too invasive for you, you could open a dummy cync account and add one of the troublesome bulbs to that account. You would have to share the username and password with me, but that would allow me to run a packet capture on the bulb and see what's going on. If you're okay with trying this, let me know. If not, no worries.

marc3k18 commented 1 year ago

The problem is also present for me after all the update for all my switch.

Le dim. 25 sept. 2022, 6 h 14 p.m., nikshriv @.***> a écrit :

I removed everything from HACS and redownloaded the repo and readded the integration, but still the same result. On/off requests still take roughly 30 seconds to fire. Adjusting the brightness when the lights are on is instant though.

I believe the bulbs you have are an older generation and they seem to use a slightly different set of command packets than the ones I have, in particular when turning on and off. All of my bulbs, switches, and plugs now work as expected. I thought I had it worked out, but clearly still having some issues.

If you're unable to do a packet capture, one option would be to allow me to do it remotely. If this isn't too invasive for you, you could open a dummy cync account and add one of the troublesome bulbs to that account. You would have to share the username and password with me, but that would allow me to run a packet capture on the bulb and see what's going on. If you're okay with trying this, let me know. If not, no worries.

— Reply to this email directly, view it on GitHub https://github.com/nikshriv/cync_lights/issues/6#issuecomment-1257290262, or unsubscribe https://github.com/notifications/unsubscribe-auth/AXKJDQCP3474QNSK5P2MWNLWADFFNANCNFSM6AAAAAAQG7TOVU . You are receiving this because you authored the thread.Message ID: @.***>

nikshriv commented 1 year ago

The problem is also present for me after all the update for all my switch. Le dim. 25 sept. 2022, 6 h 14 p.m., nikshriv @.> a écrit : I removed everything from HACS and redownloaded the repo and readded the integration, but still the same result. On/off requests still take roughly 30 seconds to fire. Adjusting the brightness when the lights are on is instant though. I believe the bulbs you have are an older generation and they seem to use a slightly different set of command packets than the ones I have, in particular when turning on and off. All of my bulbs, switches, and plugs now work as expected. I thought I had it worked out, but clearly still having some issues. If you're unable to do a packet capture, one option would be to allow me to do it remotely. If this isn't too invasive for you, you could open a dummy cync account and add one of the troublesome bulbs to that account. You would have to share the username and password with me, but that would allow me to run a packet capture on the bulb and see what's going on. If you're okay with trying this, let me know. If not, no worries. — Reply to this email directly, view it on GitHub <#6 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AXKJDQCP3474QNSK5P2MWNLWADFFNANCNFSM6AAAAAAQG7TOVU . You are receiving this because you authored the thread.Message ID: @.>

I've been working with a new set of bulbs this weekend, and it seems that the strength of the WiFi connection of these bulbs (and probably switches) is affecting their ability to respond to commands. Currently, I send commands directly to switches and bulbs if they are WiFi enabled. I suspect that if the WiFi connection is poor, the devices fail to respond to commands and hence the behavior you are seeing. I'm going to implement steps to check for a response to commands, and if no response within a second, try another WiFi connected device.

nylekyland commented 1 year ago

I ran a traffic capture using the Cync app on iOS + Fiddler on Windows. I was able to see the JSON for the device information, similar to how the cync_data.py script generates. However, turning the lights on/off and adjusting the brightness with the app did not generate any requests for me in Fiddler.

nikshriv commented 1 year ago

I think I have finally figured out this bug. Should be working now. Please try downloading again. There was a problem with the on/off command that I didn't see until yesterday.

Another issue that remains is Wi-Fi connectivity of the devices. I will be updating soon to check connectivity of Wi-Fi devices before sending commands. I think that was another issue for some users that was causing commands not to go through.

marc3k18 commented 1 year ago

Nice job! It's working perfectly for me now! No more delay.

Le ven. 30 sept. 2022, 10 h 45 a.m., nikshriv @.***> a écrit :

I think I have finally figured out this bug. Should be working now. Please try downloading again. There was a problem with the on/off command that I didn't see until yesterday.

Another issue that remains is Wi-Fi connectivity of the devices. I will be updating soon to check connectivity of Wi-Fi devices before sending commands. I think that was another issue for some users that was causing commands not to go through.

— Reply to this email directly, view it on GitHub https://github.com/nikshriv/cync_lights/issues/6#issuecomment-1263669265, or unsubscribe https://github.com/notifications/unsubscribe-auth/AXKJDQADTJ26PXHK57GLCILWA34HHANCNFSM6AAAAAAQG7TOVU . You are receiving this because you authored the thread.Message ID: @.***>

nylekyland commented 1 year ago

@nikshriv I removed the existing repo & integration, and redownloaded and set up the new configuration. Unfortunately, requests now are not working at all. I have some errors in the Home Assistant Logs:

Logger: custom_components.cync_lights.cync_hub
Source: custom_components/cync_lights/cync_hub.py:56
Integration: Cync Lights ([documentation](https://github.com/nikshriv/cync_lights))
First occurred: 8:35:27 AM (9 occurrences)
Last logged: 8:39:30 AM

Connection to Cync server reset, restarting in 15 seconds
Logger: homeassistant
Source: custom_components/cync_lights/cync_hub.py:157
Integration: Cync Lights ([documentation](https://github.com/nikshriv/cync_lights))
First occurred: 8:38:11 AM (1 occurrences)
Last logged: 8:38:11 AM

Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/config/custom_components/cync_lights/cync_hub.py", line 157, in _maintain_connection
    await self.writer.drain()
  File "/usr/local/lib/python3.10/asyncio/streams.py", line 372, in drain
    await self._protocol._drain_helper()
  File "/usr/local/lib/python3.10/asyncio/streams.py", line 171, in _drain_helper
    raise ConnectionResetError('Connection lost')
ConnectionResetError: Connection lost
Logger: aiohttp.server
Source: /usr/local/lib/python3.10/site-packages/aiohttp/web_protocol.py:405
First occurred: 8:39:35 AM (1 occurrences)
Last logged: 8:39:35 AM

Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/aiohttp/web_protocol.py", line 334, in data_received
    messages, upgraded, tail = self._request_parser.feed_data(data)
  File "aiohttp/_http_parser.pyx", line 551, in aiohttp._http_parser.HttpParser.feed_data
aiohttp.http_exceptions.BadStatusLine: 400, message="Bad status line 'Invalid method encountered'"
nikshriv commented 1 year ago

It looks like your connection to the Cync server was lost. Not sure why, but sometimes the server closes the connection. The integration will automatically reconnect after 15 seconds if that occurs. As for you bulbs not responding, that is probably due to your connection being lost.

Alternatively, in testing, I have found that most of these Cync bulbs are very flaky when it comes to Wi-Fi. Even though they report being connected, they often don't respond to any commands, even with the Cync app. I have a new update that I'll release in the next day or two that periodically checks for connected devices and only sends commands to them. It also will wait and check if the command resulted in action and will then repeat the command if necessary. Hopefully that will fix your issues.

nikshriv commented 1 year ago

@nikshriv I removed the existing repo & integration, and redownloaded and set up the new configuration. Unfortunately, requests now are not working at all. I have some errors in the Home Assistant Logs:

Logger: custom_components.cync_lights.cync_hub
Source: custom_components/cync_lights/cync_hub.py:56
Integration: Cync Lights ([documentation](https://github.com/nikshriv/cync_lights))
First occurred: 8:35:27 AM (9 occurrences)
Last logged: 8:39:30 AM

Connection to Cync server reset, restarting in 15 seconds
Logger: homeassistant
Source: custom_components/cync_lights/cync_hub.py:157
Integration: Cync Lights ([documentation](https://github.com/nikshriv/cync_lights))
First occurred: 8:38:11 AM (1 occurrences)
Last logged: 8:38:11 AM

Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/config/custom_components/cync_lights/cync_hub.py", line 157, in _maintain_connection
    await self.writer.drain()
  File "/usr/local/lib/python3.10/asyncio/streams.py", line 372, in drain
    await self._protocol._drain_helper()
  File "/usr/local/lib/python3.10/asyncio/streams.py", line 171, in _drain_helper
    raise ConnectionResetError('Connection lost')
ConnectionResetError: Connection lost
Logger: aiohttp.server
Source: /usr/local/lib/python3.10/site-packages/aiohttp/web_protocol.py:405
First occurred: 8:39:35 AM (1 occurrences)
Last logged: 8:39:35 AM

Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/aiohttp/web_protocol.py", line 334, in data_received
    messages, upgraded, tail = self._request_parser.feed_data(data)
  File "aiohttp/_http_parser.pyx", line 551, in aiohttp._http_parser.HttpParser.feed_data
aiohttp.http_exceptions.BadStatusLine: 400, message="Bad status line 'Invalid method encountered'"

Just updated again. The new update checks to make sure that your Wifi devices are actually connected to the Cync server and respond to commands. If not, commands are routed to other devices that are connected. Response to commands is also checked and if no response, the commands are repeated. Hopefully this will make the integration more reliable. Let me know if this works for you.

nylekyland commented 1 year ago

@nikshriv I just got the latest version and everything is working perfectly for me now. Turning on/off light requests take effect immediately. Thank you so much for fixing this!

nikshriv commented 1 year ago

That's awesome! It has taken a lot of tries because these Cync devices are very quirky! Glad it's finally working for you

marc3k18 commented 1 year ago

I'm using directly the switch because the room are not working for me. I have a group in a room and it do not work. It's happen for all the switch/dimmer for the on/off.

Marc-André Ouellette @.***

Le mer. 7 sept. 2022, 8 h 56 p.m., nikshriv @.***> a écrit :

I will need a little more detail. Are you controlling these switches with the room controlling switch or directly with the individual switch? Which device(s) are affected? (Please refer to your configuration information that you posted a few months ago). Is the behavior the same when you attempt to turn off the switch, or does it only occur when turning it on?

— Reply to this email directly, view it on GitHub https://github.com/nikshriv/cync_lights/issues/6#issuecomment-1240072688, or unsubscribe https://github.com/notifications/unsubscribe-auth/AXKJDQDYDWP3H6B27TZG4DLV5E2SJANCNFSM6AAAAAAQG7TOVU . You are receiving this because you authored the thread.Message ID: @.***>

ac0mputerguru commented 1 year ago

The only problem I had was when I changed my Cync password. I had to reinstall your integration to get back to the user name/password option. Other than that, works with two bulbs and a switch.