Marmelatze / avea_bulb

nodejs POC to control avea bulb
MIT License
20 stars 6 forks source link

Homebridge and Siri integration #4

Closed Alblahm closed 8 years ago

Alblahm commented 8 years ago

I've used this "avea_node" lib to create an accessory that works with the Homebridge NodeJS server inside a raspberry pi 2b with a usb bluetooth adapter. The pi-2b has the Kodi jarvis 16.1 installed. And I`ve installed also the NodeJS server.

In the raspberry-pi you can have the multimedia center connected to the tv, and running in background the homebridge service that remotely controls the elgato Avea light. By adding this accessory file to the homebridge, you dont need any other device (avea bulb<->raspberry). It directly connects to the light through the low energy bluetooth.

Due to the fantastic integration between homebridge and apple home app, you can also control this light using the siri voice commands on your iphone or ipad (if your device is in the same wifi network). It's great !!!!

The attached file is the corrected version after all the comments below... Luz_VerticalComedor_accessory.js.txt

Alblahm commented 8 years ago

About the switch on/off problem. When i first start the node service, it appears with an !. But if you click on it, it correctly gets the actual status. Or if you close the ios home app and reopen it also show the correct status. Ive tried to unplug and plug the light, and it works fine. But ill recheck.

thymjan commented 8 years ago

// Add properties for publishing (in case we're using Core.js and not BridgedCore.js) light.username = "FF:FF:FF:FF:FF:1A"; light.pincode = "031-45-154";

I always call the bridged version, so I leave this unchanged.

The apple tv bluetooth attack: I changed the bluetooth adapter on my raspberry. Pairing didn't work.

Alblahm commented 8 years ago

Although the comment say that is not needed, in all the tutorials i've seen, they always change this value to avoid duplicated usernames. So better, change this to a random hex combination in each accessory file, just in case. Remember that in the other side is the ios home app and we dont know what does this app inside.

thymjan commented 8 years ago

To figure things out, I optimized the logging once again. I also included displaying the actual rssi: dining_accessory.js.txt

In noble.on("discover", function(peripheral){...}); the peripheral.connect([callback(error)]); was called twice. I changed this to:

noble.on("discover", function(peripheral) {
    // La primera vez se conecta al dispositivo identificado y se crea una nueva luz Avea... 
    if(perifSel==null){
        console.log(timestamp()+"discovered "+peripheral.uuid);
        if((peripheral.uuid==uuidMyLamp)||(uuidMyLamp==null)){
            perifSel=peripheral;
            console.log(timestamp()+"uuid matches *****");
            //console.log("... (Init) Perif: " + );
            //perifSel.connect(function(error) {
                //console.log('... (Init) conectando el dispositivo: ' + perifSel.uuid);
                bulb = new avea.Avea(perifSel);
                bulb.connect();
                console.log(timestamp()+"bulb.connect was called...");
            //});
        }
        // De ahí en adelante tan solo se reconecta la luz y ya conecta el dispositivo al hacerlo
    } else {
        console.log(timestamp()+"discovered "+peripheral.uuid);
        if(peripheral.uuid==uuidMyLamp){
            console.log(timestamp()+"lost bulb appears again!")
        } else {
            console.log(timestamp()+"nothing important to me...");
            //noble.startScanning(serviceUUID, false);
        }
    }
});

Now, there is no

UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1):
Error: Peripheral already connected

error message any more.

I wonder how to discover the known uuidMyLamp faster. Would be nice if one could startScanning for the uuidMyLamp directly instead of the serviceUUID (I tried this, but this doesn't work with the uuidMyLamp).

Most discover-events are lost in the wrong accessory-file:

sudo node /home/pi/HAP-NodeJS/BridgedCore.js 
*** WARNING *** The program 'nodejs' uses the Apple Bonjour compatibility layer of Avahi.
*** WARNING *** Please fix your application to use the native API of Avahi!
*** WARNING *** For more information see <http://0pointer.de/avahi-compat?s=libdns_sd&e=nodejs>
*** WARNING *** The program 'nodejs' called 'DNSServiceRegister()' which is not supported (or only supported partially) in the Apple Bonjour compatibility layer of Avahi.
*** WARNING *** Please fix your application to use the native API of Avahi!
*** WARNING *** For more information see <http://0pointer.de/avahi-compat?s=libdns_sd&e=nodejs&f=DNSServiceRegister>
HAP-NodeJS starting...
Parsing accessory: dining_accessory.js
Parsing accessory: kitchen_accessory.js
Parsing accessory: stove_accessory.js
07:46:03|Esstischlampe(null)|null|null|null|noble: poweredOn
07:46:03|Küchenlampe(null)|null|null|null|noble: poweredOn
07:46:03|Herdlampe(null)|null|null|null|noble: poweredOn
07:46:03|Esstischlampe(null)|null|null|null|discovered 78a5048e670e
07:46:03|Küchenlampe(null)|null|null|null|discovered 78a5048e670e
07:46:03|Küchenlampe(78a5048e670e)|disconnected| X |null|uuid matches *****
07:46:03|Küchenlampe(78a5048e670e)|connecting| X |false|bulb.connect was called...
07:46:03|Herdlampe(null)|null|null|null|discovered 78a5048e670e
07:46:03|Esstischlampe(null)|null|null|null|discovered 7cec79d75f47
07:46:03|Esstischlampe(7cec79d75f47)|disconnected| X |null|uuid matches *****
07:46:03|Esstischlampe(7cec79d75f47)|connecting| X |false|bulb.connect was called...
07:46:03|Küchenlampe(78a5048e670e)|connecting| X |false|discovered 7cec79d75f47
07:46:03|Küchenlampe(78a5048e670e)|connecting| X |false|nothing important to me...
07:46:03|Herdlampe(null)|null|null|null|discovered 7cec79d75f47
07:46:03|Esstischlampe(7cec79d75f47)|connecting| X |false|discovered b4994c3ec392
07:46:03|Esstischlampe(7cec79d75f47)|connecting| X |false|nothing important to me...
07:46:03|Küchenlampe(78a5048e670e)|connecting| X |false|discovered b4994c3ec392
07:46:03|Küchenlampe(78a5048e670e)|connecting| X |false|nothing important to me...
07:46:03|Herdlampe(null)|null|null|null|discovered b4994c3ec392
07:46:03|Herdlampe(b4994c3ec392)|disconnected| X |null|uuid matches *****
07:46:03|Herdlampe(b4994c3ec392)|connecting| X |false|bulb.connect was called...
07:46:17|Herdlampe(b4994c3ec392)|connected|-75|true|get saturdation: 99
07:46:17|Herdlampe(b4994c3ec392)|connected|-75|true|get hue: 38
07:46:17|Küchenlampe(78a5048e670e)|connected|-71|true|get saturdation: 99
07:46:17|Küchenlampe(78a5048e670e)|connected|-71|true|get hue: 38
07:46:17|Esstischlampe(7cec79d75f47)|connected|-70|true|get saturdation: 99
07:46:17|Esstischlampe(7cec79d75f47)|connected|-70|true|get hue: 38
07:46:17|Esstischlampe(7cec79d75f47)|connected|-68|true|on
07:46:17|Herdlampe(b4994c3ec392)|connected|-69|true|on
07:46:17|Küchenlampe(78a5048e670e)|connected|-74|true|on
07:46:18|Esstischlampe(7cec79d75f47)|connected|-68|true|switch off
07:46:21|Esstischlampe(7cec79d75f47)|connected|-67|true|switch on
Alblahm commented 8 years ago

As you have seen I've added a fork of the main project, https://github.com/Alblahm/avea_node

I've put inside the sample file and I've changed the avea.js adding a line to comment the output of the winston package. In that way anyone can directly download our files to test them.

I've also started a wiki section inside to include the instructions to the users to integrate this into the Hap-node. I'll paste part of our comments there. https://github.com/Alblahm/avea_node/wiki

Of course feel free to edit or add anything you like.

thymjan commented 8 years ago

Hey, that's cool. I can edit the wiki or start a pull-request. But at the moment I can't upload/update files or start issues. Can you fix this?

Alblahm commented 8 years ago

I see for your log files that you always start the service by hand calling node. For that reason you have added the timestamp to the file, but you dont need to do that if you directly set the node as a service at startup, and also you can see the log files with the timestamp by default. So no need to create a function that does it.

The instructions to create this service are really simple but are very usefull, because every time the raspberry is restarted, the service is also restarted. Also if any error happens the service restarts automatically. You can download the config files from here: https://gist.github.com/johannrichard/0ad0de1feb6adb9eb61a/#file-homebridge

I paste here the full steps:

To add homebridge as a service at startup ...


paste the config files in the correct folders, you must place the files in:

cp /pathToDownloadedFiles/homebridge /etc/default cp /pathToDownloadedFiles/homebridge.service /etc/systemd/system

change the required access of the files ...

chmod 644 /etc/systemd/system/homebridge.service

It should be something like this ... root@osmc:/etc/default# ls -la -rw-r--r-- 1 root root 368 oct 2 21:59 homebridge

root@osmc:/etc/systemd/system# ls -la -rw-r--r-- 1 root root 312 oct homebridge.service

Inside the "homebridge.service", change the user to root User=root

you have to include the full path of the node EnvironmentFile=/etc/default/homebridge ExecStart=/usr/local/lib/node_modules/homebridge/bin/homebridge start $HOMEBRIDGE_OPTS

the first time run...

systemctl daemon-reload systemctl enable homebridge systemctl start homebridge

Everytime you want to check the service state use ...

systemctl status homebridge

To stop de service use ...

systemctl stop homebridge

To see the log output you can use this, and this log is timestamped !!! The second one only shows the log info for the service homebridge.

journalctl -f journalctl -f -u homebridge

To update the files, I usually edit the accessory files and then run this on the console :

systemctl stop homebridge && sleep 3 && systemctl start homebridge && journalctl -f -u homebridge

This line makes all the steps, stops the service, wait a second, and restart the service. This means that it reloads the node service with the updated accessories.

Alblahm commented 8 years ago

I've commited your file, and deleted the old one. So now it's ok the folder.

Alblahm commented 8 years ago

Yesterday I have a similar issue as you told in a previous comment. The homebridge was not able to reconnect and it dissapeared from the ios home app when you try to eliminate the node and add a new one. I've tried a lot of options to be sure of the problem, I recompiled the node addons, restarted the service, eliminated all the accesories, removed the temporary folders, and at the end I realized that the solution was as quite simple as change the username hex adress inside the Bridgecore.js and it works. It detects the bridge and you can once again add all the accessories connected to this Bridge.

But, to be sure, when it was working, I've tried to roll back, and use the old username, and it stoped working again, so that was clearly the reason. I dont know why, but I suppose that the ios home have some kind of cache that we cant clear.

So, if you have another time the connection problem try first this, and comment in the new issues section. //github.com/Marmelatze/avea_node/issues/5

I've created this new issue to avoid mixing all the info on this thread. (https://github.com/Marmelatze/avea_node/issues/5)

Alblahm commented 8 years ago

I've updated the code and solved the saturation problem, I've added a boolean var called bChangeSth to avoid the problem with the slide control to change the brightness. Using this var the settings are only updated one time while you slide the control up and down in the ios home app.

But now it also works fine if you ask siri to set only the brightness or hue, or saturation, all the functions call the sendToLight function. And now you can click on the color pallete of the ios app and while you change the color it inmediatly updates the bulb color. No need to divide the brightness, now the colors fit perfect with the pallete. Set first the brightness to some value in the middle, something like 70, then slide up and down, to see the change, and then go to the color palette and slide over the color to see the change. It works perfect. Luz_VerticalComedor_accessory.js.txt

thymjan commented 8 years ago

Hey, this are good news. Can't wait to test it!

Did you know, I didn't install homebridge? Just HAP-NodeJS and the accessory file and this works without homebridge?

So if I want to start homebridge as service, I have to install it first...

npm install -g --unsafe-perm homebridge
thymjan commented 8 years ago

How do you configure homebridge to work with the accessory-file?

I have started the service but nothing happens.

Think I have to edit ∼/.homebridge/config.json? Can you give me a hint?

thymjan commented 8 years ago

At the moment I feel like a complete idiot... This "homebridge as a service"-thing doesn't work for me.

If you say homebridge what do you mean?

Do you mean only HAP-NodeJS? https://github.com/KhaosT/HAP-NodeJS

Or do you mean this homebridge either: https://github.com/nfarina/homebridge

Do I have to install any plugins?

Where can I find information what to put in the file config.json?

pi@tablet:~ $ sudo journalctl -f -u homebridge
-- Logs begin at So 2016-11-06 21:59:09 CET. --
Nov 06 21:59:17 tablet homebridge[583]: *** WARNING *** For more information see <http://0pointer.de/avahi-compat?s=libdns_sd&e=nodejs&f=DNSServiceRegister>
Nov 06 21:59:29 tablet homebridge[583]: [2016-11-06 21:59:22] No plugins found. See the README for information on installing plugins.
Nov 06 21:59:29 tablet homebridge[583]: [2016-11-06 21:59:29] config.json (/var/homebridge/config.json) not found.
Nov 06 21:59:29 tablet homebridge[583]: Scan this code with your HomeKit App on your iOS device to pair with Homebridge:
Nov 06 21:59:29 tablet homebridge[583]:                        
Nov 06 21:59:29 tablet homebridge[583]:     ┌────────────┐     
Nov 06 21:59:29 tablet homebridge[583]:     │ 031-45-154 │     
Nov 06 21:59:29 tablet homebridge[583]:     └────────────┘     
Nov 06 21:59:29 tablet homebridge[583]:                        
Nov 06 21:59:29 tablet homebridge[583]: [2016-11-06 21:59:29] Homebridge is running on port 44026.
Nov 06 22:03:07 tablet systemd[1]: Stopping Node.js HomeKit Server...
Nov 06 22:03:07 tablet homebridge[583]: [2016-11-06 22:03:07] Got SIGTERM, shutting down Homebridge...
Nov 06 22:03:07 tablet systemd[1]: homebridge.service: main process exited, code=exited, status=143/n/a
Nov 06 22:03:07 tablet systemd[1]: Stopped Node.js HomeKit Server.
Nov 06 22:03:07 tablet systemd[1]: Unit homebridge.service entered failed state.
Nov 06 22:03:37 tablet systemd[1]: Stopped Node.js HomeKit Server.
Nov 06 22:03:47 tablet systemd[1]: Starting Node.js HomeKit Server...
Nov 06 22:03:47 tablet systemd[1]: Started Node.js HomeKit Server.
Nov 06 22:03:48 tablet homebridge[2042]: *** WARNING *** The program 'nodejs' uses the Apple Bonjour compatibility layer of Avahi.
Nov 06 22:03:48 tablet nodejs[2042]: *** WARNING *** The program 'nodejs' uses the Apple Bonjour compatibility layer of Avahi.
Nov 06 22:03:48 tablet nodejs[2042]: *** WARNING *** Please fix your application to use the native API of Avahi!
Nov 06 22:03:48 tablet nodejs[2042]: *** WARNING *** For more information see <http://0pointer.de/avahi-compat?s=libdns_sd&e=nodejs>
Nov 06 22:03:48 tablet nodejs[2042]: *** WARNING *** The program 'nodejs' called 'DNSServiceRegister()' which is not supported (or only supported partially) in the Apple Bonjour compatibility layer of Avahi.
Nov 06 22:03:48 tablet nodejs[2042]: *** WARNING *** Please fix your application to use the native API of Avahi!
Nov 06 22:03:48 tablet nodejs[2042]: *** WARNING *** For more information see <http://0pointer.de/avahi-compat?s=libdns_sd&e=nodejs&f=DNSServiceRegister>
Nov 06 22:03:48 tablet homebridge[2042]: *** WARNING *** Please fix your application to use the native API of Avahi!
Nov 06 22:03:48 tablet homebridge[2042]: *** WARNING *** For more information see <http://0pointer.de/avahi-compat?s=libdns_sd&e=nodejs>
Nov 06 22:03:48 tablet homebridge[2042]: *** WARNING *** The program 'nodejs' called 'DNSServiceRegister()' which is not supported (or only supported partially) in the Apple Bonjour compatibility layer of Avahi.
Nov 06 22:03:48 tablet homebridge[2042]: *** WARNING *** Please fix your application to use the native API of Avahi!
Nov 06 22:03:48 tablet homebridge[2042]: *** WARNING *** For more information see <http://0pointer.de/avahi-compat?s=libdns_sd&e=nodejs&f=DNSServiceRegister>
Nov 06 22:03:50 tablet homebridge[2042]: [2016-11-06 22:03:49] No plugins found. See the README for information on installing plugins.
Nov 06 22:03:50 tablet homebridge[2042]: [2016-11-06 22:03:50] config.json (/var/homebridge/config.json) not found.
Nov 06 22:03:50 tablet homebridge[2042]: Scan this code with your HomeKit App on your iOS device to pair with Homebridge:
Nov 06 22:03:50 tablet homebridge[2042]:                        
Nov 06 22:03:50 tablet homebridge[2042]:     ┌────────────┐     
Nov 06 22:03:50 tablet homebridge[2042]:     │ 031-45-154 │     
Nov 06 22:03:50 tablet homebridge[2042]:     └────────────┘     
Nov 06 22:03:50 tablet homebridge[2042]:                        
Nov 06 22:03:50 tablet homebridge[2042]: [2016-11-06 22:03:50] Homebridge is running on port 35066.

I'm I stupid? Did I install two implementations of homebridge?

Or how do nodejs and homebridge talk to each other?

Alblahm commented 8 years ago

Ok,ok... calm, step by step.

As I can see in your log, the service is running fine, but it restarts one time after other. If you use the option -n 100, you will see that this process is starting and stopping continuosly, this is probably because it does not find any accessory and then restarts.

Follow the intructions detailed in the link https://gist.github.com/johannrichard/0ad0de1feb6adb9eb61a/#file-homebridge

You don`t need any config.json. Only the hap-node, and if you put the accessory files inside the folder called accessories, it starts the service and read all the accessories included there.

This two files are exactly the ones that I have on my raspberry pi. The first one should be included in the /etc/systemd/system folder. And this one includes the line:

ExecStart=/usr/local/bin/node /home/osmc/HAP-NodeJS/BridgedCore.js

Download file, remove the .txt extension and paste in the correct folder. homebridge.service.txt

This line is equivalent to the proccess you did by hand when you start the app through the ssh remote conection to the raspi. Revise that this command fits your directories in your system. Probably you have installed the Hap-node in a different folder, so change this if that is the case.

The second file needed is the next one, remove the .txt extension and paste in the correct folder. homebridge.txt

This should be included in the /etc/default folder.

I've changed the user inside the first file, so it runs all as sudo. If you read the info on the link, they explain how to do in the formally correct way, creating a user called homebrigde, but my suggestion is faster, but perhaps less secure. Perfect for a first try, and then improve if everything works fine.

Take a lot of care with the file owner, revise that both files are owned by root,

Then simply run the systemctl daemon-reload systemctl enable homebridge systemctl start homebridge

and revise the log responses with the

journalctl -f

if you restart the raspi and revise the log you will see that it started automatically.

Here is the log output when I do this:

root@osmc:/home/osmc/HAP-NodeJS# systemctl stop homebridge && sleep 3 && systemctl start homebridge && journalctl -f -u homebridge

-- Logs begin at Sat 2016-11-05 14:23:16 CET. --
Nov 07 01:18:16 osmc systemd[1]: Stopping Node.js HomeKit Server...
Nov 07 01:18:16 osmc systemd[1]: Stopped Node.js HomeKit Server.
Nov 07 01:18:19 osmc systemd[1]: Starting Node.js HomeKit Server...
Nov 07 01:18:19 osmc systemd[1]: Started Node.js HomeKit Server.
Nov 07 01:18:20 osmc node[4084]: *** WARNING *** The program 'node' uses the Apple Bonjour compatibility layer of Avahi.
Nov 07 01:18:20 osmc node[4084]: *** WARNING *** The program 'node' uses the Apple Bonjour compatibility layer of Avahi.
Nov 07 01:18:20 osmc node[4084]: *** WARNING *** Please fix your application to use the native API of Avahi!
Nov 07 01:18:20 osmc node[4084]: *** WARNING *** For more information see <http://0pointer.de/avahi-compat?s=libdns_sd&e=node>
Nov 07 01:18:20 osmc node[4084]: *** WARNING *** The program 'node' called 'DNSServiceRegister()' which is not supported (or only supported partially) in the Apple Bonjour compatibility layer of Avahi.
Nov 07 01:18:20 osmc node[4084]: *** WARNING *** Please fix your application to use the native API of Avahi!
Nov 07 01:18:20 osmc node[4084]: *** WARNING *** For more information see <http://0pointer.de/avahi-compat?s=libdns_sd&e=node&f=DNSServiceRegister>
Nov 07 01:18:20 osmc node[4084]: *** WARNING *** Please fix your application to use the native API of Avahi!
Nov 07 01:18:20 osmc node[4084]: *** WARNING *** For more information see <http://0pointer.de/avahi-compat?s=libdns_sd&e=node>
Nov 07 01:18:20 osmc node[4084]: *** WARNING *** The program 'node' called 'DNSServiceRegister()' which is not supported (or only supported partially) in the Apple Bonjour compatibility layer of Avahi.
Nov 07 01:18:20 osmc node[4084]: *** WARNING *** Please fix your application to use the native API of Avahi!
Nov 07 01:18:20 osmc node[4084]: *** WARNING *** For more information see <http://0pointer.de/avahi-compat?s=libdns_sd&e=node&f=DNSServiceRegister>
Nov 07 01:18:21 osmc node[4084]: HAP-NodeJS starting...
Nov 07 01:18:23 osmc node[4084]: Parsing accessory: Fan_accessory.js
Nov 07 01:18:23 osmc node[4084]: Parsing accessory: GarageDoor_accessory.js
Nov 07 01:18:23 osmc node[4084]: Parsing accessory: Lock_accessory.js
Nov 07 01:18:23 osmc node[4084]: Parsing accessory: Luz_VerticalComedor_accessory.js
Nov 07 01:18:25 osmc node[4084]: ... (Init) Perif: connected / Luz: true
Alblahm commented 8 years ago

I think for your log, that you have to paste the accessory file inside the accessories folder of the hap-node, and pair the the bridge node with the ios app using the code that appears on your screen, and thats all.

Remember only three steps:

  1. paste homebridge.service in /etc/systemd/system
  2. paste homebridge in /etc/default
  3. paste dining_accessory.js in /home/osmc/Hap-Node/accessories

Try and let me know. I have to play some time with the file properties to get this thing work. But at the end it works perfect.

Hombridge is the name of the service, I have not installed the git repository you asked https://github.com/nfarina/homebridge

I suppose that you can also use this to configure all, but with the hap-node everything is really easy. Only edit files, stop the service, restart the service and the changes are ready. Or simply reboot the raspi.

systemctl stop homebridge && sleep 3 && systemctl start homebridge && journalctl -f -u homebridge

Or if you only want to see the service status:

root@osmc:/home/osmc/HAP-NodeJS# systemctl status homebridge

* homebridge.service - Node.js HomeKit Server
   Loaded: loaded (/etc/systemd/system/homebridge.service; enabled)
   Active: active (running) since Mon 2016-11-07 01:18:19 CET; 36min ago
 Main PID: 4084 (node)
   CGroup: /system.slice/homebridge.service
           `-4084 /usr/local/bin/node /home/osmc/HAP-NodeJS/BridgedCore.js
thymjan commented 8 years ago

Thanks for you kind help! I was confused, because every time you talked of homebridge I thought of the nfarina-homebridge. I'm working here on another project with the nfarina-homebridge and fhem.

I think its better to call this service hap-nodejs and not homebridge. You even don't need the file in /etc/default because only the path to config.json is set in there. And this config file isn't used with hap-nodejs.

I've written a small howto in your wiki: HowTo add HAP–NodeJS as a service at startup

Alblahm commented 8 years ago

Nice, it looks great. Simple instructions.

I agree with all the suggestions, probably the name of the service was a bit confusing.

I think that we can add more sample accessories inside the repository for other devices. I've done some work with the samsung tv that is directly connected to the raspberry pi with the osmc.

I'm able to play music directly telling siri to do it , and also to listen radio through a radio plugin inside the osmc.

Alblahm commented 8 years ago

If you update your accessory file, please clean all the timestamp info, it only adds noise and delays to the accessory file. Now with the service option, as you have seen it is not needed. The timestamps appear on each line automatically.

Luz_VerticalComedor_accessory.js.txt

Have you tested the last changes of my light accessory file? I mean sliding the controls that change the brightness in the ios app, or move through the color palette to see inmediatly the color change on the light bulb?. And also ask siri to change only one thing, like brightness or saturation. If you do so, please like the other times insert a log text file (better use a file link with the log inside instead of pasting the full log inside the comment).

If you do, please use the accessory file first without any change, with only one light bulb. In that way we can check whether it works fine in your home setup. So if anyone download it works without any change.

Do you have any idea if there is another bt device that we can also include here. I mean, for the phillips hue lamps, is it neccesary to have the hub ?, or is it possible to do the same as with the avea light ?, and connect directly to the hap node avoiding to buy the phillips hue bridge.

pattyland commented 8 years ago

Hey, are there any plan to submit this to https://www.npmjs.com/search?q=homebridge-plugin ? Would be great for a quick & easy install!

thymjan commented 8 years ago

It's a bit confusing, but this is not for homebridge it's for HAP-NodeJS. It does the same thing as homebridge but the architecture is different. With HAP-NodeJS you only have to place your accessory-file in the accessory directory. You don't have to install plugins.

Here is information to get this thing running: https://github.com/Alblahm/avea_node/wiki

Alblahm commented 8 years ago

It is possible to convert this project into a git repository with all the info inside, valid for homebridge. The main difference is that you have to add the accessory to the config.json, and translate part of the code to a index.js. But it can be done. The main advantage is that after converted, you can use npm install to add the accessory, and this is really simple to install. I think that, Firstly we must improve the lib, and it should be perfect if more users test it, and write here the issues if they find any problem.

Alblahm commented 8 years ago

Please, thyman, move the "new_dinning_accessory.js" from the main folder to the sample accessories folder. I can't do it because I'm not the owner. Move it to the sample accessories folder and delete the original, if you have any new version upload it with the last changes. I've added a comment indicating that your version is the multi-light version. https://github.com/Alblahm/avea_node/tree/master/accessories

thymjan commented 8 years ago

I can't delete the file directly. I've pulled a request to delete the file and another to create a new file in the accessories folder. I've did several changes:

  1. removed the time stamp. I've still included intensive logging because it is not easy to find a problem if there is more than one bulb.
  2. I've manipulated the way brightness changes are send to the bulb to get more intensive colors
  3. I've changed the way the uuid is created

It is still sometimes tricky to get all (three) bulbs connected, but when they are it is a nearly stable situation (for almost a week now). If you switch off the bulbs they can be found again after switching them on again.

Alblahm commented 8 years ago

Ok, I've retried, and now I've been able to delete the file in the main folder. Paste the link to the latest version here, and i will replace it inside the accessories folder.

pattyland commented 8 years ago

@thymjan Thanks for the info. I saw the discussion with HAP-NodeJS, but as Homebridge is based on HAP-NodeJS and is also including it's packages when you install it, I thought you simply use it. What should I edit to config.json from Homebridge to activate the accessory?

thymjan commented 8 years ago

You are stepping in the same trap than me. You don't need a config.json with HAP-NodeJS. You just put your accessory file inside the accessory folder. That's it. Look here: https://github.com/Alblahm/avea_node/wiki/Basic-Installation

thymjan commented 8 years ago

@Alblahm : I tried to get this running on a raspberry pi zero. Everything installs fine. But I've got a bunch of errors with the srp-lib srp-errors.txt npm-debug.log.txt Do you have any ideas why this happens?

Edit: Found a solution. I had to update my version of npm

sudo npm install npm@latest -g

Added this to the wiki. Now I have a little raspberry pi zero avea bridge! It works!

pattyland commented 8 years ago

I know! I put Luz_Comedor_accessory.js into /usr/lib/node_modules/homebridge/node_modules/hap-nodejs/accessories and started it via BridgedCore.js. As I'm already running homebridge and have several devices connected I thought it would be better to have one fake HomeKit Service than two (although it seems to work when I configure different ports and MAC addresses for each service)

Unfortunately running it with hap-nodejs is not working either, I'm getting the message ... La luz aun no está disponible o está desconectada!! (made a pull request to translate this message to english). sudo hcitool lescan does not display my avea but 3 unknown devices and my Pebble. I'm using a C.H.I.P. as a server, the docs say it supports Bluetooth 4.0 LE: http://docs.getchip.com/chip.html#wireless Could this be an problem? Do I need Bluetooth 4.1 aka Smart?

thymjan commented 8 years ago

I think it's essential to see your avea bulb with sudo hcitool lescan! Try to (hard) switch your bulb off and on. Be sure your mobile phone is not connected to it (switch bluetooth off), close the avea app. Try to put your bulb little bit nearer to your raspberry bluetooth device.

pattyland commented 8 years ago

Ah sorry, forgot that the MAC address is the mirrored serial number. So `sudo hcitool lescan" displays the MAC address bulb but as "unknown" not as Avea_XXXX as in your logs

thymjan commented 8 years ago

Did you try this accessory file: https://github.com/Alblahm/avea_node/blob/master/accessories/dining_bulb_accessory There is a little bit more logging. Maybe you can show it to me. Just fill in your ids at the top of the file.

pattyland commented 8 years ago
HAP-NodeJS starting...
Parsing accessory: dining_bulb_accessory.js
Esstischlampe(null)|null|null|null|noble: poweredOn
Esstischlampe(null)|null|null|null|scanStart received
Esstischlampe(null)|null|null|null|Device not Ready
Esstischlampe(null)|null|null|null|Device not Ready
Esstischlampe(null)|null|null|null|Device not Ready
Esstischlampe(null)|null|null|null|Device not Ready
Esstischlampe(null)|null|null|null|Device not Ready

:(

thymjan commented 8 years ago

Should look like this:

Nov 17 23:31:07 tablet node[20489]: *** WARNING *** The program 'nodejs' uses the Apple Bonjour compatibility layer of Avahi.
Nov 17 23:31:07 tablet nodejs[20489]: *** WARNING *** The program 'nodejs' uses the Apple Bonjour compatibility layer of Avahi.
Nov 17 23:31:07 tablet nodejs[20489]: *** WARNING *** Please fix your application to use the native API of Avahi!
Nov 17 23:31:07 tablet nodejs[20489]: *** WARNING *** For more information see <http://0pointer.de/avahi-compat?s=libdns_sd&e=nodejs>
Nov 17 23:31:07 tablet nodejs[20489]: *** WARNING *** The program 'nodejs' called 'DNSServiceRegister()' which is not supported (or only supported partially) in the Apple Bonjour compatibility layer of Avahi.
Nov 17 23:31:07 tablet nodejs[20489]: *** WARNING *** Please fix your application to use the native API of Avahi!
Nov 17 23:31:07 tablet nodejs[20489]: *** WARNING *** For more information see <http://0pointer.de/avahi-compat?s=libdns_sd&e=nodejs&f=DNSServiceRegister>
Nov 17 23:31:07 tablet node[20489]: *** WARNING *** Please fix your application to use the native API of Avahi!
Nov 17 23:31:07 tablet node[20489]: *** WARNING *** For more information see <http://0pointer.de/avahi-compat?s=libdns_sd&e=nodejs>
Nov 17 23:31:07 tablet node[20489]: *** WARNING *** The program 'nodejs' called 'DNSServiceRegister()' which is not supported (or only supported partially) in the Apple Bonjour compatibility layer of Avahi.
Nov 17 23:31:07 tablet node[20489]: *** WARNING *** Please fix your application to use the native API of Avahi!
Nov 17 23:31:07 tablet node[20489]: *** WARNING *** For more information see <http://0pointer.de/avahi-compat?s=libdns_sd&e=nodejs&f=DNSServiceRegister>
Nov 17 23:31:08 tablet node[20489]: HAP-NodeJS starting...
Nov 17 23:31:08 tablet node[20489]: Parsing accessory: dining_accessory.js
Nov 17 23:31:09 tablet node[20489]: Parsing accessory: kitchen_accessory.js
Nov 17 23:31:09 tablet node[20489]: Parsing accessory: stove_accessory.js
Nov 17 23:31:09 tablet node[20489]: noble warning: unknown handle 70 disconnected!
Nov 17 23:31:09 tablet node[20489]: Esstischlampe(null)|null|null|null|noble: poweredOn
Nov 17 23:31:09 tablet node[20489]: Küchenlampe(null)|null|null|null|noble: poweredOn
Nov 17 23:31:09 tablet node[20489]: Herdlampe(null)|null|null|null|noble: poweredOn
Nov 17 23:31:09 tablet node[20489]: Esstischlampe(null)|null|null|null|scanStart received
Nov 17 23:31:09 tablet node[20489]: Küchenlampe(null)|null|null|null|scanStart received
Nov 17 23:31:09 tablet node[20489]: Herdlampe(null)|null|null|null|scanStart received
Nov 17 23:31:09 tablet node[20489]: Esstischlampe(null)|null|null|null|discovered 78a5048e670e
Nov 17 23:31:09 tablet node[20489]: Küchenlampe(null)|null|null|null|discovered 78a5048e670e
Nov 17 23:31:09 tablet node[20489]: Küchenlampe(78a5048e670e)|disconnected| X |null|uuid matches *****
Nov 17 23:31:09 tablet node[20489]: Küchenlampe(78a5048e670e)|connecting| X |false|bulb.connect was called...
Nov 17 23:31:09 tablet node[20489]: Herdlampe(null)|null|null|null|discovered 78a5048e670e
Nov 17 23:31:09 tablet node[20489]: Esstischlampe(null)|null|null|null|discovered 7cec79d75f47
Nov 17 23:31:09 tablet node[20489]: Esstischlampe(7cec79d75f47)|disconnected| X |null|uuid matches *****
Nov 17 23:31:09 tablet node[20489]: Esstischlampe(7cec79d75f47)|connecting| X |false|bulb.connect was called...
Nov 17 23:31:09 tablet node[20489]: Küchenlampe(78a5048e670e)|connecting| X |false|discovered 7cec79d75f47
Nov 17 23:31:09 tablet node[20489]: Küchenlampe(78a5048e670e)|connecting| X |false|nothing important to me...
Nov 17 23:31:09 tablet node[20489]: Herdlampe(null)|null|null|null|discovered 7cec79d75f47
Nov 17 23:31:10 tablet node[20489]: Esstischlampe(7cec79d75f47)|connecting| X |false|discovered b4994c3ec392
Nov 17 23:31:10 tablet node[20489]: Esstischlampe(7cec79d75f47)|connecting| X |false|nothing important to me...
Nov 17 23:31:10 tablet node[20489]: Küchenlampe(78a5048e670e)|connecting| X |false|discovered b4994c3ec392
Nov 17 23:31:10 tablet node[20489]: Küchenlampe(78a5048e670e)|connecting| X |false|nothing important to me...
Nov 17 23:31:10 tablet node[20489]: Herdlampe(null)|null|null|null|discovered b4994c3ec392
Nov 17 23:31:10 tablet node[20489]: Herdlampe(b4994c3ec392)|disconnected| X |null|uuid matches *****
Nov 17 23:31:10 tablet node[20489]: Herdlampe(b4994c3ec392)|connecting| X |false|bulb.connect was called...
Nov 17 23:31:10 tablet node[20489]: Esstischlampe(7cec79d75f47)|connecting| X |false|scanStop received
Nov 17 23:31:10 tablet node[20489]: Esstischlampe(7cec79d75f47)|connecting| X |false|startScanning again (bulb not connected)......
Nov 17 23:31:10 tablet node[20489]: Küchenlampe(78a5048e670e)|connected|-71|true|scanStop received
Nov 17 23:31:10 tablet node[20489]: Herdlampe(b4994c3ec392)|connecting| X |false|scanStop received
Nov 17 23:31:10 tablet node[20489]: Herdlampe(b4994c3ec392)|connecting| X |false|startScanning again (bulb not connected)......
Nov 17 23:31:10 tablet node[20489]: Esstischlampe(7cec79d75f47)|connecting| X |false|scanStart received
Nov 17 23:31:10 tablet node[20489]: Küchenlampe(78a5048e670e)|connected|-71|true|scanStart received
Nov 17 23:31:10 tablet node[20489]: Herdlampe(b4994c3ec392)|connecting| X |false|scanStart received
Nov 17 23:31:10 tablet node[20489]: Esstischlampe(7cec79d75f47)|connected|-74|true|scanStop received
Nov 17 23:31:10 tablet node[20489]: Küchenlampe(78a5048e670e)|connected|-72|true|scanStop received
Nov 17 23:31:10 tablet node[20489]: Herdlampe(b4994c3ec392)|connecting| X |false|scanStop received
Nov 17 23:31:10 tablet node[20489]: Herdlampe(b4994c3ec392)|connecting| X |false|startScanning again (bulb not connected)......
Nov 17 23:31:10 tablet node[20489]: Esstischlampe(7cec79d75f47)|connected|-74|true|scanStart received
Nov 17 23:31:10 tablet node[20489]: Küchenlampe(78a5048e670e)|connected|-72|true|scanStart received
Nov 17 23:31:10 tablet node[20489]: Herdlampe(b4994c3ec392)|connecting| X |false|scanStart received
Nov 17 23:31:10 tablet node[20489]: Esstischlampe(7cec79d75f47)|connected|-75|true|discovered b4994c3ec392
Nov 17 23:31:10 tablet node[20489]: Esstischlampe(7cec79d75f47)|connected|-75|true|nothing important to me...
Nov 17 23:31:10 tablet node[20489]: Küchenlampe(78a5048e670e)|connected|-72|true|discovered b4994c3ec392
Nov 17 23:31:10 tablet node[20489]: Küchenlampe(78a5048e670e)|connected|-72|true|nothing important to me...
Nov 17 23:31:10 tablet node[20489]: Herdlampe(b4994c3ec392)|connecting| X |false|discovered b4994c3ec392
Nov 17 23:31:10 tablet node[20489]: Herdlampe(b4994c3ec392)|connecting| X |false|lost bulb appears again!
Nov 17 23:31:11 tablet node[20489]: Esstischlampe(7cec79d75f47)|connected|-74|true|scanStop received
Nov 17 23:31:11 tablet node[20489]: Küchenlampe(78a5048e670e)|connected|-73|true|scanStop received
Nov 17 23:31:11 tablet node[20489]: Herdlampe(b4994c3ec392)|connected|-79|true|scanStop received

Did you try to hard switch the bulb off an on?

pattyland commented 8 years ago

When I run example.js from this repository while running hap-nodejs it detect my bulb and I can manage the it with the Home app and Siri. Very strange... Maybe some bluetooth device still is still interfering with it?

thymjan commented 8 years ago

So it's working? Which example.js do you mean and which repository?

pattyland commented 8 years ago

Yes! Not very reliable, but this would be boring ;)

This file, part of the avea lib for nodejs: https://github.com/Marmelatze/avea_node/blob/master/example.js

Alblahm commented 8 years ago

The light should appear in the list when you run the hcitool lescan, if it does not appear, do not start the service. Also try to stop both servers, I mean stop homebridge and hap-node.

Then check with the command line tool whether the bulb is reachable, with lescan. If it is there, then start only the hap-node service. If not, try to do a hciconfig hci0 down, and then hciconfig hci0 up. Sometimes you have to insist to get it run.

Check if it works within the ios home app and with siri. And then if everything works start also the homebridge service with the other devices.

I'll make an english version for the one light accessory.

pattyland commented 8 years ago

The bulb appears nearly (4/5) everytime when I use the hcitool.

Here is my last log:

*** WARNING *** The program 'nodejs' uses the Apple Bonjour compatibility layer of Avahi.
*** WARNING *** Please fix your application to use the native API of Avahi!
*** WARNING *** For more information see <http://0pointer.de/avahi-compat?s=libdns_sd&e=nodejs>
*** WARNING *** The program 'nodejs' called 'DNSServiceRegister()' which is not supported (or only supported partially) in the Apple Bonjour compatibility layer of Avahi.
*** WARNING *** Please fix your application to use the native API of Avahi!
*** WARNING *** For more information see <http://0pointer.de/avahi-compat?s=libdns_sd&e=nodejs&f=DNSServiceRegister>
HAP-NodeJS starting...
Parsing accessory: Sample_1Avea_EN_accessory.js
Node Bridge identify
... The light is not yet reachable or it is not connected!!
... The light is not yet reachable or it is not connected!!
... The light is not yet reachable or it is not connected!!
... The light is not yet reachable or it is not connected!!
info: new bulb found bulb=78a5047b1acb
info: connecting bulb=78a5047b1acb
info: connected bulb=78a5047b1acb

After the last "The light is not yet reachable or it is not connected!!" I started the example.js from this repository... After starting the bulb get found by hap-node and is working with Siri. But I have to "kickstart" (?) it... Very strange. Maybe there are bluetooth devices that still try connect with the Avea... Gonna go through my Android devices ;)

Maybe we should start a "Avea NodeJS/Avea HomeKit" forum/wiki? This thread is huge!

Alblahm commented 8 years ago

Yes, please move this to issue 5, https://github.com/Marmelatze/avea_node/issues/5 , or create a new issue.

But please show the output of the hcitool scan, hcitool lescan, and hcitool con.

And then let us see exactly how do you start the service. I mean, show all the commands you use to start and stop the service. Remember that you must use sudo to start the service.