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

thymjan commented 8 years ago

Hey, this are great news! Can you give a more detailed description howto get this thing work?

thymjan commented 8 years ago

I've installed homebridge. I've placed Luz_VerticalComedor_accessory.js in /home/pi/.homebridge/accessories/ Now I wonder where to place the avea_node libs. Do I have to make changes to .homebridge/json.config?

Alblahm commented 8 years ago

Yes, you are right, you have to install homebridge, and then paste the avea_node lib inside the node_modules folder. You can do this with the git command in one step.

root@osmc:/.../node_modules/# git clone https://github.com/Marmelatze/avea_node.git cd .. root@osmc:/home/osmc/Hap-NodeJS/# npm rebuild all

If you have errors during compilation the solution is always the same. First check the error message and then add the module that generates the error. For sure this is going to launch one error asking for the winston package and another one for the promise-queue. To solve this do:

cd /home/osmc/Hap-NodeJS/node_modules root@osmc:/.../node_modules/npm install winston root@osmc:/.../node_modules/npm install promise-queue

Please, if everything works fine, take one minute more to place a comment here saying whether it worked or not. And include the version of kodi/osmc you have used. In my case I've installed Hap-Node following the instructions from this web page (I've corrected some missed details): https://gist.github.com/elvisimprsntr/f23c76587d48be0ec4b9

First connect remotely with PuTTY to the raspberry pi2b and then follow exactly this steps:

sudo su cd /home/osmc apt-get update && apt-get upgrade -y apt-get remove nodejs-legacy apt-get install git-core libnss-mdns libavahi-compat-libdnssd-dev -y

Download the most updated version of the "node" package

wget http://node-arm.herokuapp.com/node_latest_armhf.deb dpkg -i node_latest_armhf.deb

Check the versions of the packages installed on your raspberry ...

node -v && npm -v v4.2.1 2.14.7

Add all the neccesary packages...

npm install -g node-gyp git clone https://github.com/KhaosT/HAP-NodeJS.git cd HAP-NodeJS/ npm install node-persist && npm install srp && npm install mdns npm install debug && npm install curve25519-n && npm install ip npm install ed25519 && npm install request && npm install noble npm install onecolor npm rebuild

Start the service as super user (it's neccessary to access the bluetooth hardware) and check that everything was correctly installed.

sudo node BridgedCore.js

To see the logs you can type

journalclt -f

This allows you to see the software output while you speak with siri. You can also create a service that starts this process automatically on every raspberry pi restart. There are a lot of documentation explaining how to do it.

thymjan commented 8 years ago

So you are talking about the HAP-NodeJS "homekit accessory server" not homebrige https://github.com/nfarina/homebridge/blob/master/README.md? This is something slightly different, is it? I didn't get this point before.

By the way, I try to get this running on a raspberry pi 2 with actual raspbian jessie.

Alblahm commented 8 years ago

Yes, this implementation of homebridge (https://github.com/KhaosT/HAP-NodeJS.git) simplifies a lot the way of adding plugins, you only have to paste the new one inside the accessories folder, restart the service and thats all.

Only one new file for each new device and you will see it inmmediatly on your ios home app. And as soon as it appears in the ios home app, Siri recognizes the voice commands that includes the name of the device inside the sentence you say.

For instance, if you paste a new thermometer accessory in the accessories folder and restart the service, you will inmediatly see it in the ios device and you can ask siri for the room temperature.

In the case of the avea_light, as soon as you paste the js file which I included in the first comment, you can ask Siri to turn on/off the light, set it's brigtness to a 50 or set it's color to green.

To improve the speech detection is better if you change the name of the lamp to something easy (like ceil lamp) and place it inside a room (yo can do this in the ios home app, by entering inside the properties of your device and changing the default room to bedroom). In that way you can say something like hey siri turn on the bedroom ceil lamp.

I've corrected some issues and I'm now working with the color stuff, to put in correspondence the ios home app color pallete with the answer of the light bulb when you change the color inside the ios home app.

thymjan commented 8 years ago

I've troubles to install HAP-NodeJS. Something went wrong in this lines:

npm install node-persist && npm install srp && npm install mdns && npm install debug npm npm install curve25519 && npm install ip && install ed25519 && npm install request npm rebuild

So I tried this:

npm install node-persist && npm install srp && npm install mdns && npm install debug
npm install curve25519-n && npm install ip && npm install ed25519 && npm install request 
npm rebuild

Additionally I had to install: npm install noble npm install onecolor

I had to search for the pincode and found it in BridgedCore.js... and... sudo node BridgedCore.js (without sudo I had no access for bluetooth) Success... Hey Siri turn on the lights! You are doing great work!

Played with the colors and the brightness in the home app. Colors are changing after switching on and off the light (color differs from preselected color anyway). But brightness doesn't change at the moment.

Here is a short episode of playing with the avea bulb:

AveaLog.txt

Alblahm commented 8 years ago

Ok, there were some bugs in the previous installation comment, I've corrected it. so now the instructions should work fine. If anyone more install it, please send the log.

The pincode is for the BridgeNode, not for the accesory, The Home app only ask you for this code the first time you create a new house, and as I suppose you have found it is "031-45-154". You can paste new lamps or whatever inside the accesories folder, restart the service, and they just appear inmediatly in the ios Home app.

I've also added your corrections to the initial instructions. Thanks !!!

New Update of the avea light accessory file !!, Solved the brightness problem . Now you can change the brightness value and it changes inmediatly the value while you change the slider control. You can also ask siri to change the brigness value, saying something like: Hey siri set the vertical lamp brightness to 50 percent.

You can also change the colors in the ios app. But you are only going to see a good correspondence if the value of the brightness is lower than 20. With bigger values the light is almost always white. It's not yet in accurate corresponcence with the lamp colors (I'm still working on that).

Remember to replace the file extension to "js" instead of "js.txt" before copying it into the accessories folder. And if it works, please place a comment below with the raspberry pi model and the kodi version you have used.

thymjan commented 8 years ago

Very, very cool! This seems to become the first seemless homekit integration of the none homekit capable avea bulbs. I'm excited!

Brightness and color change is working now here (Home app). There must be sort of color and non-linear brightness management to get this intuitive color change feeling?

I'm on the way, but will paste my actual logging this afternoon.

Thanks for your work!

thymjan commented 8 years ago

I wonder what to do if there is more than one bulb: Do I have to add an accessory file for each bulb? At the moment it seems that the first answering bulb is taken an the others are not recognized (I've installed three of them).

Bulb x47 is recognized here: Episode_1.txt

Something went wrong here: Episode_2.txt

Bulb x92 is recognized here: Episode_3.txt

Bulb x0e is recognized here: Episode_0.txt

Alblahm commented 8 years ago

Ok, the logs are really usefull. The Episode2 is a bug that remain from a previous version, I'll correct it. I only have one avea light, so I cant try the others, but I think that you can connect using the id of the lamp. Make first some tests with the hciconfig and hcitool lescan, from the console to see if all the lamps appear in the system. In that case with the ids the instructions will be send only to the one with the selected id. I'll check it. Thanks.

thymjan commented 8 years ago

I'm a bit confused... Here are my investigations:

Confused.txt

After starting HAP hcitool con often shows all three bulbs. With hcitool scan no avea bulb is found, only mobile phones etc.

hciconfig shows:

hci0: Type: BR/EDR  Bus: USB
BD Address: 00:15:83:D2:14:7F  ACL MTU: 310:10  SCO MTU: 64:8
UP RUNNING PSCAN 
RX bytes:3234 acl:3 sco:0 events:227 errors:0
TX bytes:2394 acl:3 sco:0 commands:159 errors:0
Alblahm commented 8 years ago

Yes, because you have to use hcitool lescan, remember that the lamp is low energy bluetooth!! So you have to use the low energy scan!! The info you included in the coment is the hciconfig answer, and it means that the bt is ok and ready. Go on and comment the progress...

thymjan commented 8 years ago

hcitool doesn't offer me an option "lescan" here. It also is not mentioned in the man page.

OK. It's mentioned when calling hcitool -h

thymjan commented 8 years ago

Think I have to use sudo:

pi@tablet:~/HAP-NodeJS/accessories $ sudo hcitool lescan
Set scan parameters failed: Input/output error
Alblahm commented 8 years ago

hcitool --help My hcitool is ver 5.39 installed in the raspberry pi with the os Linux osmc 4.4.16-6-osmc

thymjan commented 8 years ago

pi@tablet:~/HAP-NodeJS/accessories $ hcitool -h hcitool - HCI Tool ver 5.23

pi@tablet:~/HAP-NodeJS/accessories $ uname -a Linux tablet 4.4.23-v7+ #913 SMP Tue Oct 4 14:16:19 BST 2016 armv7l GNU/Linux

thymjan commented 8 years ago

okokokokok... HAP-NodeJS must not run!

now it works:pi@tablet:~ $ sudo hcitool lescan
LE Scan ...
B4:99:4C:3E:C3:92 (unknown)
B4:99:4C:3E:C3:92 Avea_92C3
7C:EC:79:D7:5F:47 (unknown)
7C:EC:79:D7:5F:47 Avea_475F
B4:99:4C:3E:C3:92 (unknown)
B4:99:4C:3E:C3:92 Avea_92C3
7C:EC:79:D7:5F:47 (unknown)
7C:EC:79:D7:5F:47 Avea_475F
B4:99:4C:3E:C3:92 (unknown)
B4:99:4C:3E:C3:92 Avea_92C3
7C:EC:79:D7:5F:47 (unknown)
7C:EC:79:D7:5F:47 Avea_475F
B4:99:4C:3E:C3:92 (unknown)

and so on...

Alblahm commented 8 years ago

👍 try to change only the code inside the noble.discover function. I think that there you can fix one code for each lamp by cheking the perif.uuid And create three accessories almost identicall except for the uuid code and the accessory uuid. Take care, because the uuid that the lamp returns through the avea lib is not the same as the hcitool. So use the avea code to compare. The code appears in the logs as... Info: new bulb found bulb=7cec...

thymjan commented 8 years ago

Modified noble.discover function below. Now I wonder if there is a special discover function not to get any peripheral but the one with the perif.uuid (https://www.npmjs.com/package/noble) But I'm confused with the uuids. Are uuids identical to the bluetooth address? I don't recognize perifSel.uuid here: https://www.npmjs.com/package/noble#peripheral-discovered What would you do? (I'm a newbie to js...)

// More information about noble: https://www.npmjs.com/package/noble
noble.on("discover", function(peripheral) {

  // La primera vez se conecta al dispositivo identificado y se crea una nueva luz Avea... 
  if(perifSel==null){
     perifSel=peripheral;
     //console.log("... (Init) Perif: " + perifSel.state);
     perifSel.connect(function(error) {
       console.log('... (Init) connecting new device: ' + perifSel.uuid);
       if (perifSel.uuid=="7cec79d75f47") {
           console.log('... found dining table lamp!');
       } else if (perifSel.uuid=="b4994c3ec392") {
           console.log('... found kitchen lamp alpha!');
       } else if (perifSel.uuid=="78a5048e670e") {
           console.log('... found kitchen lamp beta!');
       } else {
           console.log('... found unknown Avea bulb!');
       }
       bulb = new avea.Avea(perifSel);
       bulb.connect();
       //var BrilloL= bulb.getBrightness();

       //console.log("... (Init) Perif: " + perifSel.state + " / Luz: " + bulb.connected);
     });
  // De ahí en adelante tan solo se reconecta la luz y ya conecta el dispositivo al hacerlo
  }else{
      console.log("... (InitB) " + perifSel.state + " bulb " + perifSel.uuid);
  }

});
Alblahm commented 8 years ago

I think that this is not a good idea, because then you dont have one device per accessory file in the ios home app. I'll send a different solution, and you can test with your lamps. I cant do it now, but i'll upload as soon as i can.

thymjan commented 8 years ago

The changes where just to get a glue how it works. I still have your instructions "one accessory file per bulb" in mind. Thanks for your help!

thymjan commented 8 years ago

Got it! Now I can control three avea bulbs independently!

Here's the example accessory file: Elgato_Avea_Bulb_accessory.js.txt

Alblahm commented 8 years ago

Nice, that was more or less what i suggested, but I think that it would be perfect if you replace this:

if ((peripheral.uuid == aveaBTAddress)){

with this:

if ((peripheral.uuid == aveaBTAddress)||(aveaBTAddress == null)){

In that case you can set the default value of the aveaBTAddress to null. And only the people that want to use more than one bulb have to edit the accessory file and include the uuid of each lamp. In the other cases, for users with only one lamp, it will work without any change, so they only have to download and it works at the first place without understanding anything about the structure of this files.

Do you agree with me ???

I'm also changing the Characteristic.On get option to recover the actual state of the lamp at the begging, because with our versions, if the lamp is on when you start the service it always says it is off. This is because the first time you start the service it do not ask the lamp for the actual state. This version only controls but never checks.

The file below is your version with minor changes to allow one lamp users to use also your code.

thymjan commented 8 years ago

Hi there, tested your file. This is working for several bulbs, too. Should be as easy as possible to get this working, you're right. Made several changes for logging. bulbName and aveaBulb should be the same, should it? Elgato_Avea_Bulb_accessory.js.txt

Alblahm commented 8 years ago

There were another important error in the code, if the lights are not conected to the power source or simply not present, the accesory service launches an error that makes the node service break down. I've corrected it to avoid this in the version below. You can try with one lamp, if you power off the lamp and restart the node service, you will see that all the other devices you have on your ios app continue working fine. That is important because with the previous versions we have to maintain all the devices powered to avoid a break down of the service. If anyone tries it, please upload a log file while you restart the service, both connected to the power source and also disconnected.

thymjan commented 8 years ago

Good evening. Did some homework and merged our files: dining_accessory.js.txt

Unfortunately I've got some trouble with the new changes when a bulb is not available:

/home/pi/HAP-NodeJS/accessories/sleeping_accessory.js:142
            callback(err, false);
                     ^

ReferenceError: err is not defined
    at .<anonymous> (/home/pi/HAP-NodeJS/accessories/sleeping_accessory.js:142:13)
    at emitMany (events.js:127:13)
    at emit (events.js:201:7)
    at Characteristic.setValue (/home/pi/HAP-NodeJS/lib/Characteristic.js:155:10)
    at Bridge.<anonymous> (/home/pi/HAP-NodeJS/lib/Accessory.js:727:22)
    at Array.forEach (native)
    at Bridge.Accessory._handleSetCharacteristics (/home/pi/HAP-NodeJS/lib/Accessory.js:672:8)
    at emitMany (events.js:127:13)
    at HAPServer.emit (events.js:201:7)
    at HAPServer._handleCharacteristics (/home/pi/HAP-NodeJS/lib/HAPServer.js:966:10)

Here is the whole episode log: err.txt

Alblahm commented 8 years ago

Ok, I've seen the code and there was a copy-paste error, it was inside a set function, so the callback has no parameters !!! Thats the reason of your error in the previous comment... Correct -> callback(err, false); and replace with callback();

I've corrected this in all other functions, now it works perfect with the light unplugged, in that situation the ios app shows a quotation mark over the accessory. And as soon as you plug the light, the bulb is detected, as you can see in the log and you can interact from the ios app by clicking on the icon to update the situation of the light. Now it correctly reads the start-up situation of the lamp, I had to change the get function to read the colors and check that all of them are equal to 0 (in that case the lamp is off). I've also created a new function (sendToLight) to send the colors to the light and clean more the code. All the stuff is corrected in this file: I think now the colors fit more or less the colormap shown on the ios device for low level brighness values.

I've another doubt with your code, you have added another startscanning inside the discover funtion, i think that this is a posible problem than can generate an infinite loop. Try directly my code with three accessories, and tell me if it finds the bulbs. I have intentionally omitted this re-scan code to see if it works anyway.

Alblahm commented 8 years ago

I`ve detected some new voice commands that siri also accept with this lamp and they work fine with our accessory file:

hey siri change the brightness of the living room lamp to 80 change the color of the living room lamp to light red decrease a bit the brightness of the living room lamp

It accepts different colors, and as soon as you do you can see the effect on the lamp !!! There was another error in the conversion. The color space should be hsv, hot hsl. Now the colors perfectly fit the voice orders.

thymjan commented 8 years ago

I have several problems: Not all bulbs are found, even "sudo hcitool lescan" shows everything. I wonder if the event 'avea bulb found' is put in the waste if the bluetooth address is mismatching. If this would be right, every avea accessory file wastes important messages.

Is it a rule to have one accessory file for each device? Or could this be a group of equal devices? Maybe its better to have an array of a device type with one accessory file?

If I switch of the hardware of a bulb, the home app doesn't recognize anything. If I switch it on again, the logfile shows many messages which may be delayed in some buffer.

If I change the color with siri (german version). The bulb shows white light and than gets dark. German siri only recognizes some colors like red and green. Blue isn't recognized. That's annoying.

So I still try to figure things out. Maybe I reduce the number of bulbs to one again. It's not easy to make one change in code and then add this change to more than one file.

Also my node bridge disappeared forever and I had to change the bridge id to find it again in the home app.

Alblahm commented 8 years ago

I agree, try first with only one bulb, test with only one bulb connected and when everything works fine duplicate the files and change the id's for each accesory file. Please upload a log with the responses for this one-file test.

The one file per device is not a rule but it allows you to control the devices by the name you set in the ios home app. If you change the name inside the ios home app, siri recognizes it by the new name you gave there. If the device do not work, only plug and unplug the light bulb. It also happens to me sometimes if I use the avea app and then use the home app. It seems that avea app captures the bt port and it does not free it when you close, but as soon as i unplug it works fine. Nevertheless, I always turn off the bluetooth in the tablet while I'm working with the home app to avoid any interference with the bluetooth of the raspi.

Take a lot of care with the errors, because some of them causes the service to enter in a failed state but without any error msg on the log. Ussually this is due to the ausence of a callback function in the code that makes the soft be in a wait state. To be sure that any changes are the reason, move the accessory file out of the accessories folder, and restart the homebrige service. If every other devices works fine, then the problem is in your file.

In my case the bridge node stopped working once, some weeks ago, but it happens if the ios is not able to access the iCloud info in two days. I changed the settings, restart and everything was fine.

The problem with the blue color change also happens in spanish sometimes, but is related with the articles in the sentence you say. Tell him in short way, I mean: Instead of saying, change the color of the room lamp to blue, say change color of room lamp blue. I dont know why, but siri sometimes does not recognize the articles on the sentences. Also avoid the hey siry in the same sentence. In my case with some sentences, i dont exactly remember which, if I say, hey siry turn on the ceil lamp it does not recognize the action but if i press the button to speak and say turn on the ceil lamp, it works fine. So try to remake your sentences and write the order that always work.

I have made a small comment on bottom of the accessory file with the sentences that work in my language. (Siri is not as intelligent as it is supposed to be 😐. But they will improve this issues with time...). If you want you can complete the list of commands that work fine in german language.

Nice job!

Last Version (25/10/2016): Luz_VerticalComedor_accessory.js.txt

thymjan commented 8 years ago

This is my current test procedure: 05 close home app, close avea app 10 bulb is powered on 20 Avea app: pure bright red [bulb shows pure red light] 30 close Avea app 40 sudo node Bridged.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: Luz_VerticalComedor_accessory.js
info: connecting bulb=7cec79d75f47
(node:8017) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Peripheral already connected

55 open home app: home app shows brightness 50% (shows not the correct state!)

info: write bulb=7cec79d75f47, data=35
info: received bulb=7cec79d75f47, data=35000000000000102720fe37000000102820ff37
... Estaba encendida Esstischlampe? Si.

50 home app: switch bulb off [gets dark]

reconectando... 
... Apagando Esstischlampe!
info: setColor bulb=7cec79d75f47, white=0, red=0, green=0, blue=0, delay=1535
info: connecting bulb=7cec79d75f47
info: write bulb=7cec79d75f47, data=35ff050a000080003000200010
info: received bulb=7cec79d75f47, data=35ff0500000000102820ff370000001000200030

60 home app: switch bulb on [shows reddish white light, home app shows brightness: 50%]

reconectando... 
... Encendiendo Esstischlampe!
info: setColor bulb=7cec79d75f47, white=0x800, red=0x800, green=0x14, blue=0x36, delay=255
info: connecting bulb=7cec79d75f47
info: write bulb=7cec79d75f47, data=35ff000a000088003814203610
info: received bulb=7cec79d75f47, data=35ff000000000010002000300008361014200038

70 home app: change brightness to 70%

reconectando... 
... Encendiendo Esstischlampe!
info: setColor bulb=7cec79d75f47, white=0x800, red=0x800, green=0x14, blue=0x36, delay=255
info: connecting bulb=7cec79d75f47
... Nuevo valor de brillo: 70
reconectando... 
... Encendiendo Esstischlampe!
info: setColor bulb=7cec79d75f47, white=0xB33, red=0xB33, green=0x1C, blue=0x4B, delay=255
... Nuevo valor de brillo: 67
info: write bulb=7cec79d75f47, data=35ff000a000088003814203610
info: received bulb=7cec79d75f47, data=35ff000000083610142000380008361014200038
info: write bulb=7cec79d75f47, data=35ff000a00338b333b1c204b10
info: received bulb=7cec79d75f47, data=35ff00000008361014200038330b4b101c20333b
... Encendiendo Esstischlampe!
info: setColor bulb=7cec79d75f47, white=0xAB8, red=0xAB8, green=0x1B, blue=0x48, delay=255
... Nuevo valor de brillo: 70
info: write bulb=7cec79d75f47, data=35ff000a00b88ab83a1b204810
info: received bulb=7cec79d75f47, data=35ff0000370a44101920373ab80a48101b20b83a

80 home app: change brightness to 10%

reconectando... 
... Encendiendo Esstischlampe!
info: setColor bulb=7cec79d75f47, white=0xB33, red=0xB33, green=0x1C, blue=0x4B, delay=255
info: connecting bulb=7cec79d75f47
... Nuevo valor de brillo: 52
reconectando... 
... Encendiendo Esstischlampe!
info: setColor bulb=7cec79d75f47, white=0x851, red=0x851, green=0x15, blue=0x38, delay=255
... Nuevo valor de brillo: 36
info: write bulb=7cec79d75f47, data=35ff000a00338b333b1c204b10
info: received bulb=7cec79d75f47, data=35ff0000b80a48101b20b83a330b4b101c20333b
info: write bulb=7cec79d75f47, data=35ff000a005188513815203810
info: received bulb=7cec79d75f47, data=35ff0000c10a48101b20c13a5108381015205138
... Encendiendo Esstischlampe!
info: setColor bulb=7cec79d75f47, white=0x5C2, red=0x5C2, green=0xE, blue=0x27, delay=255
... Nuevo valor de brillo: 27
info: write bulb=7cec79d75f47, data=35ff000a00c285c2350e202710
... Nuevo valor de brillo: 20
info: received bulb=7cec79d75f47, data=35ff00005108381015205138c20527100e20c235
... Encendiendo Esstischlampe!
info: setColor bulb=7cec79d75f47, white=0x333, red=0x333, green=0x8, blue=0x15, delay=255
... Nuevo valor de brillo: 17
info: write bulb=7cec79d75f47, data=35ff000a003383333308201510
info: received bulb=7cec79d75f47, data=35ff0000c20527100e20c2353303151008203333
... Encendiendo Esstischlampe!
info: setColor bulb=7cec79d75f47, white=0x2B8, red=0x2B8, green=0x6, blue=0x12, delay=255
... Nuevo valor de brillo: 14
info: write bulb=7cec79d75f47, data=35ff000a00b882b83206201210
info: received bulb=7cec79d75f47, data=35ff00003303151008203333b80212100620b832
... Encendiendo Esstischlampe!
info: setColor bulb=7cec79d75f47, white=0x23D, red=0x23D, green=0x5, blue=0xF, delay=255
... Nuevo valor de brillo: 12
info: write bulb=7cec79d75f47, data=35ff000a003d823d3205200f10
info: received bulb=7cec79d75f47, data=35ff0000b80212100620b8323d020f1005203d32
... Encendiendo Esstischlampe!
info: setColor bulb=7cec79d75f47, white=0x1EB, red=0x1EB, green=0x4, blue=0xD, delay=255
... Nuevo valor de brillo: 10
info: write bulb=7cec79d75f47, data=35ff000a00eb81eb3104200d10
info: received bulb=7cec79d75f47, data=35ff00003d020f1005203d32eb010d100420eb31

90 bulb power off 100 home app: no recognition! still shows bulb on 10% 110 home app: switch bulb off (home app still doesn't recognize the bulb is powered off)

reconectando... 
... Apagando Esstischlampe!
info: setColor bulb=7cec79d75f47, white=0, red=0, green=0, blue=0, delay=1535
info: connecting bulb=7cec79d75f47

120 home app: switch bulb on

reconectando... 
... Encendiendo Esstischlampe!
info: setColor bulb=7cec79d75f47, white=0x199, red=0x199, green=0x4, blue=0xA, delay=255

130 home app: change brightness to 30%

reconectando... 
... Encendiendo Esstischlampe!
info: setColor bulb=7cec79d75f47, white=0x199, red=0x199, green=0x4, blue=0xA, delay=255
... Nuevo valor de brillo: 21
reconectando... 
reconectando... 
... Encendiendo Esstischlampe!
info: setColor bulb=7cec79d75f47, white=0x35C, red=0x35C, green=0x8, blue=0x16, delay=255
... Nuevo valor de brillo: 29
reconectando... 
reconectando... 
... Encendiendo Esstischlampe!
info: setColor bulb=7cec79d75f47, white=0x4A3, red=0x4A3, green=0xB, blue=0x1F, delay=255
... Nuevo valor de brillo: 32
reconectando... 
reconectando... 
... Encendiendo Esstischlampe!
info: setColor bulb=7cec79d75f47, white=0x51E, red=0x51E, green=0xD, blue=0x22, delay=255
... Nuevo valor de brillo: 31
reconectando... 
reconectando... 
... Encendiendo Esstischlampe!
info: setColor bulb=7cec79d75f47, white=0x4F5, red=0x4F5, green=0xC, blue=0x21, delay=255
... Nuevo valor de brillo: 30
reconectando... 

140 home app: switch bulb off

reconectando... 
... Apagando Esstischlampe!
info: setColor bulb=7cec79d75f47, white=0, red=0, green=0, blue=0, delay=1535

150 home app: switch bulb on

reconectando... 
... Encendiendo Esstischlampe!
info: setColor bulb=7cec79d75f47, white=0x4CC, red=0x4CC, green=0xC, blue=0x20, delay=255

160 power bulb on again [shows reddish white light again]

info: write bulb=7cec79d75f47, data=35ff050a000080003000200010
info: received bulb=7cec79d75f47, data=35ff0500000000100f2032330000001000200030
info: write bulb=7cec79d75f47, data=35ff000a009981993104200a10
info: received bulb=7cec79d75f47, data=35ff0000000000100e20223399010a1004209931
info: write bulb=7cec79d75f47, data=35ff000a009981993104200a10
info: received bulb=7cec79d75f47, data=35ff00001f0000100d20033399010a1004209931
info: write bulb=7cec79d75f47, data=35ff000a005c835c3308201610
info: received bulb=7cec79d75f47, data=35ff00003c0000100c20e7325c03161008205c33
info: write bulb=7cec79d75f47, data=35ff000a00a384a3340b201f10
info: received bulb=7cec79d75f47, data=35ff0000980002100b20f432a3041f100b20a334
info: write bulb=7cec79d75f47, data=35ff000a001e851e350d202210
info: received bulb=7cec79d75f47, data=35ff00005f0107100b2046331e0522100d201e35
info: write bulb=7cec79d75f47, data=35ff000a00f584f5340c202110
info: received bulb=7cec79d75f47, data=35ff0000a80109100b206a33f50421100c20f534
info: write bulb=7cec79d75f47, data=35ff050a000080003000200010
info: received bulb=7cec79d75f47, data=35ff0500e9010a100b2088330000001000200030
info: write bulb=7cec79d75f47, data=35ff000a00cc84cc340c202010
info: received bulb=7cec79d75f47, data=35ff0000e20109100a207c33cc0420100c20cc34

170 home app: switch bulb off

... Apagando Esstischlampe!
info: setColor bulb=7cec79d75f47, white=0, red=0, green=0, blue=0, delay=1535
info: write bulb=7cec79d75f47, data=35ff050a000080003000200010
info: received bulb=7cec79d75f47, data=35ff0500cc0420100c20cc340000001000200030

180 home app: switch bulb on

... Encendiendo Esstischlampe!
info: setColor bulb=7cec79d75f47, white=0x4CC, red=0x4CC, green=0xC, blue=0x20, delay=255
info: write bulb=7cec79d75f47, data=35ff000a00cc84cc340c202010
info: received bulb=7cec79d75f47, data=35ff00000000001000200030cc0420100c20cc34

Luz_VerticalComedor_accessory.js.txt

thymjan commented 8 years ago
// Here we show the list of Siri voice commands accepted with this accessory file.
// ***********************************************************************************
// The name asigned in the ios home app to this sample device is "Lámpara de Pie" and it is placed in a room called "Comedor" for the spanish version, 
// if you use any other  name or room use the name assigned instead of the name shown here. This section is only informative, there is no code here, so 
// any change inside this section do not affect the behaviour of the ios home app.
// --------------------------------------------------
//  Accessory room(english): "living-room"
//  Accessory room(spanish): "Comedor"
//   Accessory room(german): "Wohnzimmer"
//      Accessory room(...): "****"
// --------------------------------------------------
//  Accessory name(english): "lamp"
//  Accessory name(spanish): "Lámpara de Pie"
//   Accessory name(german): "Lampe"
//      Accessory name(...): "*****"
// --------------------------------------------------
//       Command 1(english): "turn on the living room lamp"
//       Command 1(spanish): "Enciende la lampara de pie del comedor"
//        Command 1(german): "Wohnzimmer Lampe einschalten"
// --------------------------------------------------
//       Command 2(english): "turn off the living room lamp"
//       Command 2(spanish): "Apaga la lampara de pie del comedor"
//        Command 3(german): "Wohnzimmer Lampe ausschalten"
// --------------------------------------------------
//       Command 3(english): change the brightness of the living room lamp to 50
//       Command 3(spanish): Cambia el brillo de la Lámpara de Pie a 50
//        Command 3(german): "Wohnzimmer Lampe 30%"
// --------------------------------------------------
//       Command 4(english): change the color of the living room lamp to red
//       Command 4(spanish): Cambia el color de la Lámpara de Pie a rojo
//        Command 4(german): "Licht der Wohnzimmerlampe grün / blau / gelb / orange / pink"
//        ("rot" wird nicht erkannt)
// --------------------------------------------------
thymjan commented 8 years ago

Would it make sense to make a own repository out of this threat for the accessory file? What do you think?

thymjan commented 8 years ago

My Apple TV 5 drives me mad: noble: unknown peripheral c869cd6b2fe9 connected! noble: unknown peripheral c869cd6b2fe9 disconnected! noble: unknown peripheral c869cd6b2fe9 connected! noble: unknown peripheral c869cd6b2fe9 disconnected! noble: unknown peripheral c869cd6b2fe9 connected! noble: unknown peripheral c869cd6b2fe9 disconnected! noble: unknown peripheral c869cd6b2fe9 connected! ... It is not on the whitelist. I have no clue why it connects and disconnects every 5 seconds. Do you have an idea how I get rid of this stuff? I have to switch off the apple TV at the moment.

Alblahm commented 8 years ago

I think that this would be a good option. You can create a fork based on this lib, and change the readme file to include all the previous info condensed. If you make any other test with this accessory file, please, first add a line to the avea.js file inside the lib folder:

winston.level='warn';

This avoid all the comments related with the avea lib and is more easy to follow all the sequence of commands.

I've been using this lib all this days without any error. I've added some other devices like a samsung tv accessory that allows to play music, or radio using Siri to control the home app. It sends the commands directly to kodi to play all the media.

Alblahm commented 8 years ago

I do not have an apple tv but i've read something about, you have conected it directly to the ios home app, or you have created a new accessory file to use it through the bridge? Find info on the internet, and try with both optios to see if one works fine.

thymjan commented 8 years ago

Everything works fine with the apple tv. But I didn't told the apple tv to connect to the bluetooth device of my raspberry. But it does this since several days ago. I tried to put it on the blacklist of the raspberry. No change to get rid of this evil behavoir to connect and disconnect every few seconds to my raspberry. It's something like a bluetooth brute force attack.

Alblahm commented 8 years ago

Ahh, ok then probably the best way is let the apple tv connect to it, pair with the rasp and then it probably detects that this device do not share any usefull resource with the apple tv through bt, and it just stop asking to connect. Have you tried that?

Alblahm commented 8 years ago

Answer to the log comments:

55 open home app: home app shows brightness 50% (shows not the correct state!)

This happens at the beggining, and this is normal because the accessory file only asks the lamp if it is on or off. And gets the def value, that is the 50%. I told in a previous comment that this driver only sets, it never reads from the lamp, it reads from the state vars inside the js file. So if you use any 3rd party app to make changes it does not realize about the changes.

thymjan commented 8 years ago

I told in a previous comment that this driver only sets, it never reads from the lamp, it reads from the state vars inside the js file.

I didn't get this point before. So it is also not possible to get the state of the bluetooth connection? I mean if I power off a bulb, the bluetooth connection is broken. The home app may show "no answer" and the "!" in the upper right corner. And if I power on the bulb again the bulb is reconnected and the "no answer"-message and the "!" disappears? The bulbs should be always switched on? Would be difficult here with my wife and 3 little daughters...

thymjan commented 8 years ago

For the repository-thing: wouldn't it be enough to show up only the accessory file and point to the avea libs and HAP-NodeJS?

thymjan commented 8 years ago

Do you know what this means:

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

By the way, I've tested my three-bulbs-setting again: it works! (till my wife switched off the lights. Now the home app even doesn't recognize the avea-node-bridge again. Have to change the username-id in BridgedCore.js once again.)

thymjan commented 8 years ago

To get more solid colors I changed line var iComp="0x" + Math.floor(Math.min(4095,(OFFICELIGHT.brightness*4096)/100)).toString(16).toUpperCase(); to this: var iComp="0x" + Math.floor(Math.min(4095,(Math.max(0,(OFFICELIGHT.brightness-30))*4096)/100)).toString(16).toUpperCase();

If brightness is lower than 30 the bulb doesn't show any more white fraction.

Alblahm commented 8 years ago

The unhandled error I suppose that is related with the three bulbs, I mean, when it inits the lights, probably it enters in the connect function more than once and then it tries to reconnect the same bulb twice. To solve this probably you can add more checks to avoid this case.

Alblahm commented 8 years ago

There is one more thing that should be corrected, but i'm working on it. If you revise the logs, while you are changing the brightness in the ios app with the slide control, in the log you can see two msgs for each change. One is related with the event of changing brightness and the other is the msg that appears when it turns on the bulb. This makes the response slower, because it sends twice the same, once to change the brightness and the second to turn the light on. The second one is not needed, so it should be avoided. I'll solve in someway...

thymjan commented 8 years ago

The unhandled error I suppose that is related with the three bulbs

The error appears even with one accessory file. Every time the bulb is connected for the first time, after parsing the accessory file.

thymjan commented 8 years ago

Something seems to be not ok with the saturdation. Try to say something like "set saturdation of dining lamp to 0" or "set saturdation of dining lamp to 100". The accessory file sets the saturdation, but the color of the lamp doesn't change (the log says it does). But the color-model doesn't react to changes of saturdation. If saturdation is 0% the light should be white with no color leds on. If saturdation is 100% there should be a solid color (single r/g/b-led or a mix of it) and the white led should be off. Do you agree? I manipulated the logging once again to figure this out: dining_accessory.js.txt

Alblahm commented 8 years ago

I've seen your file, and there is something strange in it. You set a different serial number for each of your three lights, but do you change the username hexadecimal address on each file? Because you must do it, and this can be one of the causes of some of the errors you found. Each accessory file should have a different hex address. I'm not speaking about the bluetooth address, i mean the one that you set in the previous line of the pincode.

light.username = "FF:FF:FF:FF:FF:1A";

Alblahm commented 8 years ago

As soon as i get home, i'll upload the last version of my file, and you can check it without any change, only with one bulb, and let me see the log output. But do not change anything in the file. Dont set the bt light address, leave it with the default null value. And try to reproduce all the wrong behaviours with this accessory file. I cannot upload today. Perhaps tomorrow night.

Alblahm commented 8 years ago

What happened with the bt problem of the apple tv? You solved the problem?