Monitor external ip and warn ik changed

Somehow I fell this was asked before…can’t find the topic.

If my external ip changes, I have to make changes in my NAS and in the DNS settings of my internet hosting section.

Is it possible to store the current op address in a variable so it can be monitored and checked?

Thanks!

1 Like

This can do the trick (“watismijnip” is whatismyip in English by the way)
You only have to figure out how to filter the IP address from the HTML info :wink:

Thanks @Peter_Kawa !
Thats a start!

Tried to create that flow, but can’t seem to get that tag to show up (‘response’):

I saved the flow. Ran it a couple of times, but the ‘response’ tag is still not shown. Is that created manually as a variable?

Tried that too, both as a text and number variable, but the ‘value’ doesn’t change:


Schermafbeelding 2023-10-03 om 13.12.12

YW!

Yeah, how would you know… You seem to have used the card for standard flows. There’s a ‘twin’ one, for advanced flows, which has a tag symbol in it, next to the card’s name. Which means, it provides for local tags in flows.

Screenshot from 2023-10-03 22-15-06

So there’s an ‘twin’ card purely for adv. flows, because they didn’t want to break existing standard flows I assume.

1 Like

Hi Ernst,

I couldn’t let it go :woozy_face: :rofl:, finally I found a way to filter out the IP, and now we can send a warning when it has changed!


View of the Homeyscript card with the script, and the [Response] tag from the Logics HTTP GET flow card in the argument field on top:


The script (note: it will fail as soon as the webpage is changed somehow. Then the filter will have to be adjusted again):
change ‘2, 15’ into ‘2, 17’ for IP addresses like xxx.xxx.xxx.xxx (mine is xx.xxx.xxx.xx atm)

var response = args[0];
var myIP = '' + response.split("-")[1].slice(2, 15);
return myIP;



Just for fun:
When you use Better logic variable cards, you can display the IP on an Advanced virtual device like this (without flows):
Screenshot from 2023-10-04 03-31-40

Screenshot from 2023-10-04 04-02-14

1 Like

Haha, I recognise your need to solve things! Bugs you and needs to be solved…

Great help! I will try to get it to work later today.

Thanks again!!

1 Like

Getting there, need a little help… :upside_down_face:

Created/copied your flow:

but the script returns an error. I do see the ‘response’ (called ‘antwoord’ in my case) with the html code and my IP address. So the URL is correct (it is different from your example)

The script I entered is:

Could it be the English to Dutch translation??

Schermafbeelding 2023-10-04 om 12.16.05

Your first console.log is missing a comma ( , ) between your string and variable.

2 Likes

Thank you!

4 decades ago I had to write stuff in Pascal and it wouldn’t compile. Checked the code over and over again. Only thing I missed was the . at the end. It had ‘end’ but it should have been 'end."

It is working now!

1 Like

Update:
A little improvement.
While the filter slice(2, 15) is not flexible, I found a way to ensure the IP only is returned, no matter the number of digits:

var response = args[0];
// A) while the - symbol is (while the returned data doesn't change)
// the first one, and close to the actual IP address,
// we select the string following the - symbol. 
// B) when the IP has less than 12 digits, remove trailing HTML code "</"
var myIP = '' + response.split("-")[1].slice(2).split("<")[0];

console.log('args: ', args[0]);

return myIP;



So recognizable :stuck_out_tongue_winking_eye: I don’t know how many days I’ve spend in total to find out about a missing } . ) or the like. My urge to get it working helps, but oh I have given up on many scripts as well :rofl:

1 Like

Script and flows are working nicely!
Cool!

Thanks again for the solution @Peter_Kawa

1 Like

Thank you as well, as I liked to have this IP check as well, but you just made me do it :stuck_out_tongue_winking_eye: :rofl:

1 Like

I’m getting the wrong IP address when I test the flow. I think I have two things wrong:

  1. The ANY part of starting the flow?
  2. I only have a GET logic, I cannot find a specific HTTP GET logic card. Is there a difference?

Thanks for any help!

Remove that card and test the flow from the card above that one. Does that give the correct ip?

And, have you installed Homey script App?

(Not sure if it is needed. I have it installed)

Indeed the HomeyScript app is needed, due to the HomeyScript flowcard + code to filter out the IP.

  1. Also the 1. card is not needed. You can trigger the flow just how you’d like it. The time trigger seems a logical choice to me :wink:
  2. The logics GET request card = HTTP GET request. It’s the right card.

To check if your IP is determined correctly:
When you add the green [Result] tag to a timeline card, it returns the complete web page in HTML, where your IP should be somewhere between <title> and </title>
(it should be present somewhere in the first 20 lines or so)

I Removed the card [1]. And yes, I have Homey Scripts installed. But I still get the wrong IP.

I’ve removed the [1] card, the time trigger is still there. I added the green [Result] tag to a timeline card, but it doesn’t change the wrong IP.

Test run the flow and than hover your mouse over the tags. Do you see the web page contents?

1 Like

Yes, this is the code:

Well, that is promising!

I guess you have to fiddle with the code to extract the ip correctly. My ip starts with two digits, not 1.