Created
July 3, 2024 18:32
-
-
Save leowinterde/fefef8d803b4810d74de26cab5433b6c to your computer and use it in GitHub Desktop.
Home Assistant Auto Update DNS to porkbun.com
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
############################################################################# | |
# DNS Updater | |
############################################################################# | |
sensor: | |
- platform: rest | |
resource: "https://api.ipify.org/" | |
name: "external_ip" | |
scan_interval: 600 | |
rest_command: | |
ddns_porkbun: | |
url: "https://api.porkbun.com/api/json/v3/dns/editByNameType/DOMAIN/A/SUBDOMAIN" | |
method: post | |
content_type: "application/json" | |
payload: > | |
{ | |
"apikey": "{{ APIKEY }}", | |
"secretapikey": "{{ SECRETAPIKEY }}", | |
"content":"{{ IP }}", | |
"ttl": "{{ TTL }}" | |
} | |
automation: | |
- id: ddns_update_porkbun | |
alias: "Update D(Dyn)DNS on Porkbun" | |
mode: single | |
trigger: | |
- platform: state | |
entity_id: | |
- sensor.external_ip | |
condition: | |
- alias: ip is valid | |
not: | |
- condition: state | |
entity_id: sensor.external_ip | |
state: unavailable | |
- condition: state | |
entity_id: sensor.external_ip | |
state: unknown | |
action: | |
- service: rest_command.ddns_porkbun | |
data: | |
APIKEY: !secret ddns_porkbun_apikey | |
SECRETAPIKEY: !secret ddns_porkbun_secretapikey | |
IP: "{{ states('sensor.external_ip') }}" | |
TTL: "300" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment