Detect if IP changes?

Ive avoided using a service like Duck DNS or noIP as my IP seems to rarely change (has survived multiple modem reboots too). However, if it did change it would be good to have an automation triggered to send me the new IP.

Using the nest sensors I can get my external IP so I have a means to get the value. However, Im not sure how to trigger an automation. Any ideas?

Im guessing some sort of templating would work but I am no good at writing templates .

OK, got this working. If anyone is interested here is the config.

Under sensors:

  - platform: template
    sensors:
      ipchange:
        entity_id: sensor.downstairs_last_ip
        value_template: "{%- if is_state('sensor.downstairs_last_ip', 'XX.XX.XX.XX') -%} False {%- else -%} True {%- endif %}"

Under automation:

  - alias: "NOTIFY IF IP CHANGES"
    trigger:
      platform: state
      entity_id: 'sensor.ipchange'
      from: 'False'
      to: 'True'
    action:
      service: notify.home_assistant
      data:
        title: "Home IP Address has Changed"
        message: Home IP Address was changed.  The new home IP address is "{{ states('sensor.downstairs_last_ip') }}"

Replace the xx.xx.xx.xx with your current IP and the sensor with your appropriate entity ID that has your IP address. Fabaff posted above a sensor to pull your IP without a nest.

1 Like

add your external IP to a nmap list. Trigger on it being away… That might work.

Of course it assumes someone else hasn’t gotten it already.

Can you post what your nest sensors show in the dev states panel? That may give us a starting point. I only have Nest Protects so I don’t have the attributes you have.

@rpitera “sensor.downstairs_last_ip” returns my IP in the standard XX.XX.XX.XX format.

Off the top of my head, I’d say that you’d want to create a template sensor that compares the string of the IP address to whatever it usually is so that you get a True or False response (you’ll have to play with this in the dev templates panel until you get the right setup). Then use the value of the template sensor as a trigger. When it changes to the state "false’ (or “False” depending on the case it outputs) that can be your trigger.

1 Like

Which Nest sensors are you using that let you get the external IP address?

See this component:

Specifically ‘last_ip’

Cool,
It’s great what you learn when you read the documentation.

But back to your question, can you just setup on a state change on it?

No, I wouldn’t think so. The IP isn’t really a state.

For all no-Nest users:

2 Likes

I have a simple bash script for this, including wan/lan options.

Care to share?

Ok, figured out the template and it returns the right values in the development panel.

{%- if is_state(“sensor.downstairs_last_ip”, ‘XX.XX.XX.XX’) -%} False {%- else -%} True {%- endif %}

returns False if the IP matches and True if it doesn’t. Might seem backwards but I am testing for a change in IP so True is a change in this case and false is no change.

So I put that into a template sensor. (I get the same result if I make it a template sensor or template Binary sensor)
- platform: template
sensors:
ipchange:
entity_id: sensor.downstairs_last_ip
value_template: ‘{%- if is_state(“sensor.downstairs_last_ip”, ‘XX.XX.XX.XX’) -%} False {%- else -%} True {%- endif %}’

I am getting the following in the log and HA won’t start.

16-11-30 20:48:09 homeassistant.util.yaml: while parsing a block mapping
in “/home/hass/.homeassistant/sensors.yaml”, line 226, column 8
expected , but found ‘’
in “/home/hass/.homeassistant/sensors.yaml”, line 227, column 71

226 is the entitity ID line 227 is the value template line.

just checking, the XX.XX.XX.XX should not be inside the quoted string right? the quote in front of that closes off the quote in front of the open bracket.

Both sensor.downstairs_last_ip and XX.XX.XX.XX need to be in quotes. I tried both ‘single’ and “double” quotes. Both work in the template developer and return the right result.

I’ve seen this before and I think you have to use a combo of single quotes on the template and double quotes on the string (or vice versa). I’m trying to find the post this happened in.

Im guessing this one?

I think I tried this but will check again tonight. I may have not tried the exact combination of “” on the outside and ‘’ inside.

1 Like

Yep - that was it! Forgot it was me asking the question as well!! LOL

OK, got this working. If anyone is interested here is the config.

Under sensors:

  - platform: template
    sensors:
      ipchange:
        entity_id: sensor.downstairs_last_ip
        value_template: "{%- if is_state('sensor.downstairs_last_ip', 'XX.XX.XX.XX') -%} False {%- else -%} True {%- endif %}"

Under automation:

  - alias: "NOTIFY IF IP CHANGES"
    trigger:
      platform: state
      entity_id: 'sensor.ipchange'
      from: 'False'
      to: 'True'
    action:
      service: notify.home_assistant
      data:
        title: "Home IP Address has Changed"
        message: Home IP Address was changed.  The new home IP address is "{{ states('sensor.downstairs_last_ip') }}"

Replace the xx.xx.xx.xx with your current IP and the sensor with your appropriate entity ID that has your IP address. Fabaff posted above a sensor to pull your IP without a nest.

2 Likes

Did last_ip go away with the 0.34.3 upgrade to HA??