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.
- 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.
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.
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.
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.
- 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.