home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
71.9k stars 30.13k forks source link

Yeelight: Bulb closed the connection. (Yeelight 1S YLDP13YL color4) #35202

Closed Hukuma1 closed 3 years ago

Hukuma1 commented 4 years ago

The problem

Getting lots of errors in logs regarding light connection. Lights turn on/off for a split second periodically at random intervals. Voice assistants sometimes say they are unable to control the lights. Have a strong wifi signal; doesn't seem to be a LAN issue.

Using latest Yeelight 1S color bulbs YLDP13YL. Device model name: color4 (not listed in integration page)

Environment

Problem-relevant configuration.yaml

discovery:
  ignore:
    - yeelight
yeelight:
  devices:
    192.168.0.12:
      name: Desktop Light
    192.168.0.13:
      name: Living Room Light
    192.168.0.14:
      name: Kitchen Light
    192.168.0.15:
      name: Bedroom Light

Traceback/Error logs

Log Details (ERROR)
Logger: homeassistant.components.yeelight
Source: components/yeelight/__init__.py:160
Integration: Yeelight (documentation, issues)
First occurred: May 2, 2020, 9:23:37 PM (136 occurrences)
Last logged: 12:03:45 PM

Unable to update device 192.168.0.13, Living Room Light: Bulb closed the connection.
Unable to update device 192.168.0.14, Kitchen Light: Bulb closed the connection.
Unable to update device 192.168.0.15, Bedroom Light: Bulb closed the connection.
Unable to update device 192.168.0.13, Living Room Light: A socket error occurred when sending the command.

Additional information

Have not attempted to turn off Music Mode connection method, but would rather keep that on so 60 commands per minute limit is bypassed. (edit: Default state of integration does not use Music Mode)

Using stock firmware which is 1.3.2_0018. Latest firmware I can update to is 2.0.6_0027 but I'm wary of updating because I hear many complaints of connection/color accuracy issues with newest firmware?

probot-home-assistant[bot] commented 4 years ago

yeelight documentation yeelight source (message by IssueLinks)

probot-home-assistant[bot] commented 4 years ago

Hey there @rytilahti, @zewelor, mind taking a look at this issue as its been labeled with a integration (yeelight) you are listed as a codeowner for? Thanks! (message by CodeOwnersMention)

Hukuma1 commented 4 years ago

Correction: Was never using music mode. (didn't realize default setting is music mode off)

yeegit

Even updated router to a robust OpenWRT setup. Still same issue.

ceesvanegmond commented 4 years ago

Same issue here as well.

perseus177 commented 4 years ago

Same issue here as well, also with Yeelight JIAOYUE YLXD02YL 650

Hukuma1 commented 4 years ago

Can you all also please post your firmware versions for your devices? Just curious if same issues happening and you're on latest fw.

Critical-Impact commented 4 years ago

Seeing this as well. Have got fairly solid wifi and have actually replaced wifi with a ubiquti access point. I use zigbee switches for them but I haven't seen any delay. It seemed to be working far better in the past and nothing had really changed bar updating firmware/updating HA.

Seeing a lot of this in the logs Unable to update device yee-bedroomstrip, Strip2: Bulb closed the connection. Unable to update device yee-kitchen1, Light2: A socket error occurred when sending the command. Unable to update device yee-lounge1, Light5: A socket error occurred when sending the command. Unable to update device yee-gym1, Gym Light 1: A socket error occurred when sending the command. Unable to update device yee-ensuite, Light1: A socket error occurred when sending the command.

V2 bulbs are at 2.0.6_0065 V1 bulbs are at 1.4.2_0076

ceesvanegmond commented 4 years ago

same here. Aso using unifi and ubiquiti stuff. All my b2 bulbs are on latest version which is 2.0.6_0065

kukachik commented 4 years ago

Got it after update to 110

Logger: homeassistant.components.yeelight
Source: components/yeelight/__init__.py:160
Integration: Yeelight (documentation, issues)
First occurred: 19:26:53 (83 occurrences)
Last logged: 20:38:07

Unable to update device 192.168.50.243, Моя спальня: Bulb closed the connection.

Worked fine in 109.

PS Problem was fixed by physical reset yeelight.

ceesvanegmond commented 4 years ago

Resetting yeelight isn't working here. Constant I get this error:

'A socket error occurred when sending the command.'

Hukuma1 commented 4 years ago

Home Assistant 0.110.3

2020-05-26 07:38:05 ERROR (SyncWorker_16) [homeassistant.components.yeelight] Unable to update device 192.168.1.17, Bedroom Wall Light Left: Bulb closed the connection.
2020-05-26 08:09:04 ERROR (SyncWorker_6) [homeassistant.components.yeelight] Unable to update device 192.168.1.17, Bedroom Wall Light Left: Bulb closed the connection.
2020-05-26 08:10:31 ERROR (SyncWorker_6) [homeassistant.components.yeelight] Unable to update device 192.168.1.14, Living Room Light: Bulb closed the connection.
2020-05-26 08:31:10 ERROR (SyncWorker_3) [homeassistant.components.yeelight] Unable to update device 192.168.1.14, Living Room Light: Bulb closed the connection.
2020-05-26 08:37:51 ERROR (SyncWorker_0) [homeassistant.components.yeelight] Unable to update device 192.168.1.16, Bedroom Light: A socket error occurred when sending the command.
2020-05-26 08:39:24 ERROR (SyncWorker_17) [homeassistant.components.yeelight] Unable to update device 192.168.1.16, Bedroom Light: A socket error occurred when sending the command.
2020-05-26 08:42:04 ERROR (SyncWorker_16) [homeassistant.components.yeelight] Unable to update device 192.168.1.16, Bedroom Light: Bulb closed the connection.
2020-05-26 09:17:44 ERROR (SyncWorker_17) [homeassistant.components.yeelight] Unable to update device 192.168.1.18, Bedroom Wall Light Right: Bulb closed the connection.
2020-05-26 10:11:55 ERROR (SyncWorker_2) [homeassistant.components.yeelight] Unable to update device 192.168.1.18, Bedroom Wall Light Right: Bulb closed the connection.
2020-05-26 10:27:23 ERROR (SyncWorker_5) [homeassistant.components.yeelight] Unable to update device 192.168.1.17, Bedroom Wall Light Left: Bulb closed the connection.
2020-05-26 10:30:54 ERROR (SyncWorker_7) [homeassistant.components.yeelight] Unable to update device 192.168.1.14, Living Room Light: Bulb closed the connection.
2020-05-26 10:41:11 ERROR (SyncWorker_11) [homeassistant.components.yeelight] Unable to update device 192.168.1.14, Living Room Light: Bulb closed the connection.
2020-05-26 10:44:54 ERROR (SyncWorker_8) [homeassistant.components.yeelight] Unable to update device 192.168.1.18, Bedroom Wall Light Right: Bulb closed the connection.
2020-05-26 10:49:56 ERROR (SyncWorker_5) [homeassistant.components.yeelight] Unable to update device 192.168.1.14, Living Room Light: Bulb closed the connection.
2020-05-26 11:34:23 ERROR (SyncWorker_14) [homeassistant.components.yeelight] Unable to update device 192.168.1.18, Bedroom Wall Light Right: Bulb closed the connection.
2020-05-26 11:53:59 ERROR (SyncWorker_9) [homeassistant.components.yeelight] Unable to update device 192.168.1.17, Bedroom Wall Light Left: Bulb closed the connection.
2020-05-26 12:07:47 ERROR (SyncWorker_11) [homeassistant.components.yeelight] Unable to update device 192.168.1.14, Living Room Light: Bulb closed the connection.
2020-05-26 12:14:36 ERROR (SyncWorker_1) [homeassistant.components.yeelight] Unable to update device 192.168.1.18, Bedroom Wall Light Right: Bulb closed the connection.
2020-05-26 12:34:14 ERROR (SyncWorker_12) [homeassistant.components.yeelight] Unable to update device 192.168.1.17, Bedroom Wall Light Left: Bulb closed the connection.
2020-05-26 12:37:20 ERROR (SyncWorker_17) [homeassistant.components.yeelight] Unable to update device 192.168.1.17, Bedroom Wall Light Left: Bulb closed the connection.
2020-05-26 13:06:13 ERROR (SyncWorker_4) [homeassistant.components.yeelight] Unable to update device 192.168.1.18, Bedroom Wall Light Right: Bulb closed the connection.
2020-05-26 13:12:50 ERROR (SyncWorker_4) [homeassistant.components.yeelight] Unable to update device 192.168.1.14, Living Room Light: Bulb closed the connection.
2020-05-26 13:13:27 ERROR (SyncWorker_10) [homeassistant.components.yeelight] Unable to update device 192.168.1.18, Bedroom Wall Light Right: Bulb closed the connection.
2020-05-26 13:21:37 ERROR (SyncWorker_7) [homeassistant.components.yeelight] Unable to update device 192.168.1.14, Living Room Light: Bulb closed the connection.
2020-05-26 13:31:31 ERROR (SyncWorker_1) [homeassistant.components.yeelight] Unable to update device 192.168.1.17, Bedroom Wall Light Left: Bulb closed the connection.
2020-05-26 14:17:24 ERROR (SyncWorker_9) [homeassistant.components.yeelight] Unable to update device 192.168.1.18, Bedroom Wall Light Right: Bulb closed the connection.
rytilahti commented 4 years ago

Did you enable the LAN mode after reseting the bulb? Does yeecli work on the devices?

Critical-Impact commented 4 years ago

I can only speak for myself but I have LAN mode on on all devices. The issue I'm getting is intermittent. Basically I turn a light on and it might take a few seconds for it to come on. Then if I switch it on and off and works fine. Come back 30 minutes to an hour later and the switch again is delayed. I'm getting those same messages in the log.

Hukuma1 commented 4 years ago

LAN mode is on. yeecli works fine. The issue is the bulb just breaks connection and would sometimes drop commands if you catch it in that broken state I assume. Firmware issue I'm guessing. :/

root@DietPi:~# yee --ip=192.168.1.14 toggle
Toggling the bulb...
root@DietPi:~# yee --ip=192.168.1.14 toggle
Toggling the bulb...
root@DietPi:~# yee --ip=192.168.1.14 turn on
Turning the bulb on...
root@DietPi:~# yee --ip=192.168.1.14 rgb ff00ff
Setting the bulb to RGB ff00ff...
root@DietPi:~# yee --ip=192.168.1.14 brightness 100
Setting the bulb to 100 brightness...
root@DietPi:~# yee --ip=192.168.1.14 toggle
Toggling the bulb...
ekozan commented 4 years ago

Yeah same here yeelink.light.color4 firmware 1.3.2_0018

Hukuma1 commented 4 years ago

Any chance someone can take a look into if it's because the Yeelight phones home (China) and maybe a latency issue of some sort? I'm in the US. Wondering if ultimately an emulated Yeelight cloud of sorts has to be implemented to keep the cloud completely contained to your network. I don't think LAN mode routes all Yeelight traffic to stay local.

ceesvanegmond commented 4 years ago

@Hukuma1 That's not the issue. I've blocked all outgoing connections of Yeelight and I'm having the same issues. Also when not blocking the connection = same problem.

Hukuma1 commented 4 years ago

Yikes. So even Wiresharking packets would be useless to further debug this?

ceesvanegmond commented 4 years ago

@Hukuma1 I don't know man. I'm not that technical. Its so a weird error. Dont know what to do with it. U have Ubiquiti stuff as well?

Critical-Impact commented 4 years ago

I've got a Ubiquiti AP acting as my only wireless I've been able to fix this myself by doing a few things(not sure which actually fixed the errors). 1) Make sure the 2.4ghz and 5ghz APs have different names 2) Make sure the 2.4ghz AP has a specific channel set rather than being on auto. I'm thinking maybe the lights don't like to switch channels and ubiquiti has some sort of channel switching built in? 3) Disabled a brother printer integration I had as I generally had the printer offline and it was spamming errors in the log

Hukuma1 commented 4 years ago

I don't have a Ubiquiti device. But I do have a merged 2.4/5ghz network name. Could that really be it? Will also try keeping constant channel.

Will report back if this changes anything. Thanks!

syphernl commented 4 years ago

I don't have a Ubiquiti device. But I do have a merged 2.4/5ghz network name. Could that really be it?

I've been using that for the past years and it hasn't caused issues on my end.

Yesterday I upgraded to 0.111 which was not working properly (for me) so I reverted back to 0.110.7.

However, after that all of my Yeelight devices (a bulb, the bedside lights & the meteorite) were all showing up as "Unavailable" in HA and the "Bulb has closed the connection" message in the logs.

Powercycling the bulbs didn't work just like keeping one offline for a few hours. Result is that all bulbs still show as unavailable.

The strange thing is that it works just fine in the Yeelight app and even with this:

from yeelight import Bulb
bulb = Bulb("192.168.110.12")
bulb.turn_on()
'ok'

The bulb turns on just fine. turn_off works too. get_properties() shows all attributes. This uses the very same Yeelight library as HASS is so I would assume there is something wrong in that part?

My desk light is acting up too:

>>> from yeelight import Bulb
>>> bulb = Bulb("192.168.110.27")
>>> bulb.turn_on()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<decorator-gen-7>", line 2, in turn_on
  File "/srv/hass/lib/python3.8/site-packages/yeelight/main.py", line 128, in _command
    result = self.send_command(method, params).get("result", [])
  File "/srv/hass/lib/python3.8/site-packages/yeelight/main.py", line 455, in send_command
    raise BulbException(response["error"])
yeelight.main.BulbException: Bulb closed the connection.
>>> bulb.turn_off()
'ok'
>>> bulb.turn_on()
'ok'
>>> bulb.turn_off()
'ok'

The part where it gave the "closed connection" message it still turned on. Could it be that the component considers the bulb unavailable when it gets one of the closed connections and simply doesn't attempt querying it again?

Edit: Actually, I think I'm on to something here! I simply deleted the entities from HASS and restarted. Afterwards my devices show up fine and are controllable again. So ISTM that something in the entity store has been corrupted.

ezaton commented 4 years ago

I can add that following Yeelight upgrade to version 2.x, I have had a lot of problems. It seems that when the devices are blocked from accessing the internet, they ignore DHCP lease times, and renew every five minutes. When they renew (without altering their IP, and still responding to ping) the Yeelight devices "disappear" from HA for a few seconds, and then return, with a "device closed connection" log message. I have had to open their Internet access (which I do not like) just to work around this, because every five minutes is intolerable to me...

Critical-Impact commented 4 years ago

I had mine start dropping out again and I think it's possible by Ubiquiti configuration reset. I noticed that turning "Enable multicast enhancement (IGMPv3)" on appeared to make all the lights work properly again. Not sure if there is an equivalent for other routers/wifi.

Varjo1 commented 4 years ago

I'm also having issues with V2 bulbs (2.0.6_0065) similar to what others are reporting. Bulbs constantly unavailable and disappearing.

Bashy commented 4 years ago

Same issue here with model yeelink.light.color4, MAC ADDR begins with 44:23:7C... I have 2 others yeelink.light.color4 that are working perfectly, (those one the MAC ADDR begins with 5C:E5...) All those lights are using 2.0.6_0065 firmware.

yeecli works, tried to hard reset the faulty bulb, the issue is still here.

david-kalbermatten commented 4 years ago

yea, same here. yeelink.link.color4 Happens a lot, makes setting up scenes an absolute pain in the butt. If this is a firmware issue, please let us know, so we can contact yeelight's support and annoy them into fixing their shit :D

Edit

I dug through a huge Yeelight forum thread where they apparently managed to fix the issue. They released version 2.0.6_0065 of the firmware. However, it seems that our light bulbs (Model YLDP13YL) didn't get the update and now we're stuck on 2.0.6_0027 until Yeelight finally fixes their shit...

Updating to 2.0.6_0027 at least fixed the wifi drop-outs for me. Unfortunately, they still become unavailable every now and then (every 2 hours, it seems...).

Observations:

The bug(s) mainly affects the model YLDP13YL (at least for me)

Note

I had to change the server region to mainland China in order for the app to show the firmware update (2.0.6_0027).

Hukuma1 commented 4 years ago

@david-kalbermatten Firmware 2.0.6_0027 messes with HomeKit brightness. You cannot achieve same level of brightness unless you fire up Yeelight app. I have reported the issue over 2 months ago and they assured me I would be added to beta firmware whitelist. At this rate they'll release a new version bulb and not even fix this one. As seems to be the case of the V2 bulbs before 1S came out. Very annoyed. Wish someone would hack the firmware on these. The hardware is very capable, the software is so buggy.

david-kalbermatten commented 4 years ago

@Hukuma1 yea, it's a shame. Fortunately, I was still able to RMA it and got myself a LIFX mini bulb. More expensive, but damn does it work smoothly with Home Assistant. The brightness and color saturation are still unrivaled :D

imho, it's worth to spend the extra on LIFX and have something that works properly. Just having the rate limit for LAN control with Yeelight is a deal-breaker already.

flamewow commented 4 years ago

Got the same issues with pretty much all of my yeelight products. LED strip, ceiling lights, pendant light. Wish there was some sort of esphome for yeelight bulbs to flash it with custom firmware and stop those issues once and for all

Hukuma1 commented 4 years ago

Everyone that’s having issues, I opened a ticket with creator of Yeelight-CLI. Could you please help debug in case this is something that can be patched up on that end? (Still unsure if the issue is HA, YCLI, or firmware right now, so trying to narrow it down since HA devs here haven’t chimed in for a long while...)

https://github.com/sgbasaraner/yeelight-cli/issues/4

rytilahti commented 4 years ago

The real upstream for the library used by homeassistant is here https://gitlab.com/stavros/python-yeelight . Looks like yeelight-cli is rust implementation of the API, but I recall reading somewhere (a post by @stavros of python-yeelight fame) that this is likely a firmware issue on those bulbs.

It could potentially be beneficial to make the python-yeelight logging on socket errors more verbose, at least to give out what sort of socket error it got. Any takers? The relevant part is here, I think: https://gitlab.com/stavros/python-yeelight/-/blob/master/yeelight/main.py#L452

Hukuma1 commented 4 years ago

Ah oops, mixed up my Yeelight libraries. Looks like this is the firmware issue in question: https://gitlab.com/stavros/python-yeelight/-/issues/37

Those list firmware 2.0.6_0051. I've got bulbs with factory 1.3.2_0018 and 1 that got updated to 2.0.6_0027. People above in this thread wrote that 2.0.6_0065 seems to be the magic firmware that fixes their issues. Unfortunately not every bulb has this firmware available to update to? :/

@rytilahti I think you may have tagged the wrong Stavros? But thank you for linking to the correct Yeelight library!

skorokithakis commented 4 years ago

Ah yep, I'm the proper Stavros, though the other one is a friend. I have debugged this, the bulb just never returns a confirmation and the library waits until it times out.

I think I have a workaround in mind, I might be able to implement it in a few days, though if someone wants to try it out before that, please do:

We should be able to send an "info" command after every command, and the latter should always return a response (it did in my testing). Then, all the library needs to do is ignore the second confirmation and return normally.

Hukuma1 commented 4 years ago

I'm not a coder, but I could easily try to help running whatever commands you want. If you could just please provide a step-by-step of what to try, I can paste the outcome from my testing as well. Thanks for the quick reply!

skorokithakis commented 4 years ago

I don't remember the commands off the top of my head now, unfortunately, but it's basically sending one command, the carriage return/line feed combo, then immediately a second command with another crlf.

Hukuma1 commented 4 years ago

Gotcha. Will wait if there's a test build once you have a chance and report back to what my bulbs do.

skorokithakis commented 4 years ago

I have a potential fix:

diff --git a/yeelight/main.py b/yeelight/main.py
index f446626..adb7291 100644
--- a/yeelight/main.py
+++ b/yeelight/main.py
@@ -494,7 +494,8 @@ class Bulb(object):
         _LOGGER.debug("%s > %s", self, command)

         try:
-            self._socket.send((json.dumps(command) + "\r\n").encode("utf8"))
+            cmd = json.dumps(command) + "\r\n" + '{"id": 0, "method": "get_prop", "params": []}\r\n'
+            self._socket.send((cmd).encode("utf8"))
         except socket.error as ex:
             # Some error occurred, remove this socket in hopes that we can later
             # create a new one.

Can someone with a bulb that doesn't currently work perform the following steps?

All my bulbs work so I can't really test this, I'd appreciate help if anyone has a broken bulb.

Hukuma1 commented 4 years ago

Thanks, @skorokithakis! Made the file change and here's the log:

root@DietPi:~# yee --ip=192.168.1.16 toggle
Toggling the bulb...
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/dist-packages/yeelight/main.py", line 448, in s                                                                                                         end_command
    self._socket.send((cmd).encode("utf8"))
  File "/usr/local/lib/python3.7/dist-packages/yeelight/main.py", line 242, in _                                                                                                         socket
    self.__socket.connect((self._ip, self._port))
socket.timeout: timed out

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/bin/yee", line 10, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python3.7/dist-packages/click/core.py", line 829, in __ca                                                                                                         ll__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.7/dist-packages/click/core.py", line 1259, in inv                                                                                                         oke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.7/dist-packages/click/core.py", line 1066, in inv                                                                                                         oke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.7/dist-packages/click/core.py", line 610, in invo                                                                                                         ke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/yeecli/cli.py", line 147, in togg                                                                                                         le
    bulb.toggle()
  File "<decorator-gen-9>", line 2, in toggle
  File "/usr/local/lib/python3.7/dist-packages/yeelight/main.py", line 125, in _                                                                                                         command
    result = self.send_command(method, params).get("result", [])
  File "/usr/local/lib/python3.7/dist-packages/yeelight/main.py", line 454, in s                                                                                                         end_command
    raise_from(BulbException("A socket error occurred when sending the command."                                                                                                         ), ex)
  File "/usr/local/lib/python3.7/dist-packages/future/utils/__init__.py", line 4                                                                                                         03, in raise_from
    exec(execstr, myglobals, mylocals)
  File "<string>", line 1, in <module>
yeelight.main.BulbException: A socket error occurred when sending the command.

Finally got around to issuing command on an unresponsive bulb. I did have to re-start the bulb from the socket to get it to be responsive again. But hopefully the above gives some more info.

skorokithakis commented 4 years ago

Hmm, thanks @Hukuma1. Did the bulb actually toggle?

Hukuma1 commented 4 years ago

It did not. :/

skorokithakis commented 4 years ago

Try the same command without the change? It should toggle with or without the change, I'm wondering if the bulb was frozen or something. Even when you get the original error, the bulb still responds to the command, no?

Hukuma1 commented 4 years ago

Without the change it just sits and doesn't say anything else. This happened to a bulb that I didn't even need to restart from the socket. It became 'available' shortly after and then the toggle worked again.

root@DietPi:~# yee --ip=192.168.1.16 toggle
Toggling the bulb...
skorokithakis commented 4 years ago

It doesn't say "bulb closed the connection"?

Hukuma1 commented 4 years ago

Nothing in terminal when using yeecli. I get a bunch of those in logs from HA:

Unable to turn the bulb on: Bulb closed the connection.
5:39:56 PM – Yeelight (ERROR)

and

Unable to update device 192.168.1.18, Bedroom Wall Light Right: Bulb closed the connection.
Unable to update device 192.168.1.12, Desktop Light Left: Bulb closed the connection.
Unable to update device 192.168.1.14, Living Room Light: Bulb closed the connection.
Unable to update device 192.168.1.12, Desktop Light Left: A socket error occurred when sending the command.
Unable to update device 192.168.1.15, Kitchen Light: Bulb closed the connection.
t-anjan commented 4 years ago

@skorokithakis - I am facing the same issue with the yeelight bulbs on HA. So, I am interested to find a solution to this.

On my macOS, I installed your yeecli using pip and tried yee --ip=192.168.2.209 toggle (without making any changes to the code in the packages). I got almost exactly the same error posted by @Hukuma1 . The bulbs do not toggle.

Toggling the bulb...
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/yeelight/main.py", line 447, in send_command
    self._socket.send((json.dumps(command) + "\r\n").encode("utf8"))
  File "/usr/local/lib/python3.7/site-packages/yeelight/main.py", line 242, in _socket
    self.__socket.connect((self._ip, self._port))
socket.timeout: timed out

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/bin/yee", line 8, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python3.7/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.7/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.7/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.7/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/yeecli/cli.py", line 147, in toggle
    bulb.toggle()
  File "<decorator-gen-9>", line 2, in toggle
  File "/usr/local/lib/python3.7/site-packages/yeelight/main.py", line 125, in _command
    result = self.send_command(method, params).get("result", [])
  File "/usr/local/lib/python3.7/site-packages/yeelight/main.py", line 453, in send_command
    raise_from(BulbException("A socket error occurred when sending the command."), ex)
  File "/usr/local/lib/python3.7/site-packages/future/utils/__init__.py", line 403, in raise_from
    exec(execstr, myglobals, mylocals)
  File "<string>", line 1, in <module>
yeelight.main.BulbException: A socket error occurred when sending the command.

The yeelight bulbs work perfectly with the Yeelight app, and they are all on the 2.0.6_0065 firmware (v2 bulbs).

Please let me know if there is anything I could do to help troubleshoot.

skorokithakis commented 4 years ago

Could you apply the patch upthread and try the command again, and let me know what happens? Thanks!

t-anjan commented 4 years ago

Should I make the changes in the /usr/local/lib/python3.7/site-packages/yeelight/main.py file?

========= UPDATE =============== I made the change in the above file and re-ran the same toggle command. But I got the same error.

Toggling the bulb...
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/yeelight/main.py", line 449, in send_command
    self._socket.send((cmd).encode("utf8"))
  File "/usr/local/lib/python3.7/site-packages/yeelight/main.py", line 242, in _socket
    self.__socket.connect((self._ip, self._port))
socket.timeout: timed out

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/bin/yee", line 8, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python3.7/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.7/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.7/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.7/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/yeecli/cli.py", line 147, in toggle
    bulb.toggle()
  File "<decorator-gen-9>", line 2, in toggle
  File "/usr/local/lib/python3.7/site-packages/yeelight/main.py", line 125, in _command
    result = self.send_command(method, params).get("result", [])
  File "/usr/local/lib/python3.7/site-packages/yeelight/main.py", line 455, in send_command
    raise_from(BulbException("A socket error occurred when sending the command."), ex)
  File "/usr/local/lib/python3.7/site-packages/future/utils/__init__.py", line 403, in raise_from
    exec(execstr, myglobals, mylocals)
  File "<string>", line 1, in <module>
yeelight.main.BulbException: A socket error occurred when sending the command.

I wonder if it is because of 2.4GHz vs 5GHz WiFi. My MacBook is connected to the 5GHz AC wifi, while the bulbs (I am guessing) are connected to the 2.4GHz 802.11 "n" WiFi. The SSID and password are the same for both frequencies.

Hukuma1 commented 4 years ago

I got 2.4/5 wifi with same credentials for both as well. But it technically shouldn't matter since the bulbs can only connect to 2.4, right?

skorokithakis commented 4 years ago

Yeah, that shouldn't matter. It's odd that it's timing out, since all it's doing is sending an extra command. It should just execute both, that's what it was doing in my own tests.