HomeHome AutomationDynamic 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 with BTC: 1FwFqqh71mUTENcRe9q4s9AWFgoc8BA9ZU

Smart Ideas with

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

client-image
client-image
client-image
client-image
client-image
client-image
client-image
client-image
client-image

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

Tuya SDK for beginners: Intro to Tuya Cloud API

0
Working with Tuya Cloud API. A guide to Cloud automation for beginners, get started with REST!

NEST your old thermostat under $5

0
Nest-ing up your older thermostat under $5

Nora – Google Assistant in NodeRED

0
Integrate Google Assistant with NodeRED thanks to Nora - NodeRED home automation

DIY Smart Washing Machine – for about 15 bucks!

0
Learn how to add washing machine notifications to your Google Home on the cheap

Sonoff Zigbee Bridge – review

0
Sonoff line up will soon include Sonoff Zigbee Bridge and more Zigbee sensors - here is the first look

Smart Home

We’ve seen this before: SwitchBot K10+ PRO

0
This is an odd one. Building on the success of SwitchBot K10+ they released SwitchBot K10+ PRO - but is the experience actually better?

Is this the smart panel we have waited for?

0
ITEAD has released a new smart panel: Sonoff NSPanel Pro 120 - have they learned the lesson from the terrible launch of the original Pro? Let's see what's new.

Aqara FP1E detects motionless humans

0
This isn't exactly a new device, it's an interaction of the original Aqara presence sensor. Aqara FP1E brings Matter, ZigBee and new triggers to your smart home

SwitchBot S10: cleaning re-imagined!

0
SwitchBot S10 promises unattended vacuuming and mopping so you can focus on things you love and care for. Does it deliver?

Sonoff for households and gardens

0
ITEAD released two ZigBee devices to manage water in your household and gardens. Now you can monitor the flow and dispense water with Sonoff SWV and prevent water damage using the Sonoff Water Leak sensor with a twist.