Homebridge Not Accessible

mlavio829

Cadet
Joined
Mar 12, 2022
Messages
3
Hello,
I'm trying to configure Homebridge in TrueNAS Scale via the TrueCharts incubator.
While the app works and if I use the shell to get to ping a website on the internet, none of my local devices can connect to the Homebridge.
I notice Homebridge is getting the ip: 172.16.1.100, however my local IP addresses are in the 10.0.0.0 range.
Has anyone come across a way to fix this?
I've tried Host-Networking but there isn't much documentation that I can find to help me set this up.

Any ideas?

Thanks
Michael
 

FrostyCat

Explorer
Joined
Jan 4, 2022
Messages
79
I'm not using Homebridge myself, but, running apps in Kubernetes is different than running them directly. Apps will get a Kubernetes specific IP address as you correclty noticed and then, at deployment time you'll have to expose services listening on this IP address to the outside work via either a load balancer, or an ingress.

The simplest way is via a load balancer. The UI will allow you to select this via the "Simple" option.

Now, let's check what services Homebridge deploys, I'm assuming you kept the name and Homebridge is running in the ix-homebridge namespace. Use the UI shell option to run the command below.
Please run this command for me k3s kubectl -n ix-homebridge get svc and paste the output in a comment.
 

FrostyCat

Explorer
Joined
Jan 4, 2022
Messages
79
Hi @FrostyCat, I get an error: /bin/sh: k3s: not found
When you say loadblancer, how does one setup a loadbalancer?
You will need to use the shell via System Settings / Shell to run the command I posted above, not the pod shell, sorry, I should've been more explicit.

Load balancers are notmally setup for you automatically when launching an app and selecting the service type to be either Simple or LoadBalancer. This is the best option to have your pod exposed on your host, and on your network.

What I'm trying to determine here is if all the Homebridge services are exposed as LoadBalancer
 

mlavio829

Cadet
Joined
Mar 12, 2022
Messages
3
Ah ok!
Thank you for letting me know where to try it.
I tried it however I then got this error: No resources found in ix-homebridge namespace.
the app is named ix-homebridge.
 

FrostyCat

Explorer
Joined
Jan 4, 2022
Messages
79
Ok, let's step back a bit.

App namespaces are normally named ix-APPNAME so if your ap named is homebridge then the namespace would be ix-homebridge, so replace the namespace name with the proper one and try again.

A second method would be to run:
k3s kubectl get ns
and look for the correct namespace.
 
Joined
Mar 21, 2022
Messages
1
I'm not running it as a container, but in a separate Ubuntu VM with Scrypted. I noticed that by default the virtual interfaces for the VMs are set to not allow multicast traffic, which broke my HAOS VM as well and everything Homekit related. I had to manually run:
Code:
ip link set dev macvtap0 allmulticast on
ip link set dev macvtap1 allmulticast on

You might need to manually set the container's interface to allow multicast traffic. It should allow it on your actual NICs, but none of the virtualized ones.
 

AirborneTrooper

Contributor
Joined
Jun 20, 2014
Messages
148
I'm not using Homebridge myself, but, running apps in Kubernetes is different than running them directly. Apps will get a Kubernetes specific IP address as you correclty noticed and then, at deployment time you'll have to expose services listening on this IP address to the outside work via either a load balancer, or an ingress.

The simplest way is via a load balancer. The UI will allow you to select this via the "Simple" option.

Now, let's check what services Homebridge deploys, I'm assuming you kept the name and Homebridge is running in the ix-homebridge namespace. Use the UI shell option to run the command below.
Please run this command for me k3s kubectl -n ix-homebridge get svc and paste the output in a comment.
I just switched to Scale and trying to get Homebridge working and discovered this thread. Here's the results from the command for me:

root@truenas[~]# k3s kubectl -n ix-homebridge get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
homebridge LoadBalancer 172.18.33.99 172.16.1.50 8581:57302/TCP 42m
 
Joined
Jun 13, 2022
Messages
1
Did anyone here figure out how to get this to work?
I have it working, but it won't start unless I turn off my timemachine share, then turn off mdns in network settings, then start the app. After that I can turn mdns back on and enable my timemachine share to get everything running at once. I have to do this any time I reboot the server. Strange part is I can restart homebridge all I want after that and it starts up fine.

If you don't have a timemachine share, you could probably just disable mdns in network settings and it would start. Let me know if you want me to share any settings.

I want to file a bug about this but I'm not sure where the issue lies, with the app/chart or truenas.
 
Joined
Dec 7, 2016
Messages
2
I have it working, but it won't start unless I turn off my timemachine share, then turn off mdns in network settings, then start the app. After that I can turn mdns back on and enable my timemachine share to get everything running at once. I have to do this any time I reboot the server. Strange part is I can restart homebridge all I want after that and it starts up fine.

If you don't have a timemachine share, you could probably just disable mdns in network settings and it would start. Let me know if you want me to share any settings.

I want to file a bug about this but I'm not sure where the issue lies, with the app/chart or truenas.
I got it working. Think I just had something wrong during configuration. I started from scratch and it worked just fine. Didn't touch mdns.
 

aekt

Dabbler
Joined
Jul 22, 2022
Messages
13
I have registered an account to provide solution to this problem.

This solution allowed the usage of mDNS to remain enabled without the need to set Homebridge app to be on host network, while allow it to be registered with Home app

The problem with Homebridge being inaccessible is due to two issues:

1. Homebridge cannot broadcast itself to the outside
container is not allowed to advertise its own HAP mDNS record to the host.

TrueNAS SCALE uses Avahi as its mDNS stack.
if container is not allowed to advertise itself, then we just have to add the mDNS entry into it.

2. Homebridge cannot respond to the incoming verification Homekit request
container broadcast port is not exposed outside of the container. To fix this, we simply create a k8s nodeport service to remedy this situation.

This bring us to the following script below:

Code:
#!/bin/bash
set -euo pipefail
APP_NAME=$1
NAMESPACE=ix-${APP_NAME}
POD_NAME=$(k3s kubectl get po -n ix-${APP_NAME} -n ${NAMESPACE} -o name | grep "pod/${APP_NAME}" | cut -d '/' -f 2)
MAIN_CONFIG=$(k3s kubectl exec -it -n ${NAMESPACE} ${POD_NAME} -c ${APP_NAME} -- cat /homebridge/config.json)
BRIDGE_NAME=$(echo "${MAIN_CONFIG}" | jq -r .bridge.name)
BRIDGE_MAC=$(echo "${MAIN_CONFIG}" | jq -r .bridge.username)
BRIDGE_BROADCAST_PORT=$(echo "${MAIN_CONFIG}" | jq -r .bridge.port)
OCCUPIED_PORT=$(k3s kubectl get svc --all-namespaces -o go-template='{{range .items}}{{range.spec.ports}}{{if .nodePort}}{{.nodePort}}{{"\n"}}{{end}}{{end}}{{end}}' | grep ${BRIDGE_BROADCAST_PORT})
if [ "${OCCUPIED_PORT}" != "" ]; then
    echo "port ${OCCUPIED_PORT} is already occupied, please change port specified before retrying.."
    exit 1
fi
ACCESSORY_CONFIG=$(k3s kubectl exec -it -n ${NAMESPACE} ${POD_NAME} -c ${APP_NAME} -- cat /homebridge/persist/AccessoryInfo.${BRIDGE_MAC//:/}.json)
BRIDGE_SETUP_ID=$(echo "${ACCESSORY_CONFIG}" | jq -r .setupID)
BRIDGE_CATEGORY=$(echo "${ACCESSORY_CONFIG}" | jq -r .category)
# creating avahi servicec entry to allow pod to react to mDNS request
cat <<EOF > "/etc/avahi/services/${APP_NAME}.service"
<service-group>
  <name>${BRIDGE_NAME}</name>
  <service>
    <type>_hap._tcp</type>
    <port>${BRIDGE_BROADCAST_PORT}</port>
    <txt-record>md=${BRIDGE_NAME}</txt-record>
    <txt-record>pv=1.0</txt-record>
    <txt-record>id=${BRIDGE_MAC}</txt-record>
    <!-- Current configuration number -->
    <txt-record>c#=2</txt-record>
    <txt-record>ci=${BRIDGE_CATEGORY}</txt-record>
    <txt-record>s#=1</txt-record>
    <txt-record>ff=0</txt-record>
    <txt-record>sf=1</txt-record>
    <txt-record>sh=$(echo -n ${BRIDGE_SETUP_ID}${BRIDGE_MAC} | openssl dgst -binary -sha512 | head -c 4 | base64)</txt-record>
  </service>
</service-group>
EOF
# creating service to allow outside to reach into the pod
cat <<EOF | k3s kubectl apply -f -
apiVersion: v1
kind: Service
metadata:
  name: ${APP_NAME}-exposed
  namespace: ${NAMESPACE}
  labels:
    app: ${APP_NAME}
spec:
  type: NodePort
  selector:
    app.kubernetes.io/instance: ${APP_NAME}
  ports:
    - port: ${BRIDGE_BROADCAST_PORT}
      nodePort: ${BRIDGE_BROADCAST_PORT}
EOF

save the script to a file called homebridge-fix.sh
give it execute permission via
Code:
chmod +x homebridge-fix.sh

Execute the script by providing Homebridge App Name (the name used when you created the Homebridge app) as the only parameter like so
Code:
./homebridge-fix.sh <homebridge_app_name>

use
Code:
service avahi-daemon status

to verify Avahi has picked up the mDNS entry before attempting to register bridge with iOS Home app (shouldn't take more than 1 min)

now you can add any device to your homebridge.
 

aekt

Dabbler
Joined
Jul 22, 2022
Messages
13
minor correction:
in order for device to respond correctly, change the NodePort part in script to LoadBalancer. this will automatically attach the port to host ip.

you can verify this via

Code:
k3s kubectl get svc --all-namespaces


which should show that external IP is reflected as your TrueNAS ip.
without this, all accessories will show as "not responding"
 

Mixel

Explorer
Joined
Jan 11, 2014
Messages
50
would that in generic work for any pod that needs mDNS (home assistant, zigbee2mqtt)?
 

aekt

Dabbler
Joined
Jul 22, 2022
Messages
13
would that in generic work for any pod that needs mDNS (home assistant, zigbee2mqtt)?
you will need to modify the script a bit to suit the need for other container pod

This line made assumption on what pod name of the app will be, should be pretty generic
POD_NAME=$(k3s kubectl get po -n ix-${APP_NAME} -n ${NAMESPACE} -o name | grep "pod/${APP_NAME}" | cut -d '/' -f 2)

This line fetch the configuration content of the homebridge config file
MAIN_CONFIG=$(k3s kubectl exec -it -n ${NAMESPACE} ${POD_NAME} -c ${APP_NAME} -- cat /homebridge/config.json)

These line fetch individual attribute needed for avahi configuration. The only one that can be named whatever you want is "BRIDGE_NAME"
BRIDGE_NAME=$(echo "${MAIN_CONFIG}" | jq -r .bridge.name)
BRIDGE_MAC=$(echo "${MAIN_CONFIG}" | jq -r .bridge.username)
BRIDGE_BROADCAST_PORT=$(echo "${MAIN_CONFIG}" | jq -r .bridge.port)

if you modified the necessary line to fit the need of other container pod, i'd imagine it will work for them too.

Alternatively, you can also mount avahi folder on the TrueNAS main system to the avahi folder of the container pod, that should also allow broadcasting to be successful - assuming your pod can be reached via <TrueNAS-IP>:<listening_port>
 

Mixel

Explorer
Joined
Jan 11, 2014
Messages
50
you will need to modify the script a bit to suit the need for other container pod

This line made assumption on what pod name of the app will be, should be pretty generic


This line fetch the configuration content of the homebridge config file


These line fetch individual attribute needed for avahi configuration. The only one that can be named whatever you want is "BRIDGE_NAME"


if you modified the necessary line to fit the need of other container pod, i'd imagine it will work for them too.

Alternatively, you can also mount avahi folder on the TrueNAS main system to the avahi folder of the container pod, that should also allow broadcasting to be successful - assuming your pod can be reached via <TrueNAS-IP>:<listening_port>
Wow thats fantastic. Especially since I got Truecharts host networking to work, but that gave me other issues. As they warn for, basically.

Wonder if @truecharts would be willing to add your script into the installer scripting of theirs for home-assistant, zigbee2mqtt and other apps that need avahi to be able to connect to the host network.
 

simdim

Explorer
Joined
Mar 12, 2019
Messages
75
This post is fantastic news, going to start moving my homebridge to TrueNas Scale ...
Couple of issues remain ( maybe I need separate thread ):
1. On restart of Homebridge I am getting:

[Homebridge 9685 5B84] The selected advertiser, "avahi", isn't available on this platform. Reverting to "bonjour-hap"
[11/2/2022, 10:58:03 AM] Homebridge v1.5.1 (HAP v0.10.4) (Homebridge 9685) is running on port 53296.

2. TrueCharts app comes as Homebridge 1.4 , after in app upgrade to 1.5.1 it runs as 1.5.1 until container restart when it reverts to 1.4
Sounds like I need to sharpen my k8 skills for that

3. Some Homebridge plugins (Camera UI) require separate exposed ports, how do I add them to the TrueCharts app?
 

aekt

Dabbler
Joined
Jul 22, 2022
Messages
13
This post is fantastic news, going to start moving my homebridge to TrueNas Scale ...
Couple of issues remain ( maybe I need separate thread ):
1. On restart of Homebridge I am getting:

[Homebridge 9685 5B84] The selected advertiser, "avahi", isn't available on this platform. Reverting to "bonjour-hap"
[11/2/2022, 10:58:03 AM] Homebridge v1.5.1 (HAP v0.10.4) (Homebridge 9685) is running on port 53296.

2. TrueCharts app comes as Homebridge 1.4 , after in app upgrade to 1.5.1 it runs as 1.5.1 until container restart when it reverts to 1.4
Sounds like I need to sharpen my k8 skills for that

3. Some Homebridge plugins (Camera UI) require separate exposed ports, how do I add them to the TrueCharts app?
for the issues you are getting.
1.
i would recommend moving to CIAO if possible within the Homebridge container.
the script only fixes host to container pathway, container itself can use anything it wants

if you are using avahi mounting method (not used here), you will be tied to avahi without other options

2.
this is expected behavior as homebridge binary is embedded within the docker image used. This is how it was designed and something only updating the TrueChart App image will fix.

3.
exposed port is not friendly with Kubernetes as it involved adding new Service (NodePort / LoadBalancer) that points to the exposed port, and add new entry into Avahi config on the TrueNAS host config.

Overall, there are limitation and advance config needed when using kubernetes with Homebridge / Home Assistant / Scrypted etc due to the nature of port exposure. If you want a more "stable" experience, I would recommend using Virtualization with homebridge-vm-image.iso (you can download this from homebridge official repository), as it will get its own LAN IP via Virt NIC. Just remember to set BIOS as legacy.
 
Top