Yes you can use dyndns like services, but I just wanted to know when it changed.
For some reason I ended op adding this script as a cronjob, or can be called from within Domoticz with os.execute.
It will send you a Telegram message (pre requirement is that you have telegrambot working) with the NEW IP message.
You will also need to add a user variable in Domoticz to store the WAN IP address.
I borrowed some code from the world wide internet to obtain the WAN IP and added the Domoticz parts using the great wiki pages.
Code: Select all
#!/bin/bash
DomoticzIP="192.*.*.*" # Your Domoticz IP
DomoticzPort="8080" # Your Domoticz PORT
# Info for Telegrambot
TelegramUrl="https://api.telegram.org"
TelegramToken="bot*********:***********************************"
token="*********:***********************************"" # A yes, this still needs to be fixed..
# it is the same as TelegramToken without 'bot' ...
# Yes I know scripts can be cleaned up a bit, yes yes
TelegramChatId="*********" # you get the picture what needs to be here
# Create a USER VARIABLE as STRING in DOMOTICZ and write down the number and name
WAN_IP_VAR=*** # Domoticz ID of Uservariable
WAN_IP_NAME="THE_NAME_IN_DOMOTICZ" # Domoticz NAME of Uservariable
CURRENT_IP=$(curl -s http://whatismijnip.nl |cut -d " " -f 5) # Get the current public IP
#Get the current KNOWN IP from DOMOTICZ
DOMOTICZ_WAN=$(curl -s 'http://'$DomoticzIP':'$DomoticzPort'/json.htm?type=command¶m=getuservariable&idx='$WAN_IP_VAR'' | jq '.result[].Value' | cut -f1 -d" " | sed 's/\"//g')
#Check DOMOTICZ for currently KNOWN IP address
if [ $DOMOTICZ_WAN ]; then
KNOWN_IP=$DOMOTICZ_WAN
else
KNOWN_IP=
fi
#See if the IP has changed
if [ "$CURRENT_IP" != "$KNOWN_IP" ]; then
# UPDATE DOMOTICZ VARIABLE if the IP was different
curl -s 'http://'$DomoticzIP':'$DomoticzPort'/json.htm?type=command¶m=updateuservariable&vname='$WAN_IP_NAME'&vtype=2&vvalue='$CURRENT_IP''
#Generating string to send via Telegram.
MESSAGE="text=Domoticz: Current IP Address Changed to: "
TOTAL=$MESSAGE$CURRENT_IP # Concatenation of both messages MESSAGE + IP
curl --data chat_id=$TelegramChatId --data-urlencode "$TOTAL" ''$TelegramUrl'/bot'$token'/sendMessage'
fi
Code: Select all
curl --data chat_id=$TelegramChatId --data-urlencode "$TOTAL" ''$TelegramUrl'/'$TelegramToken'/sendMessage'