Kane610 / aiounifi

Asynchronous library to communicate with Unifi Controller
MIT License
59 stars 51 forks source link

WAN IP #488

Open jcallaghan opened 11 months ago

jcallaghan commented 11 months ago

Moving query from https://github.com/home-assistant/core/pull/99307 here as requested.

Could I ask if the IP attribute of my UDM device_tracker entity (the WAN address) is obtained via the same way you're getting the temperature of the device?

The reason I ask is that I recently added an LTE-PRO to my setup. If I force a failover to the LTE, the IP attribute doesn't seem to update. I'm having to use DNS IP integration which is cloud dependant and adds latency as it requires my UDM to update DDNS and then the integration to detect the change in 2 minutes intervals. While I'm notified of the failover event within ~5 minutes I was curious if the WAN IP was available locally in a similar way to this PR?

Kane610 commented 11 months ago

Could I ask if the IP attribute of my UDM device_tracker entity (the WAN address) is obtained via the same way you're getting the temperature of the device?

Yes, its all from the same source, its sent over web socket so what information is available in the controller ui should be reflected in home assistant. Fail over to LTE is that on a different wan port or how does your setup look?

If you want to look at what data you get when falling back to LTE you can enable debug logging for the integration or run the library cli from the terminal.

ViViDboarder commented 10 months ago

I’ve been looking to do something similar here. I’m using a remote rest api for getting my IP as well, but this sounds better.

It sounds like you’re saying it should be available already, but I don’t see a device tracker for my UDMP.

Kane610 commented 10 months ago

It sounds like you’re saying it should be available already, but I don’t see a device tracker for my UDMP.

Device trackers in Home Assistant is disabled by default, it would be automatically enabled if there were other entities for the same device reported. In your case Im assuming you do not have other entities for your UDMP. You can look in your registry for enabling the UDMP device tracker entity.

If that is not the case you might have disabled device entities more explicitly?

ViViDboarder commented 10 months ago

Thanks. I found it after enabling that setting.

Since it only includes the IP, that probably won’t be enough for me to detect that I’m on failover internet. I see more info in the diagnostics download for the device. That shows things like which uplink is active able status for the wan ports. I expect this means the data is available to expose via this library or accessible from HASS already. I’ll take a deeper look later.

I’m really looking to automatically turn on certain traffic rules when I’m on failover internet to better manage my bandwidth. The new patch for traffic rules brings me close with my current way of sensing the outage, but it’d be better if I could get it all from the router.

ViViDboarder commented 10 months ago

OP, if the UniFi LTE is special in some way, you should be able to do something like I am today using a rest sensor:

- resource: https://ipinfo.io/json
  scan_interval: 90
  sensor:
    - name: Public IP
      icon: mdi:ip
      json_attributes:
        - city
        - region
        - country
        - org
      value_template: "{{ value_json.ip }}"

Is faster than your router updating your ddns and then pulling that back down via another polling interval. This is updated every 90s. Can’t go faster or you hit the free tier daily limit.

Kane610 commented 10 months ago

I’m really looking to automatically turn on certain traffic rules when I’m on failover internet to better manage my bandwidth. The new patch for traffic rules brings me close with my current way of sensing the outage, but it’d be better if I could get it all from the router.

It would be nice once you've achieved this to write up a post about it :)

ViViDboarder commented 8 months ago

Is there already someone working on adding Traffic Rules to Home Assistant? If not, I can start a PR.

Kane610 commented 8 months ago

Is there already someone working on adding Traffic Rules to Home Assistant? If not, I can start a PR.

If anyone it would most probably be @herriejr but I don't know if he's gotten to start that yet.

ViViDboarder commented 8 months ago

Cool. I started one. Wrapping up tests now.

ViViDboarder commented 8 months ago

FYI: https://github.com/home-assistant/core/pull/104671

herriejr commented 8 months ago

I've got a working version locally running, but I hadn't gotten around to writing tests. I'll try commit my changes to my repo today, so we can compare notes. ;-)

herriejr commented 8 months ago

You can find my code on https://github.com/herriejr/home-assistent-core/tree/dev/homeassistant/components/unifi/