Check external IP address and send a message with Telegram on changes
What This Flow Does
This Node-RED flow periodically checks your external IP address and sends a Telegram message if it changes.
Every 30 minutes:
-
It checks your current external IP address.
-
If the IP is different from the last recorded one, it:
-
Saves the new IP.
-
Sends a Telegram message to notify you.
-
This is useful if your internet provider gives you a dynamic IP and you want to track when it changes—ideal for home servers or remote access setups. Here's how it works, step by step:
1. Inject Node: "Check every 30 minutes"
Function: Triggers the flow every 30 minutes.
-
Also runs once at startup after a 5-second delay.
-
Sends the current timestamp as
msg.payload
.
2. HTTP Request: "Get external IP"
Function: Makes a GET request to https://api.ipify.org
.
-
This service returns your current public (external) IP address in plain text.
-
The response becomes the new
msg.payload
.
3. Function Node: "Check IP address change"
Function: Compares the new IP address to the previously stored one.
-
Retrieves the last known IP from Node-RED's flow memory (
flow.get('previousIp')
). -
If the new IP is different, it:
-
Stores the new IP (
flow.set('previousIp', currentIp)
). -
Sets a message like
Nieuw extern IP-adres gedetecteerd: <new IP>
. -
Passes this message along.
-
-
If the IP hasn't changed, it stops (returns
null
).
// Haal het huidige IP-adres op uit de payload
const currentIp = msg.payload;
// Haal het vorige IP-adres op uit de flow context
const previousIp = flow.get('previousIp') || '';
// Vergelijk het huidige IP met het vorige IP
if (currentIp !== previousIp) {
// Bewaar het nieuwe IP in de flow context
flow.set('previousIp', currentIp);
// Stuur een bericht met het nieuwe IP
msg.payload = 'Nieuw extern IP-adres gedetecteerd: ' + currentIp;
return msg;
} else {
// IP is niet veranderd, stop de flow
return null;
}
4. Telegram Sender
Function: Sends the notification via your configured Telegram bot if there's a new IP address.
5. Telegram Bot Configuration
-
Connected to a bot named
mybot
. -
Sends messages to a specified user or chat ID.