Spring naar de hoofdinhoud

Check external IP address and send a message throug Telegram when it has changed

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.

  • 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).


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

  • Sends messages to a specified user or chat ID.