Check external IP address and send a message with Telegram on changes

Screenshot_20250528_110311.png

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:

  1. It checks your current external IP address.

  2. 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.

Screenshot_20250528_110622.png


2. HTTP Request: "Get external IP"

Function: Makes a GET request to https://api.ipify.org.

Screenshot_20250528_110555.png


3. Function Node: "Check IP address change"

Function: Compares the new IP address to the previously stored one.

Screenshot_20250528_110651.png

// 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.

Screenshot_20250528_110722.png


5. Telegram Bot Configuration


Revisie #5
Gemaakt: 28 mei 2025 08:57:36 door Gert
Bijgewerkt: 28 mei 2025 09:13:13 door Gert