Home Home Automation Dynamic IP updates in NodeRED

Dynamic IP updates in NodeRED

Don't worry about changing IP, be happy

Are you stuck in a situation where your WAN IP changes faster than nappies on a year old baby, ruining the access to your network connected drives and other services? Running a premium DNS service with the automatic IP updates can be expensive so it’s time to revisits other options.

Automatic IP updater

Fortunately, you have some options. Not all of them are perfect, but the one I’m going to talk about in this article is free.

How does it work?

The NodeRED flow checks every couple of minutes what is the current IP and if the IP has changed, issues the notification to the relevant device. Using the API I found on the internet, you will be able to send the current WAN IP to any AutoRemote compatible device (Android, Windows PC). The free allowance of 1000 calls a day makes possible to monitor the IP changes every 2 min without additional payments. BONUS: no account creation required to use the API.

NodeRED Flow: Current IP

The “Insert” node comes with repeat setting, which I can use to query the API every X minutes. You could set this to trigger as often as 2 min without hitting the 1000/day limit. I think there is very little reason for the excessive calls so 5-10 min interval is more than enough.

To make the API call, I’m simply making HTTP GET request to:

http://api.db-ip.com/v2/free/self/ipAddress

The response is your IP address which is saved as a global variable with global.set("CurrentIP", msg.payload). I want to set this value only if the device was online, so checking if the msg.statusCode === 200 is a good idea to see if the request has been sent correctly.

I don’t want to spam this message back to my AutoRemote devices unless the value changes, so I placed the RBE node that passes the value when the value changes.

Sending AutoRemote

I send a lot of information via AutoRemote so it makes sense to automate the process somehow. I created a subflow that requires the following information to make the successful request:

  • msg.message – message to pass
  • msg.timeout – TTL
  • msg.device – device name

The message sent to the device contains the prefix currentip and the command with xxx.xxx.xxx.xxx IP: currentip=:=xxx.xxx.xxx.xxx this way I can easily use it in Tasker to set the new IP as a variable

Subflow

AutoRemote is essentially making a request via Gooogle API to the registered mobile device or a computer running EventGhost. You will need an AR key associated with your device. I’m my example I used the credentials system I designed for NodeRED. The values are stored as global variables and can be pulled by setting the correct device.

//set up AR response
 var device = "AR_"+ msg.device;
 var message = msg.message;
 var timeout = msg.timeout;
 var key = global.get(device);
 //send AR response
 if(timeout === null || timeout === undefined){
     timeout = 10;
 }
 if(message === null || message === undefined){
     message = "no message set";
 }
 var url = "https://autoremotejoaomgcd.appspot.com/sendmessage?key=" + key + "&message=" + message + "&ttl="+ timeout;
 msg.url = url;
 msg.feedback = "Messgage send to " + device + ": " + message;
 return msg;

That script is passed to the HTTP POST and executed. I have added a msg.feedback in output in case you ever want to see what message has been sent. You can reuse this subflow in every flow that requires the AR message to be submitted.

Using the new IP in Tasker and EventGhost

Now, that the IP has been updated and sent to the preferred devices, I will show you how to update the designated variable with the new value. I will use Tasker to do this on Android and EventGhost to store the IP as a variable in EventGhost.

Tasker: My IP

The profile will respond to an intercepted message currentip and update the variable of your choice %CURRENTIP (click here to learn why I use upper case for these).

TASKER PROFILE: DIC IP Update
Profile: DIC IP Update 
	Event: AutoRemote [ Configuration:currentip ]
Enter: DIC Update IP 
	A1: Variable Set [ Name:%CURRENTIP To:%arcomm ]

The Tasker’s profile is supers simple and once your variable is updated you can use it to send HTTP request back to your home server.

EventGhost: My IP

In a similar manner, the intercepted message by EventGhost can be set as a variable in the EventGhost itself. You will be able to pass this data in your scripts to execute other commands and send the web requests.

This is how to extract the IP from the message and save it as a variable:

IP = eg.event.payload.arcomm
setattr(eg.globals, "CurrentIP", IP)

print IP

And this is how you recall the global variable and use it in a python script.

IP = getattr(eg.globals, "CurrentIP")

print IP

Conclusion

Even if your IP changes frequently, you can keep track of that with this project and make sure your systems always have the up to date data. The best part of it – it’s free! Let me know how often your IP changes! If you want to learn more about Tasker use this portal, alternatively I have a very good 7 part tutorial to teach you more about NodeRED. Does your ISP come with serious rules about IP assignment and lease times? Use this Reddit thread to leave me a message.

Project Download

Download project files here. Bear in mind that Patreon supporters have early access to project files and videos.

PayPal

Nothing says "Thank you" better than keeping my coffee jar topped up!

Patreon

Support me on Patreon and get an early access to tutorial files and videos.

image/svg+xml

Bitcoin (BTC)

Use this QR to keep me caffeinated in style with crypto-currency

Smart Ideas with

Automate your space in with these ecosystems and integrate it with other automation services

Learn NodeRED

NodeRED for beginners: 1. Why do you need a NodeRED server?

0
To server or not to server? That's a very silly question!

Best Automation Projects

ESP8266 WIFI lights under $5

0
Your Sonoff device can't do this!

Free wireless doorbell (Amazon Dash button hack)

0
The most terrifying situation I can imagine* is missing a parcel

New Amazon Dash Buttons

0
You can teach new buttons old tricks!

ESP8266 ceiling light – demo

0
Testing the ESP8266 as a WIFI light controller

Try Tasker and Raspberry Pi for your home automation needs!

0
Raspberry Pi can help you with your Tasker profiles

Smart Home

How to make Sonoff ZB Mini and ZigBee2MQTT work together

0
It's time to make Sonoff ZB Mini and ZigBee2MQTT work together!

Sonoff ZBMINI is in town!

0
ITEAD released a new product - Sonoff ZB Mini - a smarter twin brother of Sonoff Mini!

Testing 9 external antennas with CC2531 ZigBee coordinator

0
I have tested the range and the link quality of 9 external antennas with CC2531!

I have infinite buttons thanks to Aqara Opple

0
Gaming on Switch meets IoT - can you play games on Aqara Opple? Apparently you can! This and more uses of the connected wall switch

Smart lights won’t save you money

0
It's pretty clear how much power a smart light draws when turned on, but have you ever wonder how much do you pay to have it connected 24/7?