Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WAN IP[Question] #308

Closed
sygys opened this issue Oct 2, 2023 · 10 comments
Closed

WAN IP[Question] #308

sygys opened this issue Oct 2, 2023 · 10 comments
Labels
question Further information is requested stale

Comments

@sygys
Copy link

sygys commented Oct 2, 2023

Is there a way to get the WAN ip in home assistant? I have an automation to check if the connection is lost or when ha reboots and send me the latest ip address by telegram when connection is restored. In the Fritzbox integration there was a way to get this ip. I can't find it in the mikrotik integration. Is there a way?

@sygys sygys added the question Further information is requested label Oct 2, 2023
@tomaae
Copy link
Owner

tomaae commented Oct 2, 2023

that really depends on your network setup. it could be under interface you use for outside traffic.
you could always make a script on your router to write current it into envinroment variables. simple automation in HA that detects the value change and do whatever you need to do with it. that would be network setup independent and reliable.

@Extrapilot1
Copy link

You could use an existing integration- https://www.home-assistant.io/integrations/dnsip/

Another option would be to enable the IP/Cloud functionality (which is MT's native dynamic DNS service-free), which tracks your external IP as a property you can query with a script as:

:local cloud [/ip cloud get public-address];

You would need to determine how you want to handle this- it could behave as a function just returning text for example, that you parse as a template sensor, and have the Script option in the Integration enabled so you can trigger that as a switch.

It would probably be better to have the integration here do the lookup- where if Cloud was enabled, this value would be returned, since there could be more flexibility if there were multiple links, or if you wanted to have HA updated if the external IP changed etc.

@tomaae
Copy link
Owner

tomaae commented Oct 5, 2023

I mean, maybe? I will have to look up what /ip cloud is even about.

@sygys
Copy link
Author

sygys commented Oct 5, 2023

Many thanks so far guys. I appreciate all the options. I was looking for it in the mikrotik integration and never thought about an option to let another integration check the IP and send it. I guess it's even allot easier this way. I'm no mikrotik pro so writing scripts and stuff isn't really an option for me. It also isn't a big problem though I can try to get the IP from another integration. I do however have some problems with entities doing nothing in the integration and other entities that are becoming unavailable. But I think that's something for another time (thread)

@tomaae
Copy link
Owner

tomaae commented Oct 5, 2023

certainly, if there is a problem you notice, let me know. I'm transitioning my integration to new model to take advantage of all new HA features, so there may be some issues.

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@github-actions github-actions bot added the stale label Oct 20, 2023
@github-actions
Copy link

This issue was closed because it has been stalled for 5 days with no activity.

@TV456
Copy link

TV456 commented Oct 31, 2023

@sygys It is certainly possible to create a script for the WanIP in the environment. @tomaae is right in this one. When the environment variable is set, the MikroTik Router Integration automatically picks it up. He is also right when it depends on the set up you have. In my case I have the MikroTik Router as a switch connected on the ISP browser. I my case the script is quite easily applied. In routerOS go to System -> Script, than add a script. The script I use to set the environmental variable wanIP:

:global wanIP;
:set wanIP [/ip address get [/ip address find interface="....."] address;

On the dots of interface enter the name of the interface which is connected to your ISP. Then test the script by clicking Run Script. In the tab Environment you should no see the declare variable with the IP-address as it's value. If did not work, locate the desired variable and test reading this variable in the terminal using the MikroTik scripting.

Then it helps to set a schedule to run the script at the desired interval. Go to System -> Scheduler and add a schedule. Simple add in the On Event section:

/system script run ...

Enter the name of your scripts on the dots. You can set the start time on startup and the interval. More on MikroTik scheduling. Hope it helps.

@sygys
Copy link
Author

sygys commented Nov 1, 2023

Many thanks for this answer I will test this out. This would be awsome

@TV456
Copy link

TV456 commented Nov 5, 2023

Many thanks for this answer I will test this out. This would be awsome

When testing I helped me to run the commands from the terminal in routerOS by using :put before it. The terminal retrieves the respectable values and prints in the screen. This way you will know if your command works. I.e.:
:put [/ip address get [/ ip address find interface="...."] address ]

While working on my reply to you I tweaked my comment to get the address not from the IP Address List, but directly from the IP DCHP-client list. You can use the following command: [/ip dhcp-client get [/ip dhcp-client find interface="....."] address ]

@github-actions github-actions bot locked and limited conversation to collaborators Dec 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question Further information is requested stale
Projects
None yet
Development

No branches or pull requests

4 participants