Display Public IP, Notify Of Change

Hello, I would like to have a card that shows my current public IP address. I would also like it to send a pushover notification when it changes, and what the new IP is.

I do not want to use a DDNS service, hoping there is a way to directly integrate it.

Thanks in advance for any help or direction!!

sensor:
  - platform: dnsip

group:
  External IP:
    - sensor.dnsip

automation:
  alias: Notify when external ip changes
  initial_state: on 
  trigger:
    platform: state 
    entity_id: sensor.dnsip
  action:
    service: notify.YOU
    data_template:
      message: "New external IP address is {{ states('sensor.dnsip') }}"
10 Likes

Nice! Ill give it a try tonight.

Tank you very much for the quick reply. :beers:

1 Like

This works very well, thanks for writing this down!

1 Like

Thanks! I was also looking for an option to show my public IP. The sensor option works verry well for this.

But what I don’t understand, you have also mentioned the “group” config, what does it do?
Because I’m already able to show the public IP with a sensor card in lovelace with only the Sensor config.

I’m just trying to understand were the group config is for and what it does :slight_smile:
Thanks already!

That post is from 2 years ago, the old ui used to present groups as cards.

2 Likes

Thanks for your answer!
JUst tried to understand, but this seems clear. So no use of configuring the “group” settings into Lovelace now I guess.

1 Like

I wanted to see an IP on my dashboard.
So I added a cronjob on my server:

*/5 * * * * echo "<html><head><meta name="color-scheme" content="dark light"></head><body style=\"text-align:center;\">$(curl https://ipinfo.io/ip)<BR><BR>Updated at:<BR><BR>$(date)</body></html>" > /home/${USER}/has/www/1.html

And added a webpage card to the dashboard:

 - type: iframe
   title: IP
   url: /local/1.html
   aspect_ratio: 46%

So I can see it as:
Screen Shot 2021-07-07 at 13.07.27

The only issue, is that I need to clean browser cache to see a change immidiately.

There has some changes in HA now it’s not calles dnsip it generates myip instead

sensor:
  - platform: myip

automation:
  alias: Notify when external ip changes
  initial_state: on 
  trigger:
    platform: state 
    entity_id: sensor.myip
  action:
    service: notify.YOU
    data_template:
      message: "New external IP address is {{ states('sensor.myip') }}"
1 Like

Will that really work?
When the IP changes the phones connection to HA is lost and therefore this message wont be received?
Or is there something I’m not understanding here?

You could Email the new IP but using notifications won’t work (at least when you are not home)

Looks like platform: dnsip still works for me as of Core version 12.10. Where is this change documented?

If you use current integration on default it is myip.

See in the source https://github.com/home-assistant/core/blob/12a7b64e64e0068241dfd284ea65202e7c3b59fb/homeassistant/components/dnsip/const.py

Everything else is History. And current core is core-2022.3.1

No if u use the app you are using firebase API from google and there is no need of IP knowing, everything is based on the Firebase PUSH Token

stupid question but where do you paste this in? configuration.yaml or automations.yaml? Thanks
I am getting a duplicate key error when I paste into configuration.yaml

group: !include groups.yaml

automation: !include automations.yaml #i get a duplicate key error here

script: !include scripts.yaml

scene: !include scenes.yaml

I don’t think you need to make any YAML changes:

3 Likes

I logged in to like you. It is very useful.

I have a similar issue where DNS IP won’t work and that is if my DDNS update has failed and I got a new IP address from my ISP. In that case, asking a DNS is futile. I would recommend this instead:

- platform: rest
  name: External Ip
  resource: http://ip.jsontest.com
  value_template: "{{ value_json.ip }}"
1 Like

Like many others, I could not get the DNSIP integration to work with the default myip.opendns.com config and had to resort to using YOUR_SUBDOMAIN.duckdns.org

But while this worked, I think relying on a DNS resolver could potentially cause problems or delays with a dynamic IP address, so I think the RESTful integration external IP sensor will be more reliable since it gets the IP address directly, no need to wait for any DNS propagation or update.

So just add this to configuration.yaml and remember a full HA restart is required, not just a YAML reload:

sensor:
  - platform: rest
    scan_interval: 300
    resource: http://ip.jsontest.com
    name: External IP
    value_template: "{{ value_json.ip }}"

Note that the default scan_interval for the RESTful sensor is 30 seconds which seems excessive and would put unnecessary load on the jsontest.com servers who are kindly offering this public service, hence why I changed it to 5 minutes.

Now, to do something useful with the Extenal IP address I’ve created an automation to send a notification and to force an update for DuckDNS:

alias: IP Change
trigger:
  - platform: state
    entity_id:
      - sensor.external_ip
condition: []
action:
  # Updated the IP address for DuckDNS
  - service: rest_command.duckdns_update
    data: {}

  # Send a notification to all mobile devices
  - service: notify.all_devices
    metadata: {}
    data:
      message: New external IP address is {{ states('sensor.external_ip') }}
      data:
        actions:
          - action: URI
            title: Check external access works
            uri: https://YOUR_SUBDOMAIN.duckdns.org
        importance: high
        ledColor: red
mode: single

If you get many false positive alerts, then try a condition like this

And for the notify actions to work, add this to configuration.yaml

rest_command:
  duckdns_update:
    url: "https://duckdns.org/update/{YOURDOMAIN}/{YOURTOKEN}"

notify:
  - name: all_devices 
    platform: group
    services: 
      - service: mobile_app_first_device_name
      - service: mobile_app_second_device_name

This hopefully gives you a bit more context on how you could use this

2 Likes