alexhorn / libhueble Goto Github PK
View Code? Open in Web Editor NEWA library for controlling Philips Hue lights via Bluetooth
License: BSD 3-Clause "New" or "Revised" License
A library for controlling Philips Hue lights via Bluetooth
License: BSD 3-Clause "New" or "Revised" License
Hey, a week ago in my spare time I started doing the same thing that you're doing. I am using different technologies (such as pygatt) but I see that we have started from the self-same resources.
During my own research I have noticed something that I have not found written anywhere, so I thought I would share it. If you open the Hue BT app, then go to Settings -> Voice Assistants -> [Pick one assistant] -> Click on "Make visible", then the bulb can be paired. At that point you will be able to control the bulb from both the smartphone and the pc.
I have only tested this on one bulb so I'm not sure how much it is reliable. If you can try it yourself, let me know
My setup:
Rpi0 W, Philips Hue white GU10 (paired and trusted via bluetoothctl)
My script:
import libhueble
import asyncio
async def main():
lamp = libhueble.Lamp('C1:14:8A:F4:FA:CC')
await lamp.connect()
print('Connected.')
try:
await lamp.set_power(True)
await lamp.set_brightness(1.0)
# await lamp.set_color_rgb(1.0, 0.0, 0.0)
finally:
await lamp.disconnect()
asyncio.run(main())
Error:
Traceback (most recent call last):
File "/home/pi/libhueble/src/test.py", line 15, in <module>
asyncio.run(main())
File "/usr/lib/python3.9/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
File "/usr/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
return future.result()
File "/home/pi/libhueble/src/test.py", line 9, in main
await lamp.set_power(True)
File "/home/pi/libhueble/src/libhueble.py", line 52, in set_power
await self.client.write_gatt_char(CHAR_POWER, bytes([1 if on else 0]), response=True)
File "/home/pi/.local/lib/python3.9/site-packages/bleak/backends/bluezdbus/client.py", line 707, in write_gatt_char
reply = await self._bus.call(
File "/home/pi/.local/lib/python3.9/site-packages/dbus_fast/aio/message_bus.py", line 337, in call
await future
File "/home/pi/.local/lib/python3.9/site-packages/dbus_fast/aio/message_bus.py", line 404, in _message_reader
if self._unmarshaller.unmarshall():
File "/home/pi/.local/lib/python3.9/site-packages/dbus_fast/_private/unmarshaller.py", line 332, in unmarshall
self._read_header()
File "/home/pi/.local/lib/python3.9/site-packages/dbus_fast/_private/unmarshaller.py", line 271, in _read_header
self.read_to_offset(HEADER_SIGNATURE_SIZE)
File "/home/pi/.local/lib/python3.9/site-packages/dbus_fast/_private/unmarshaller.py", line 174, in read_to_offset
raise EOFError()
EOFError
a part of unmarshaller.py:
def read_to_offset(self, offset: int) -> None:
"""
Read from underlying socket into buffer.
Raises MarshallerStreamEndError if there is not enough data to be read.
:arg offset:
The offset to read to. If not enough bytes are available in the
buffer, read more from it.
:returns:
None
"""
start_len = len(self.buf)
missing_bytes = offset - (start_len - self.offset)
if self.sock is None:
data = self.stream.read(missing_bytes)
else:
data = self.read_sock(missing_bytes)
if data == b"":
raise EOFError()
This seems to be indicating that the pi can't read data from the bulb?!
I'm not sure what I did wrong here. Help is appreciated.
This isn't really a problem with your library, since I haven't been able to use your library, because I can't pair to my light. The Hue BT app seems to be deprecated. The Hue BT app is still available in the android app store, but when running it, it just redirects to the regular Hue app. Within the regular Hue app I don't see any way of enabling Amazon Alexa. Nor do I see any settings for any other voice assistants. Therefore I can't follow this step:
In the Hue BT app, go to Settings > Voice Assistants > Amazon Alexa and tap Make visible.
When I try to pair, this is what happens:
$ sudo bluetoothctl
Agent registered
[CHG] Controller 00:28:F8:5B:5E:5E Pairable: yes
[bluetooth]# power on
Changing power on succeeded
[bluetooth]# scan on
Discovery started
[CHG] Controller 00:28:F8:5B:5E:5E Discovering: yes
[NEW] Device FF:FA:CC:E6:73:0D light1
[bluetooth]# pair FF:FA:CC:E6:73:0D
Attempting to pair with FF:FA:CC:E6:73:0D
[CHG] Device FF:FA:CC:E6:73:0D Connected: yes
Failed to pair: org.bluez.Error.AuthenticationFailed
[CHG] Device FF:FA:CC:E6:73:0D Connected: no
$
I get the error message Failed to pair: org.bluez.Error.AuthenticationFailed
with all of my 4 lights. Do you know how to help?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.