Home Assistant - How I ditched the VM and embraced The Container

Something that I learned is that macvlan resets with reboots. I modified my script to delete the old macvlan and the shim and recreate them. Then set it up with a post init script so it runs when truenas restarts.

Please be careful with suggestions from ChatGPT, it may hallucinate commands that will break your setup.

2 Likes

@tannisroot I’m going to be trying out a custom YAML setup for HA soon. In the network section, does it matter if existing network devices are in the range of the 192.168.0.240/29 subnet? And is the .241 host address the address of your TrueNAS server?

The biggest issue I ran into using this was mdns discovery didnt work because mdns is tied to the top level IP on the box. I use time machine so disabling mdns wasnt an option. I have my fingers crossed the mdns avahi thing is going to get fixed for gold eye.

It does, you should change the DHCP lease upper range on your router to max out at 239 (including).
The .241 is the address of the TrueNAS server yes, I use that for communicating with local services like UPS NUT.

1 Like

I’m getting a variety of errors when trying to set this up, attempting to work through them one at a time. When running the macvlan commands on the host they work until the last line, which throws “Error: Invalid prefix for given prefix length” which google tells me is probably netmask related. Here are my commands:

ip link add ha-host-shim link br0 type macvlan mode bridge
ip addr add 192.168.0.250/32 dev ha-host-shim
ip link set ha-host-shim up
ip route add 192.168.0.249/29 dev ha-host-shim

My primary home network is 192.168.0.0, my truenas server is 192.168.0.250. I do have a bridge setup as br0, the address for br0 is 192.168.0.250/24. Does the /24 netmask make sense there?

I was going to atttempt to setup HA with address 192.168.0.251

This is because you modified the original IP values.
In my example, the network is specified at 241/29, which has a range of 240-248, with 241 being the host and 242-246 being usable by other clients.
You set it to 249/29, which ends beyond the 8-bit range of the block (0-255).

Ah dang. The online cidr IP calculators showed your range as 240-247 and mine as 248-255 so I thought it might work. I’ll test if /30 works or if I need to lower my IP ranges closer to yours.
Thanks

@tannisroot You have been a big help, thank you. I have Home Assistant up and running in a macvlan and device discovery works. My remaining issue is connecting it to mosquitto. I have the z2mqtt and mosquitto apps from the app catalog installed and have had those working for a while. I can connect HA to mqtt when it is on the truenas network, but not now that it is in the macvlan. You mentioned earlier you are also using z2m and mosquitto, how do you have it setup to communicate?

Edit: after doing some additional reading I may understand what to try tomorrow. I believe my shim commands might be incorrect. This page explains the issue well.
https://blog.oddbit.com/post/2018-03-12-using-docker-macvlan-networks/

It sounds like you’re running into the typical issue with Docker’s Macvlan network where containers on different networks can’t communicate easily. Since you’re using Home Assistant in a Macvlan, it might not be able to access the Mosquitto broker on the same network.

If you haven’t already, check your shim commands for setting up the network bridge between the br0 interface and your Docker containers. The OddBit guide explains the issue and provides a good approach to fixing this.

In my case, I solved it by either:

  1. Using network_mode: host for Home Assistant to allow it to access the local network (if you’re using Docker in Proxmox).
  2. Ensure your Macvlan network config includes proper routing between containers.

Let me know if that helps, or if you’d like more details on my setup!

1 Like

Got it working now using the shim setup. What I didn’t initially understand was that the .241 address is more of an ‘intermediate’ IP between the MACVLAN and host and not the actual host IP. Go figures, things work correctly when you actually follow directions. :sweat_smile:

1 Like