Check public ip

Hello everyone, is there a way to make a routine that will consult the public ip and save the value in a variable so that it can display it on a dashboard or send it by push Thanks a lot

the hubitat doesnt know your public ip it is not a router.. in addition, you can have more than one public ip depending on your network configuration.. Take a look at your router and see if has ddns (dynamic dns) or configure a vpn to get to your private ip of your hub.

It would be to wget a page like https://ifconfig.co/ and see if the answer can be saved in some way.

Well, I felt like seeing if I could throw something together to do this, I don't know groovy, so this was a good simple one to try out.

So here you go, here's a driver that will do it, uses an AWS based URL to poll for the IP. Select your poll interval and it will go on its merry way and regularly poll for your IP. Add an attribute tile on your dashboard and select the attribute created by the device.

The caveat is, I'm not a developer and so I don't promise it's perfect. It's not really complex, so not sure how it could break, but it's certainly possible.

4 Likes

I have a driver in HPM(Hubitat Package Manager) to do this called PublicIPTracker.

2 Likes

It works just I wanted, thank you very much.

The application works perfect, but there is not, or I can't find a way to use the ip value in a rule or send it to a notification, or put it on the board. I suspect that due to the lack of attributes in the driver. it is right?

I made some changes to your device handler. let me know if you want to integrate.

I declared the attributes you use so that you can put them on a dashboard.

The design change is so that you can be notified when your ip changes. Unfortantely hubitat does not allow sending messages or notifications from a device handler, which we want so that we can display the attributes (vs an app).

So my solution was to track the current and last ip, and set an attribute called ipchanged to true or false so that you can check when this attribute changes to true in a rule (rule machine) and send yourself a notification from there.

Here is the modified code.

thanks

3 Likes

it works perfect and I can use the value as I needed, thank you very much for your time.

1 Like

here is what you have to do to declare the variables and write a rule to use it..

2 Likes

Just thowing this out here if it can be useful,
https://www.ipify.org/

thats what it uses.. the point is to get notified when it changes especially if you are not using dynamic dns

@kahn-hubitat added that in Thanks.

1 Like

Thank you very much, that if it ends up working, thank you all.

Slight change.. just noticed you need to add the if and runin to schedule to the update fx otherwise when you hit submit on changes it is not saved unless you manually rerun initialize.

Any reason why you just don't use a dynamic DNS service, like DuckDNS? Makes like pretty simple...

i do, but i also have had it fail previously and if the house is empty no way to know the ip easily.

my other house has static ips so no issue there.

1 Like

Thanks...I actually meant the OP...I assumed you would have a good reason for doing what you do. The only thing I've seen you do on this forum that doesn't make any sense is answering all my dumb questions. :wink:

2 Likes

@kahn-hubitat. Thanks thought I had put that in there, had it locally on the non-HPM one but not in github one.

An app that will integrate duckedns in hubitat and in addition to the ip will update duckedns would be good. Cheers

1 Like