snOOrz / homebridge-aqara

HomeBridge plugin for Aqara gateway and devices
539 stars 74 forks source link

Problem with port #37

Open ghost opened 7 years ago

ghost commented 7 years ago

Hi! Tried to use homebridge-aqara, but faced with a problem.

  1. If I do everything out-of-the-box, then I see error, msg - bind EADDRINUSE 0.0.0.0:9898, stack - Error: bind EADDRINUSE 0.0.0.0:9898 at homebridge log and Aqara plugin doesn't work.
  2. If I change serverPort in AqaraPlatform.js, then plugin starts well, but after receiving initial data from sensors do nothing. I mean, I get proper states of all sensors right after starting homebridge, but then I get no updates, even if sensors changed their state. Both at Home app on iOS device and in homebridge log sensor's state doesn't change. What could be wrong? I checked with lsof if some other apps use 9898 port, but nothing. I run homebridge on macOS, all devices are in same network, all preparations (getting Gateway sid, password, enabling local network) are done correctly. Homebridge-hue plugin works without issues.
javefang commented 7 years ago

I noticed macOS doesn't always release the port after a force close of homebridge. Try reboot your machine see if that fixes the problem. Otherwise, check if anything else is running which is using the port. On Sun, 5 Feb 2017 at 13:09, Alexander notifications@github.com wrote:

Hi! Tried to use homebridge-aqara, but faced with a problem.

  1. If I do everything out-of-the-box, then I see error, msg - bind EADDRINUSE 0.0.0.0:9898, stack - Error: bind EADDRINUSE 0.0.0.0:9898 at homebridge log and Aqara plugin doesn't work.
  2. If I change serverPort in AqaraPlatform.js, then plugin starts well, but after receiving initial data from sensors do nothing. I mean, I get proper states of all sensors right after starting homebridge, but then I get no updates, even if sensors changed their state. Both at Home app on iOS device and in homebridge log sensor's state doesn't change. What could be wrong? I checked with lsof if some other apps use 9898 port, but nothing. I run homebridge on macOS, all devices are in same network, all preparations (getting Gateway sid, password, enabling local network) are done correctly. Homebridge-hue plugin works without issues.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/snOOrz/homebridge-aqara/issues/37, or mute the thread https://github.com/notifications/unsubscribe-auth/ABJRxFDGQ1qwY8ZXTrEsmBPoQnMY-bkZks5rZcn4gaJpZM4L3ffN .

ghost commented 7 years ago

Yep, you right. After reboot it works fine. I transferred all stuff to Raspberry Pi, now all sensor's data displayed correctly at iOS Home app. And app immediately reacts on sensor's state changes. But I have another issue now: automations don't work. For example, I made automation "if Aqara contact sensor is opened – turn on the Hue light". If I open the door, Home app shows that sensor's state is changed to 'opened', but Hue light does not turning on. Same thing with all sensors. Couple of times automations work – after I reboot everything (Pi, router, AppleTv), but only once. I make another automation, completely on Hue accessories: "if one Hue lamp is turned on, turn off another one" and it works correctly. Could you please tell me, what could be wrong?

adekka commented 7 years ago

I have the same issue. What happens when you have the Home app open while opening the door?

ghost commented 7 years ago

@adekka In Home app I see that sensor state immediately changes to 'opened', but for unknown reason it doesn't trigger automation – lights not turning on. I didn't find solution yet. I tried to make automation using only Hue accessories (lights are exposed to Home app natively, switches are exposed via homebridge) and they seems to work. I have Philips Dimmer Switch with for buttons: on, off, dim up, dim down and it is possible to rewrite behaviour of each button. It makes me think that problem is in homebridge-aqara, not in homebridge itself or Apple TV, because automations that are not using aqara sensors works well. Now I added home-assistant to my RPi, removed homebridge-aqara and added all xiaomi sensors to home-assistant. With plugin, I'm able to expose home-assistant stuff to Homekit. I'll check if automations work with such setup. Home-assistant adds additional layer between Homekit and Aqara, but it provides nice webgui and some rules could be configured right on it instead of Homekit (and be more complex). So now I use homebridge + home-assistant as temporary (maybe constant) soution. I'll write later about automations work or not.

adekka commented 7 years ago

My experience is that the automation works (for some time) when I have the app open. And somehow it doesn't work when I close the app.

I like your approach. I'm currious how it works out. I might do the same with Domoticz.

ghost commented 7 years ago

@adekka I already tried Domoticz and found it more complex and less well-looking then home-assistant. And Domoticz refused to add Hue accessories in my case. I checked automation with Domoticz – it made by Blocks (visual programming) or by Lua scripts. And it doesn't work either :) So, my opinion that Domoticz is interesting (btw it provides not only Aqara sensors, but Gateway itself, like RGB led), but its design and UI structure and complex way to make automations make me to choose home-assistant. OpenHub already looks interesting, but as I know it doesn't have bindings for Aqara yet.

ghost commented 7 years ago

Well, I've done some tests. First of all, here is my current setup: – RPi 3 + homebridge + home-assistant – HomeKit <-> homebridge <-homebridge-hass_plugin-> home-assistant <-> Aqara Gateway – Philips Hue exposed to all systems: –– bulbs to HomeKit natively –– switches to homebridge using homebridge-hue plugin –– bulbs to home-assistant using native homeassistant configure tool So, I see both Hue and Aqara at my Home iOS app. Aqara provided only by home-assistant via homebridge (i.e I don't use homebridge-aqara). And... Automations don't work either! :) The only one automation I was able to get work is Aqara wireless button. It works) Motion sensor or contact sensor don't work at all. I see their state changes properly in Home app, but nothing happens. Otherwise, home-assistant based automations work well. I think I'll use them now. It has simple YAML config file, that could be easily saved (while automations in Home app could not be exported or saved), I think it better solution. And seems like it's not homebridge-aqara fault: I tried 3 systems, Domoticz, Hass, homebridge-aqara and none of them provide Aqara sensors that could work in Homekit automations. Don't know why, just a fact.

abaozang commented 7 years ago

@imisanthrope Hey there. I am trying the same combination like you. I'm able to turn the light on through homebridge aqara using motion sensors, but further I want the light turned off automatically if I am not around or no motion is detected by sensors. And also I would like to use the button switchers to control my lights. Homeassistant can do this. But I got the port problem since I was trying to connect the xiaomi gateway to connect to both homebridge and home assistant. I did manually change the port in the code of aqara.by but the port got changed back to 9898 when I restarted homeassistant. How did you solve that? Thx in advance

ghost commented 7 years ago

@abaozang Hi! Could you please give more detail about your setup? I was not able to make automations work through homebridge-aqara. Here is my first setup: – Hue bulbs, exposed to iOS Home app natively (natively means through adding Hue bridge in Home app) – Hue switches, exposed to Home app with homebridge-hue plugin – Aqara sensors, exposed to Home app with homebridge-aqara plugin With this setup I able to see everything at Home app (bulbs, switches, sensors). But when I try to make native automations (native = inside Home app) I get such results:

  1. trigger> Hue bulb, action> Hue bulb (for example if bulb_1 is on -> turn bulb_2 off) – works perfectly. Homebridge is not necessary for such automation.
  2. trigger> Hue switch, action> Hue bulb – works perfectly. Homebridge + homebridge-hue is required for such automation, because Hue switches could not be exposed natively (also third-party iOS app needed, because native Home app does not support dimmer switches).
  3. trigger> aqara motion/magnet sensor action> Hue bulb – not working. Executed 1 time, after rebooting everything: homebridge, AppleTV, router. 2nd time not working at all. But Home app properly reflects sensor state, I mean it shows that Motion sensor detects motion, or Magnet sensor is opened/closed, but action is not executed.
  4. trigger> aqara button, action> Hue bulb – worked 1-2 times, then not working. Button state at the Home app also displayed properly, but action not executed.

My second setup is with home-assistant. I've added everything (aqara, Hue) in it, removed both homebridge-aqara and homebridge-hue plugins, so homebridge used only to expose home-assistant stuff to Home app. Results are the same – native automations don't work. What is your setup? What triggers you used, what devices are used as actions? And about your question: do you have both home-assistant and homebridge-aqara active? They will conflict, because try to listen to same 9898 port. Remove homebridge-aqara to solve it. Again, I need more details about your setup)

abaozang commented 7 years ago

@imisanthrope I think my config is almost exactly the same as yours. I have also this feeling that automations don't execute every time. But i am not sure if it's because of the homebridge or homekit itself. Both Hue and Mi App work fine...

ghost commented 7 years ago

@abaozang Yep, for me MiHome app and automations within it works perfect. Homekit automations with Hue lights work perfect too. So I think something wrong with bridge between Aqara and Homekit, whatever it is. Nevertheless, I use home-assistant now and build all automations within it. I use Homekit only for voice control via Siri.