Since it happened that I have received some duplicated notifications, finally I switched to a sensor made in Node-Red and the node node-red-contrib-public-ip-address
.
Now the automation is really simplified without conditions, since the Node-Red flow doesn’t output state changes if the public ip address doesn’t change.
Here a screenshot of that simple flow and the code for sharing Thanks to you all!
Flow code:
[{"id":"c0facedc.0275a","type":"tab","label":"Sensore Ip Pubblico Per HA","disabled":false,"info":""},{"id":"ea8e2a74.4bfd98","type":"public-ip-address","z":"c0facedc.0275a","name":"","x":410,"y":300,"wires":[["5a6babd4.99f614"]]},{"id":"57c36e65.78a9d","type":"inject","z":"c0facedc.0275a","name":"Trigger ogni minuto","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"60","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":220,"y":300,"wires":[["ea8e2a74.4bfd98"]]},{"id":"5a6babd4.99f614","type":"ha-entity","z":"c0facedc.0275a","name":"Ip Pubblico Node-Red","server":"b6476084.b9987","version":2,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"Ip Pubblico Node-Red"},{"property":"device_class","value":"sensor"},{"property":"icon","value":"mdi:ip-network"},{"property":"unit_of_measurement","value":""},{"property":"state_class","value":""},{"property":"last_reset","value":""}],"state":"payload","stateType":"msg","attributes":[{"property":"entity_id","value":"sensor.node-red.ip_pubblico","valueType":"str"}],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","outputOnStateChange":false,"outputPayload":"","outputPayloadType":"str","x":620,"y":360,"wires":[["9deef2f7.9c2e1"]]},{"id":"4794ed24.5bc924","type":"inject","z":"c0facedc.0275a","name":"Test Ip 37.128.5.123","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"37.128.5.123","payloadType":"str","x":210,"y":360,"wires":[["5a6babd4.99f614"]]},{"id":"3a43bebf.8bfa32","type":"inject","z":"c0facedc.0275a","name":"Test Ip 99.99.99.9","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"99.99.99.9","payloadType":"str","x":210,"y":420,"wires":[["5a6babd4.99f614"]]},{"id":"9deef2f7.9c2e1","type":"debug","z":"c0facedc.0275a","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":890,"y":360,"wires":[]},{"id":"b6476084.b9987","type":"server","name":"HA-Local","version":2,"addon":false,"rejectUnauthorizedCerts":false,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30}]