Betree / magicblue

💡 Unofficial Python API to control Magic Blue bulbs over Bluetooth
MIT License
100 stars 23 forks source link

API Usage #37

Closed Raynman77 closed 7 years ago

Raynman77 commented 7 years ago

When using magicblue as an API, how can we avoid using the default address type PUBLIC?

Betree commented 7 years ago

I guess you found the solution, if not you can set the version to 9 or 10 to use a public address.

Raynman77 commented 7 years ago

Can you elaborate on this? How would I go about setting the version number in my python code when importing magicblue?

Betree commented 7 years ago

When instantiating MagicBlue accepts the following parameters : MagicBlue(mac_address, version=7, addr_type=None)

You should always prefer using version. However, if you're using v6 (which hasn't been released on pypi yet, only on master branch) or if you have a good reason to force the address type you can pass btle.ADDR_TYPE_PUBLIC or btle.ADDR_TYPE_RANDOM as a third parameter.

So ideally (replace 9 by whatever your version is) :

bulb = MagicBlue('xx:xx:xx:xx:xx:xx', 9)

Or if you really need to force address type

from bluepy import btle bulb = MagicBlue('xx:xx:xx:xx:xx:xx', 6, btle.ADDR_TYPE_PUBLIC)

Please let met know if your version is not automatically supported; as we intend to cover all versions of magicblue this could be valuable information.

Raynman77 commented 7 years ago

@Betree Thanks for the info & updating the usage details. Hopefully this will improve my experience. These bulbs seem a little flakey, but thats just my opinion. They were a gift and I was hoping to find a way to integrate these into some home automation by using the Raspberry Pi as a hub. Thanks for your work on this project!

Betree commented 7 years ago

Have you checked HomeAssistant ? This component may help you for your automation project

Raynman77 commented 7 years ago

@Betree I'm using a Vera Home Controller as the main control point. It's very open source alone. However, the bluetooth feature built-in to the Vera Plus is still very new-ish to the Mios team whom assists in module integration for the unit. So for now bluetooth is limited to one rgb bulb by "Revogi" and that bulbs like $30-$40. These MagicBlue bulbs were a gift to me so I was just messing around with them to see how far I could take it as well as avoiding putting the app on my phone. I didn't agree with all the permissions that were listed nor did I feel like changing it's permissions in settings.

I'm using the Raspberry Pi to control the bluetooth bulbs and my Vera Unit will talk to the Pi. I can tcp to through my network to the Vera Unit.....in which will also give me control through Alexa.

Raynman77 commented 7 years ago

@Betree When calling "set_effect" method in API usage, can you give an example expression with the correct parameter syntax? This is not working as I interpreted: bulb.set_effect(green_blue_cross_fade, 5)

Betree commented 7 years ago

You can use it like this :

from magicbluelib import MagicBlue, Effect

bulb = MagicBlue('xx:xx:xx:xx:xx:xx', 6, btle.ADDR_TYPE_PUBLIC)
bulb.set_effect(Effect.green_blue_cross_fade, 5)
Raynman77 commented 7 years ago

@Betree Thanks again. I looked at the library and noticed that I needed to access the class "Effect", but did not realize that it needed to be included in the import. So, thank you for this.