moroen / IKEA-Tradfri-plugin

A Python plugin for Domoticz to controll IKEA Gateway
68 stars 23 forks source link

NotAnIssueButMaybeAFeatureRequest - DHCP: Changing IP address of gateway #138

Open guykes83 opened 2 years ago

guykes83 commented 2 years ago

Firstly, I'd like to thank you for your hard work in this project. I enjoy it everyday!

I'm not sure if this really is an issue, maybe it just depends on the combination of network-devices I use at my home. If so, feel free to close this thread.

In my situation, I use my provider's modem/router combination, and connect the gateway directly to it. Since the provider doesn't allow (nor IKEA) me to set a fixed ip-address, the gateway gets one assigned more or less randomly. So, I'm stuck with DHCP, which is not ideal for automation and availability. This happens whenever I restart the gateway or the router/modem combination, maybe even when I replug a cable.

Of course, when this happens, I'll have to remember to update the config.json file, or half my home's automation will stop working (including some wall buttons, which is not very convenient). In order to do this, first I'll have to identify what's the gateways newly assinged IP-address and then update the config.json file with the new ip-address. Weirdly enough, the range of the newly assigned addresses is always very close, ie. 192.168.0.137, 192.168.0.138 and 192.168.0.139.

To work around this, I created a shell-script that is being run every hour and updates the ip-address in the config.json file:

str=$(arp -a | grep "00:00:00:00:00:00") ip=$(echo $str | awk -v FS="(\(|\))" '{print $2}') sed -i 's/192.168.0.137/'$ip'/g' /home/pi/domoticz/plugins/IKEA-Tradfri/config.json sed -i 's/192.168.0.138/'$ip'/g' /home/pi/domoticz/plugins/IKEA-Tradfri/config.json sed -i 's/192.168.0.139/'$ip'/g' /home/pi/domoticz/plugins/IKEA-Tradfri/config.json

What it does:

Then, what's left are my actual questions:

Many thanks in advance!

moroen commented 2 years ago

Glad you're getting some use of this! :)

It's possible to add a "auto detect the IKEA-gateway" for instance on startup, it's just not high on my personal priority list.

But I'll keep in in mind with the new, totally rewritten plugin, which is inching ever so slowly towards beta status. If you, or someone else want's to implement it in this current version, I'll be more than happy to accept a pull request (but I suspect it might take some work, down to the gocoap library on which py3coap is based...)

Regards, M