This project is a Flask application that updates the dynamic DNS records for a list of hostnames with Loopia as the DNS provider. It also includes a Home Assistant sensor and automation.
- Clone the repository:
git clone https://github.com/swetoast/smartresolver.git
- Navigate to the project directory:
cd smartresolver - Install the required Python packages:
pip install flask requests configparser
- Open
dns_endpoint.confin a text editor. - Under the
[Credentials]section, setusernameandpasswordto your Loopia DNS credentials. - Under the
[Hostnames]section, sethostnamesto a comma-separated list of hostnames to update. - Under the
[DEFAULT]section, setHOST,PORT,USE_HTTPS,CERTIFICATE_PATH, andKEY_PATHas needed.
- Start the application:
python smartresolver.py
- The application will now update your dynamic DNS records whenever you access
http://IP_ADDRESS:PORT/update_dyndns.
To add a sensor in Home Assistant that triggers the dynamic DNS update:
- Add the following to your
configuration.yaml:sensor: - platform: rest resource: http://IP_ADDRESS:PORT/update_dyndns name: DNS Resolver value_template: '{{ value_json[0].status }}' json_attributes: - 'hostname' - 'ip_address' scan_interval: hours: 4
- Restart Home Assistant to apply the changes.
To add an automation in Home Assistant that triggers the dynamic DNS update when the IP address does not match:
- Add the following to your
automations.yaml:alias: "Auto-Update: Update DNS Resolver on IP Mismatch" description: >- This automation updates the DNS Resolver sensor when its IP address does not match with the external IP sensor. trigger: - platform: template value_template: >- {{ states('sensor.external_ip') != state_attr('sensor.dns_resolver', 'ip_address') }} action: - service: homeassistant.update_entity target: entity_id: sensor.dns_resolver data: {} mode: restart
- Restart Home Assistant to apply the changes.
This project is unlicensed.