Coder Social home page Coder Social logo

alexhorn / libhueble Goto Github PK

View Code? Open in Web Editor NEW
19.0 19.0 11.0 37 KB

A library for controlling Philips Hue lights via Bluetooth

License: BSD 3-Clause "New" or "Revised" License

Python 100.00%
bluetooth bluetooth-low-energy home-automation philips-hue

libhueble's People

Contributors

alexhorn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

mrv96 honsa

libhueble's Issues

Factory reset may not be needed

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

Always getting EOFError when trying to turn on the bulb

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.

Can't pair to light

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.