Handling changing IP addresses when router reboots

I have setup multiple lamps and sensors in my Home Assistant configuration and everything works fine. However, I want to know how to best handle the following scenario.

Suppose there is a problem with my router or a power cut happens, and my router is rebooted. In this case there is a possibility that the multiple IoT devices connected to my network get new IP address assigned to them. If these new IP addresses are different from ones I used in the configuration.yaml setup, I will have to update the file to handle this.

I was wondering if there an automatic/graceful way of handling this, rather than having to manually update all the addresses? Any help will be appreciated.
I looked at a few of the example configuration.yaml files under the Examples section. I see most of them have hardcoded IP addresses for sensors, lights etc. How do they ensure these are not changed to new addresses if/when the router reboots?

thank you.

1 Like

You should be able to do that from inside your router configuration. There should be an option for “address reservation”. There you can set a fixed ip address to the mac address of your device.

Sander

2 Likes

@sanders my router doesn’t show any option to reserve DHCP. is there any alternative method to do this?

What is the make and model?

My router doesn’t reserve dhcp either, but it does allow to specify a range of addresses that it won’t allocate, so these can be used for static IP addresses.

I have to set up static IP addresses for the HA machine, and anything else that is likely to be addressed from configuration files, such as ip cameras.

its from my internet provider its called “Mobily Elife”

If you’re only looking for your rpi to have a fixed ip address I guess there are a lot guides explaining how to set a static ip address. There are, however devices that don’t have that option… So then you’re stuck I guess.

Just a thought: would increasing the dhcp lease time ensure a device always gets the same IP address?

my HA doesn’t discover chrome cast I have to mention my chrome cast IP address in HA configuration.yaml. if I’m not wrong we can not set static IP for chrome cast

I don’t have chrome cast so I can’t help there.

I believe items like this generally run a service discovery protocol like mDNS, so you can just use a device name, rather than the address, but I don’t know the details about using this in HA.

for devices like a RPI there is the option to set a static IP.
i can imagine that there are routers that cant have devices with a static IP.
so that part of devices is covered.
but then there is the part of devices that need a DHCP IP.
there are routers (like mine) that have the option to give the same ip address every time.

most of the time that setting is a little hard to find.
you can look for it this way:

  • in the router settings look for the list of devices that have become a DHCP ip address.
  • look if there is a way to edit the settings from 1 of those devices.
  • if so you probably can change the name from the device there.
  • but there is also often an option there that looks like “give this device the same IP every time”

if you found that option then your device will get the same DHCP ip every time.

I found this video for the Mobily eLife which shows a DHCP section and something called “Conditional DHCP Rules”, which sounds like the right area but the text in the video appears to be Arabic so I can’t tell what he’s doing. It’s a video on setting up the router so it might help:

Hi @ReneTode

could not find any description.
I am using also homeassistant with raspberry pi and my router does not support static ips. And there fore I need to set it on the pi level (hassbian).

Is there somewehere a documentaiton on how this is achieved?

Kr, Marvin

Here’s some fairly straightforward instructions:

https://www.modmypi.com/blog/how-to-give-your-raspberry-pi-a-static-ip-address-update

3 Likes

Thanks. I will give it a try and feedback the results

@rpitera Proposal worked fine!

2 Likes