Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Two homebridge instances as TWO SERVICES #1246

Closed
PatiB87 opened this issue Apr 6, 2017 · 40 comments
Closed

Two homebridge instances as TWO SERVICES #1246

PatiB87 opened this issue Apr 6, 2017 · 40 comments
Labels

Comments

@PatiB87
Copy link

PatiB87 commented Apr 6, 2017

Hey,

I can already successfully run two Homebridge, one is currently set up as service (init.d on Raspberry Pi on Jessie) and the other one is started manually via the command line.
I therefore copied the /home/pi/.homebridge folder to /home/pi/.homebridge-k to have a second config.json file.
Now I can successfully run the second instance with "sudo homebridge -U /home/pi/.homebridge-k" but I don't know how to set up a second service.

I tried just to create a "homebridge-k" service in a similar fashion as I created the original "homebridge" service (according to these instruction: https://github.com/nfarina/homebridge/wiki/Running-HomeBridge-on-a-Raspberry-Pi#running-homebridge-on-bootup-initd) but it ain't working. :(

Thanks a lot for helping. :)

@SkyJohn
Copy link

SkyJohn commented Apr 6, 2017

You mean you can't add both in the Home app?

I think you'd need to give each a different name in the config file to do that.

@PatiB87
Copy link
Author

PatiB87 commented Apr 7, 2017

Hey, thanks for he reply :)

No, that works fine.
I just don't know how to start two separate instances as service with init.d or how to use the -U flag in a second service respectively?

@dkrizic
Copy link

dkrizic commented Apr 20, 2017

I think the services should have different IP addresses, different names and different "usernames" (the hex string) so HomeKit knows that there are actually two different HomeKit bridges.

@NorthernMan54
Copy link
Contributor

NorthernMan54 commented Apr 20, 2017 via email

@kapps7
Copy link

kapps7 commented Apr 20, 2017

What is the advantage of having more than one instance off home bridge

@NorthernMan54
Copy link
Contributor

NorthernMan54 commented Apr 20, 2017 via email

@kapps7
Copy link

kapps7 commented Apr 20, 2017

Thanks, thats a good tip. Only yesterday I was thinking a search function in the Home app would be useful ;)
By your standards what do you consider a large number of accessories for a stable home bridge.

@NorthernMan54
Copy link
Contributor

NorthernMan54 commented Apr 20, 2017 via email

@kapps7
Copy link

kapps7 commented Apr 21, 2017

I have roughly 20 accessories running on the single instance and keep an eye out on stability.

On a side note, if I run homebridge on a remote computer and want to add it to my HomeKit as a second instance , will I need to be on the local network of that computer ?

@jenskastensson
Copy link

Just to confirm: the number of bridge instances is not related to/will not affect the maximum number of devices (=100) right?

@KhaosT
Copy link
Contributor

KhaosT commented Apr 21, 2017

Nope, each bridge can host 99 accessories. (Although HomeKit does have a maximum 1000 accessories limit).

@NorthernMan54
Copy link
Contributor

NorthernMan54 commented Apr 21, 2017 via email

@kapps7
Copy link

kapps7 commented Apr 21, 2017

I see or perhaps if you had a hub at the remote location signed into the same iCloud id as yours ?
I suppose its too complex to add an accessory remotely instead.

@ebaauw
Copy link
Contributor

ebaauw commented Apr 25, 2017

By your standards what do you consider a large number of accessories for a stable home bridge.

I'm running a single homebridge instance on my Mac mini server with homebridge-hue exposing 79 accessories (from a v2 Hue bridge) and homebridge-zp exposing 4 accessories.

Although HomeKit does have a maximum 1000 accessories limit

You'll hit the CKRecord limit way before that.

@simonrb2000
Copy link

I have just setup my second homebridge instance as am now over 100 devices. Wondered how you get the command "homebridge -U ~/.homebridge2" (which is mine) to run as a service?

Cheers

@viictor924
Copy link

Hey @PatiB87 ,

Were you able to figure out a solution to your problem? @NorthernMan54's response helped me set up a second instance of homebridge which I can run manually but I haven't been able to add this second instance to init.d/. Which I think was your original issue but then this thread conversation got derailed. My first homebridge instance gets run on reboot successfully but the second one doesn't. Also, when I do "sudo /etc/init.d/homesean start" the terminal outputs "starting", but if I follow up with "sudo /etc/init.d/homesean status" I get "Not running"

#================================================
#/etc/init.d/homebridge
#first homebridge instance
dir="/home/pi"
cmd="DEBUG=* /usr/bin/homebridge"
user="pi"
#================================================

#================================================
#/etc/init.d/homesean
#second homebridge instance
dir="/home/pi"
cmd="DEBUG=* /usr/bin/homebridge -U ~/.homesean"
user="pi"
#================================================

Strangely, when I do this manually homebridge will run successfully:
$ cd /home/pi
$ /usr/bin/homebridge -U ~/.homesean

.. which I don't think makes sense since that is the same cmd in the init.d file.

@ramsnerm
Copy link

Hi @viictor924,
Crosscheck your settings again. I see in your message you use following command to start

cmd="DEBUG=* /usr/bin/homebridge -U ~/.homesean"

Here you are using ~ as a short way to point to your directory but be aware that a service is no started with your username (if not explicitly set) so try it again with a fully qualified path e.g.

/home/pi/.homesan.

Hope this helps
BR / Marin

@viictor924
Copy link

Thanks @ramsnerm, I changed the path and then did "sudo update-rc.d homesean defaults" and it seems to be working now!

@viictor924
Copy link

Actually, I spoke too soon! homesean runs on startup now but homebridge stopped running on startup. I can still run both simultaneously by doing "/etc/init.d/homesean start" and "/etc/init.d/homebridge start". However, when I reboot the pi only homesean starts running

#================================================
#/etc/init.d/homebridge
#first homebridge instance
#I added "-U /home/pi/.homebridge" to the cmd
dir="/home/pi"
cmd="DEBUG=* /usr/bin/homebridge -U /home/pi/.homebridge"
user="pi"
#================================================

#================================================
#/etc/init.d/homesean
dir="/home/pi"
cmd="DEBUG=* /usr/bin/homebridge -U /home/pi/.homesean"
user="pi"
#================================================
I edited the init.d files as above and then ran the following:
$ sudo chmod 755 /etc/init.d/homesean
$ sudo chmod 755 /etc/init.d/homebridge
$ sudo update-rc.d homesean defaults
$ sudo update-rc.d homebridge defaults
$ sudo reboot

However, after the pi reboots only homesean is running.

@jeylites
Copy link

jeylites commented Oct 26, 2017

I followed the @NorthernMan54 instructions and got the second instance setup, however, I'm unable to run the second homebrige without including the plugin from the first instance in the config file. Otherwords, the plugin won't allow the second homebridge to run if it's not in the config.

Has anyone looked into a homebridge container using Docker? I've seen a couple on docker hub but the problem I'm facing is I'm unable to install the application in the container due to capabilities issues and also lack of experience setting it up.

The needs
First instance running Domoticz, broadlink plugin
The second instance running IP cameras

`pi@raspberrypi:~ $ homebridge -U ~/.homecam
*** 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
[10/26/2017, 9:37:58 AM] Loaded plugin: homebridge-broadlink-rm
[10/26/2017, 9:37:58 AM] Registering platform 'homebridge-broadlink-rm.BroadlinkRM'
[10/26/2017, 9:37:58 AM] ---
[10/26/2017, 9:37:58 AM] Loaded plugin: homebridge-camera-ffmpeg-omx
[10/26/2017, 9:37:58 AM] Registering platform 'homebridge-camera-ffmpeg-omx.Camera-ffmpeg-omx'
[10/26/2017, 9:37:58 AM] ---
[10/26/2017, 9:37:59 AM] Loaded plugin: homebridge-edomoticz
[10/26/2017, 9:37:59 AM] Registering platform 'homebridge-edomoticz.eDomoticz'
[10/26/2017, 9:37:59 AM] ---
[10/26/2017, 9:37:59 AM] Loaded config.json with 0 accessories and 1 platforms.
[10/26/2017, 9:37:59 AM] ---
[10/26/2017, 9:37:59 AM] Loading 1 platforms...
[10/26/2017, 9:37:59 AM] Initializing Camera-ffmpeg-omx platform...
[10/26/2017, 9:37:59 AM] Loading 0 accessories...
Load homebridge-edomoticz.eDomoticz
/usr/lib/node_modules/homebridge-edomoticz/index.js:96
this.server = config.server;
^

TypeError: Cannot read property 'server' of null
at eDomoticzPlatform (/usr/lib/node_modules/homebridge-edomoticz/index.js:96:23)
at Server._loadDynamicPlatforms (/usr/lib/node_modules/homebridge/lib/server.js:315:30)
at Server.run (/usr/lib/node_modules/homebridge/lib/server.js:82:8)
at module.exports (/usr/lib/node_modules/homebridge/lib/cli.js:40:10)
at Object. (/usr/lib/node_modules/homebridge/bin/homebridge:17:22)
at Module._compile (module.js:571:32)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)`

@ebaauw
Copy link
Contributor

ebaauw commented Oct 26, 2017

Before goong Docker, you could try and specify a different plugin directory for the second instance (I think this is done through the -P command line parameter).

@jeylites
Copy link

jeylites commented Oct 26, 2017

@ebaauw Sorry - How to use the -p command line, below is how I have my directory setup

The problem seems to be on the domoticz plugin. Other plugins no problem.

Homebridge 1
/var/homebridge

Homebridge 2
/var/homecam

@ebaauw
Copy link
Contributor

ebaauw commented Oct 26, 2017

See https://github.com/nfarina/homebridge#plugin-development. I guess you could start Homebridge 2 as:

homebridge -U ~/.homecam -P /usr/lib/node_modules/homebridge-camera-ffmpeg-omx

If not, move the camera plugin to a different directory and specify that for -P.

@NorthernMan54
Copy link
Contributor

NorthernMan54 commented Oct 26, 2017 via email

@jeylites
Copy link

jeylites commented Oct 27, 2017

@ebaauw - "-p" Will give it a go to see what comes out of it.
@NorthernMan54 - I took your advice and have raised the question on edomoticz, hope it gets address soon.

The other thing is I've been experimenting with homebridge Docker compiled by @oznu, very cool stuff. If anyone wants to give it a go, check his GitHub link. Also, there are other Homebridge Docker image out there running on Synology, RPI that I have yet to try.

With his help, I was able to set up several instances in containers. The only bummer for me is since I need ffmpeg-omx to run my cameras, omx is not Alpine Linux compatible from what I was told. However, there's a ffmpeg image available on Alpine hub.

The other thing is, I have no idea how to set up a container running Peter Scargill scrip and/or a container running Rasbian to install whatever stuff in it.... similar to a VM.

@stale
Copy link

stale bot commented Apr 25, 2018

This issue has been automatically marked as stale because it has not had recent activity, and will be closed if no further activity occurs. If this issue was overlooked, forgotten, or should remain open for any other reason, please reply here to call attention to it and remove the stale status. Thank you for your contributions.

@stale stale bot added the stale label Apr 25, 2018
@stale stale bot closed this as completed May 9, 2018
@vzlgdu
Copy link

vzlgdu commented Mar 23, 2019

Hi, about running 2 hombridges istances, my question is: if I install a new plugin in this environment, this plugin will be available for both istances, also if I can configure the plugin only in one config.json file. Is this right?

@ebaauw
Copy link
Contributor

ebaauw commented Mar 23, 2019

Depending on the plugin, you could actually configure it in both instances.

On startup, homebridge first loads all plugins from the node_modules directory, registering the platforms (and, I suppose, accessories):

[3/23/2019, 10:34:17 AM] ---
[3/23/2019, 10:34:17 AM] Loaded plugin: homebridge-ws
[3/23/2019, 10:34:17 AM] Registering platform 'homebridge-ws.WS'
[3/23/2019, 10:34:17 AM] ---
[3/23/2019, 10:34:17 AM] Loaded plugin: homebridge-zp
[3/23/2019, 10:34:17 AM] Registering platform 'homebridge-zp.ZP'
[3/23/2019, 10:34:17 AM] ---

Then it initialises the plugins that are listed under "platforms" or "accessories" in config.json (as well as any dynamic platform plugins).

[3/23/2019, 10:34:17 AM] Loaded config.json with 0 accessories and 2 platforms.
...
[3/23/2019, 10:34:17 AM] [Weather] Initializing WS platform...
...
[3/23/2019, 10:34:18 AM] [Sonos] Initializing ZP platform...

To prevent plugins from being loaded (and dynamic platform plugins from being initialised), use the "plugins" key in config.json to whitelist the plugins you want.

For example, on my production Pi, I run two homebridge services, one for homebridge-hue, on for my other plugins. The corresponding config.json files are:

$ cat .homebridge/config.json 
{
  "bridge": {
    "name": "pi2",
    "username": "CC:22:3D:E3:CD:31",
    "port": 51827,
    "pin": "xxx-xx-xxx"
  },
  "plugins": [
    "homebridge-p1",
    "homebridge-ws",
    "homebridge-zp"
  ],
  "platforms": [
    {
      "platform": "P1"
    },
    {
      "platform": "WS",
      "name": "Weather",
      "openweathermap": {
        "apikey": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
        "locations": ["Amsterdam"]
      }
    },
    {
      "platform": "ZP",
      "name": "Sonos",
      "speakers": true,
      "searchTimeout": 15
    }
  ]
}
$ cat .homebridge-hue/config.json 
{
  "bridge": {
    "name": "pi2 hue",
    "username": "CC:22:3D:E3:CD:30",
    "port": 51826,
    "pin": "xxx-xx-xxx"
  },
  "plugins": [
    "homebridge-hue"
  ],
  "platforms": [
    {
      "platform": "Hue",
      "host": "127.0.0.1",
      "users": {
	"00212EFFFFxxxxxx": "xxxxxxxxxx"
      },
      "sensors": true,
      "hueDimmerRepeat": true,
      "lowBattery": 10,
      "lights": true,
      "groups": false,
      "schedules": true,
      "heartrate": 5
    }
  ]
}

@beatpaul
Copy link

beatpaul commented Apr 4, 2019

Hi!
@ebaauw
is whitelisting working on a mac too?

Is there any way of running 2 instances on a mac as a service? / how to?
( i have the problem that some plugins slow down / crash homebridge if wifi connection to the accessory is lost, so i want to separate these plugins)

Greez paul

@ebaauw
Copy link
Contributor

ebaauw commented Apr 4, 2019

is whitelisting working on a mac too?

Yes.

Is there any way of running 2 instances on a mac as a service?

See the Wiki, https://github.com/nfarina/homebridge/wiki/Install-Homebridge-on-macOS#starting-homebridge-automatically-with-launchd. You would have to create two .plist files, one for each instance, and add -U /Users/user/.homebridge2(or something similar) to one.

@beatpaul
Copy link

beatpaul commented Apr 5, 2019

I created the file, not sure about the -H
Could it be -U ?

Will test it on the weekend...
Thx

@jeylites
Copy link

jeylites commented Apr 5, 2019

I said it before, will say it again Incase it got forgotten.

There’s a well documented docker based homebridge that runs on Raspberry pi, Synology and/ or may be Mac available at OZNU github page.

Some of the good features that I like

  • One can deploy multiple instances quickly without going through the hassle of creating multiple directories.

  • web browse access to the following ;

config directories, instances performance check, individual instances reboot, terminal, installation & un-installation of libraries, etc.

Just google OZNU Homebridge it should show up.

@julien94800
Copy link

Hello,
I had a look on this wiki that is really helpful and complete.
Nevertheless, I did not find any information on how to set up two homebridge substances on a Synology by using docker.
Do you know where I could find this?
Thanks in advance

@mafyata
Copy link

mafyata commented Apr 5, 2019

There are so many videos on youtube , shows step by step.

@jeylites
Copy link

jeylites commented Apr 5, 2019

Currently I’m running 6 instances on my RPI, instance 1-5 does all my daily automation stuff, instance 6 - I use it to run test, r&d stuff. It has been 2 years can’t complain about using this method.

Here’s some information for you

homebridge/docker-homebridge#32

@julien94800
Copy link

Hello again,
Thanks very much for your feedback. Indeed I previously read this but it seems to be easier to apply it on a raspberry rather than on a Synology due to the fact that you have better access. I will try to apply it to the Synology in order to see how I can do
Thanks again

@jeylites
Copy link

jeylites commented Apr 5, 2019

Synology, I’m pretty sure someone worked on something similar. Or at least the setup should be far off compared to RPI. I would raise the question for the sake of discussion.

@ebaauw
Copy link
Contributor

ebaauw commented Apr 5, 2019

I created the file, not sure about the -H
Could it be -U ?

Sorry, my bad. Updated my comment to reflect -U.

@julien94800
Copy link

@jeylites Indeed in docker for synology there is an option to duplicate in one click...
I only had to create an other folder for setting config files on it (and modify settings as names and port) and then modify the path. After this, everything was working perfectly without any effort
Thanks again

@beatpaul
Copy link

beatpaul commented Apr 6, 2019

I created the file, not sure about the -H
Could it be -U ?

Sorry, my bad. Updated my comment to reflect -U.

Working now after some trial and error :) thx for your help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests