Mote and Apple Homekit

Mote arrived yesterday and is working well.
I tried out the Apple Homekit integration (via mote_api.py and Homebridge … and there are a few problems that I think mote_api.py could handle better.

Error as follows:

Traceback (most recent call last): File "/usr/share/pyshared/flask/app.py", line 1836, in __call__ return self.wsgi_app(environ, start_response) File "/usr/share/pyshared/flask/app.py", line 1820, in wsgi_app response = self.make_response(self.handle_exception(e)) File "/usr/share/pyshared/flask/app.py", line 1403, in handle_exception reraise(exc_type, exc_value, tb) File "/usr/share/pyshared/flask/app.py", line 1817, in wsgi_app response = self.full_dispatch_request() File "/usr/share/pyshared/flask/app.py", line 1477, in full_dispatch_request rv = self.handle_user_exception(e) File "/usr/share/pyshared/flask/app.py", line 1381, in handle_user_exception reraise(exc_type, exc_value, tb) File "/usr/share/pyshared/flask/app.py", line 1475, in full_dispatch_request rv = self.dispatch_request() File "/usr/share/pyshared/flask/app.py", line 1461, in dispatch_request return self.view_functions[rule.endpoint](**req.view_args) File "/home/pi/Pimoroni/mote_api.py", line 65, in set_colour mote_on(colour) File "/home/pi/Pimoroni/mote_api.py", line 22, in mote_on r, g, b = hex_to_rgb(c) File "/home/pi/Pimoroni/mote_api.py", line 19, in hex_to_rgb return tuple(int(value[i:i + length / 3], 16) for i in range(0, length, length / 3)) File "/home/pi/Pimoroni/mote_api.py", line 19, in <genexpr> return tuple(int(value[i:i + length / 3], 16) for i in range(0, length, length / 3)) ValueError: invalid literal for int() with base 16: 'NaN'

I suspect that Siri or Apple Home application is not setting some of the values - e.g. Color - when doing a simple On command - which results in error and then issues with Apple thinking device is on when it is not.

You might want to give this a try, I’m not sure if it’ll fix your problem, but if you’re using the HomeKit API then your eyes would be greatly appreciated on this code: https://github.com/pimoroni/mote/pull/17

I’ll give it a try.
Am also starting to look at getting an old 1st Gen colour bulb remote control working with it.
Family not convinced that they have to get out phone to turn lights on (and particularly off).

Aha - version control issues I think …

I used the code from this post
https://learn.pimoroni.com/tutorial/sandyj/using-mote-with-homekit-and-siri
but that is not the same as in github (master)
e.g. /on replaced by one that requires channel number or “all”.
So this breaks the homebridge integration.
The original API calls should be retained - and then (for example) a /on should then call the new function with “all”.
Alternative is to update the homebridge config file - but then that makes it harder for anyone who has followed the example and then updates the mote scripts.
So much for the script having a version 1.0 endpoint ;)

Also - the MoteEffects.py needs to be added to the pull request.

Edit: Also - the returns from API when used by HomeKit/Homebridge will, presumably have to provide the best guess reply on the assumption that all pixels are in the same state.
Perhaps provide each channel as a different device to allow a set of pixels to be individually controlled - but probably not required.

I’ve added a version of this comment to the GitHub page.

I’ve tried out the tutorial for setting up mote with homebridge from here:
Using-Mote-with-homekit-and-siri
but it doesn’t seem to work anymore.

To be more specific,I can use the curl commands to turn the LEDs on (flask & python script working), I can start homebridge (without errors), I can even add homebridge to the ‘Home-App’ but the device ‘mote’ is greyed out and can’t be controlled. In the details of ‘Mote’, it simply says device not supported.

I’m currently using an iphone 5s with ios11.4.1. I did manage to get this up and running on ios10 a year ago so I’m guessing it’s something related to the difference between ios10 and 11. Does someone have any ideas on how to fix this?

@ace Did you get it working? I saw your other post about the Unicorn pHAT project.

Hi Sandy, thanks for your reply. The unicorn pHAT project from instructables uses a ready-made image made more than a year ago. It was based on your ‘Controlling mote with homekit and Siri’ tutorial. Since the Raspberry Pi is set up as an AP, it works offline.

For some reason, that image still works (maybe because it’s offline?), even on ios11.4.1. The problem is that for some reason the same tutorial doesn’t work anymore on a fresh install of Raspbian (Stretch). The accessory shows up in the ‘Home’ App, yet can’t be controlled and is greyed out.

Since the only difference between the current and old image should be the AP mode on the rpi, I’m guessing it’s something related to sending or receiving data. But since neither Homebridge nor the Debug mode of the mote_api.py file show any errors, I can’t figure out how to debug this issue.

I just tried my set-up using Home app on iOS 11 (iPad) and iOS 10 (iPhone 5) and both allowed me to turn Mote on/off and play with the colours.
My set-up started from following the same initial instructions but I might well have changed some things along the way (see my earlier post in this thread from when I did my initial install).

Am also controlling it from Google AIY Voice Kit (version 1) -
OK Google, Kitchen Light On
etc

@ PaulWebster

For some reason, I’ve still not managed to get this up an running. I’ve tried the rpi3b, the pi zero w and followed the instructions 2 times on a fresh install. All of them lead to the same point, i.e. where the accessory can be added but nor controlled.

Here’s a shirt clip of what happens during pairing:
com-optimize

The accessory is greyed out after pairing. It can’t be controlled. In the details it simply says that the device is not supported.

I can confirm that there are no problems with the python code or the config.json file. Homebridge doesn’t show any erros in Debug mode too.

@sandyjmacdonald
@PaulWebster
Some time ago, I made a backup image of Jessie running homebridge properly. Even now, it works.

When I try to set up homebridge on Raspbian Stretch though , the devices can’t be controlled.

After comparing both images, I realised that the only difference between jessie and stretch is that avahi (mdns) comes pre-installed on stretch. Is it possible that this might be the cause?

Could you please try the tutorial for ‘Controlling Mote with Siri’ on Raspbian Stretch?

Mine is old and still on Jessie.
Not having that daemon running might well prevent Apple-style discovery.
Should be straight forward to install via apt-get and run it.

There is a description on how to install and configure it at
https://elinux.org/RPi_Advanced_Setup (search that page for avahi)

@PaulWebster
Thanks for the info that it really does work on Jessie. Without doubt, the problem lies within some part of avahi itself.
On Stretch, avahi-daemon is up and running after running homebridge, yet can’t be discovered by a Bonjour browser. This wasn’t the case with Jessie. Must be the reason why the devices can’t be controlled.

I’ll take a look at the link you posted and try to figure out a way to get this working.

It would be nice if Sandy could kindly update the Mote tutorial for support on Stretch.

Sorry that it’s taken so long, but I finally got round to trying all this out again on Stretch and with the newly-released iOS 12, and I’ve updated the tutorial. :-)

It turns out the fix was frustratingly easy. I just had to add "service": "Light" to the config.json file as part of the better-http-rgb accessory.

Give it a try and let me know how it goes!

https://learn.pimoroni.com/tutorial/sandyj/using-mote-with-homekit-and-siri

Well done.
How did you manage to find that was the problem?

Comparing the config example in the latest version of the GitHub repo to the version I had in the tutorial. That line was the only difference. I also worked through the whole of the tutorial though, to make sure everything was a-ok. :-)