Has anyone looked at this bulb http://www.gearbest.com/smart-light-bulb/pp_230349.html, I’ve got a couple they are pretty cheap and come in 3 flavours (E26/7 and B22) and with the app you can do plenty with them, however I want to control them via my RPI3 and this https://github.com/Betree/magicblue has been written by Betree in python, so my question is would it be possible to integrate into HA? I can currently control them with scripts using commandline (sudo magicblueshell -c ‘set_color red’ -m C7:17:1D:43:39:03) but it would be nice if they were integrated with HA.
I haven’t been able to integrate MB bulb with HA yet so I’m still using scripts to control them. As for your bulb I couldn’t find any python to control it so I’m guessing that it would not integrate with HA, unless you can find out what codes the bulb is using.
Hey, I am the main developer of magicblue unofficial API.
I just found out about this post and the HomeAssistant project and it looks really cool
As you said the API is written in python 3 so it shouldn’t be complicated to integrate. Project can be used in command line as you’re doing now in your scripts but Python API is pretty straightforward too :
>>> from magicbluelib import magicblue
>>> bulb_mac_address = 'XX:XX:XX:XX:XX:XX'
>>> bulb = MagicBlue(bulb_mac_address)
>>> bulb.connect()
>>> bulb.set_color([255, 0, 0]) # Set red
>>> bulb.set_random_color() # Set random
>>> bulb.turn_off() # Turn off the light
>>> bulb.turn_on() # Set white light
Hey @Betree, I have a single bulb that i have bought in error so I am going to have a play with the AppDaemon in HomeAssistant to see if i can get some sort of control over it as a trial via a standard Python script, then i will look at a custom light platform
Also will i need the bulb to have just turned on in order to get a connection to it? Once connected will the bulb remember the source of the connection for the next time?
Unfortunately after reinstalling my bluez version, following the steps, hciconfig no longer returns any results.
Bluetooth service is running, but there appears to be no devices anymore.
So i thinks this going to take a bit longer, last resort will be a reinstall of raspbian, but as that will knock out all my lighting in the house it is a definite last resort.
I feel your pain, it’s taken me a good two weeks to get my ble working properly, as although I use a RPI3 I use an external dongle for bluetooth
Good luck getting yours working.
Managed to control the bulb from the shell script (some odd errors but it worked).
Then tried to put a quick python script together, However the first line failed
pi@raspberrypi:~/magicblue $ python3 MagicBlue.py
Traceback (most recent call last):
File "MagicBlue.py", line 1, in <module>
from magicbluelib import magicblue
ImportError: No module named 'magicbluelib'
If i run via the python shell:
pi@raspberrypi:~/magicblue $ python
Python 2.7.9 (default, Sep 17 2016, 20:26:04)
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from magicbluelib import magicblue
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named magicbluelib
>>>
(Full disclosure, i am a c# / javascript dev by trade, Python NOOB. So could well just be a stupid thing like paths)
Your feedback about V10 compatibility will be valuable, don’t hesitate to open an issue on Github to report bugs or installation specificities.
For your current problem, I assume you simply cloned the repo. The easiest way to use magicblue is to install it, either by calling python3 setup.py install in your cloned repo or directly with :
Install was done following the readme, so i used the pip3 install command.
With the corrected import line, running from the Python shell as sudo i now get:
pi@raspberrypi:~ $ sudo python
Python 2.7.9 (default, Sep 17 2016, 20:26:04)
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from magicblue import MagicBlue
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "magicblue/MagicBlue.py", line 1, in <module>
from magicblue import MagicBlue
ImportError: cannot import name MagicBlue
>>>
If i go via a script (after making the mistake of using CAPS in my mac address) i can get control.
A quick test in Home Assistant was unsuccessful,
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-0uc30b7c-build/
The path is a director where home assistant seems to unpack things
Are you sure your default python is python 3 ? On most debian-like systems python command is mapped to python2.7. You can run python --version to check that.
If this is your problem, you can usually run python 3 with python3 command. Ubuntu and some others also provide a pip3 package. Python 2 and Python 3 environments are totally separated (libraries you install for one version are only installed for this version).
Also, MagicBlue is only compatible with Python3 but it should be fine as HomeAssistant run on Python 3 too
Got my python script working in isolation from Home Assistant so step 1 is done.
So i have now installed the magicblue library with a target of the deps folder (as per Home Assistant instructions) which has stopped the setup.py egg_info error. So another step forward!
However the start of the Home Assistant service now gets stuck and does not load any of my lights. I cannot see an errors but the load gets halted.
My theory is that the connection to the bulb is not going through, I think this may be sue to the need for the python script needing to run under sudo to access the bluetooth but Home Assistant not running it’s components in the same manner.