|
| 1 | +###################################################################### |
| 2 | +# @CCOSTAN - Follow Me on X |
| 3 | +# For more info visit https://www.vcloudinfo.com/click-here |
| 4 | +# Original Repo : https://github.com/CCOSTAN/Home-AssistantConfig |
| 5 | +# ------------------------------------------------------------------- |
| 6 | +# Pi-hole HA Sync - Mirror blocking state across DNS nodes |
| 7 | +# Keep Pi-hole blocking on docker_10 and docker_14 in lockstep. |
| 8 | +# ------------------------------------------------------------------- |
| 9 | +# Notes: Uses switch.pi_hole + switch.pi_hole_2 from the Pi-hole integration. |
| 10 | +###################################################################### |
| 11 | + |
| 12 | +automation: |
| 13 | + - id: pihole_ha_sync_blocking_state |
| 14 | + alias: "Pi-hole HA Sync - Blocking State" |
| 15 | + description: "Mirror Pi-hole blocking state between primary and secondary DNS nodes." |
| 16 | + trigger: |
| 17 | + - platform: state |
| 18 | + entity_id: |
| 19 | + - switch.pi_hole |
| 20 | + - switch.pi_hole_2 |
| 21 | + action: |
| 22 | + - choose: |
| 23 | + - conditions: |
| 24 | + - condition: template |
| 25 | + value_template: >- |
| 26 | + {{ trigger.entity_id == 'switch.pi_hole' |
| 27 | + and trigger.to_state.state == 'off' |
| 28 | + and states('switch.pi_hole_2') != 'off' }} |
| 29 | + sequence: |
| 30 | + - service: switch.turn_off |
| 31 | + target: |
| 32 | + entity_id: switch.pi_hole_2 |
| 33 | + - conditions: |
| 34 | + - condition: template |
| 35 | + value_template: >- |
| 36 | + {{ trigger.entity_id == 'switch.pi_hole' |
| 37 | + and trigger.to_state.state == 'on' |
| 38 | + and states('switch.pi_hole_2') != 'on' }} |
| 39 | + sequence: |
| 40 | + - service: switch.turn_on |
| 41 | + target: |
| 42 | + entity_id: switch.pi_hole_2 |
| 43 | + - conditions: |
| 44 | + - condition: template |
| 45 | + value_template: >- |
| 46 | + {{ trigger.entity_id == 'switch.pi_hole_2' |
| 47 | + and trigger.to_state.state == 'off' |
| 48 | + and states('switch.pi_hole') != 'off' }} |
| 49 | + sequence: |
| 50 | + - service: switch.turn_off |
| 51 | + target: |
| 52 | + entity_id: switch.pi_hole |
| 53 | + - conditions: |
| 54 | + - condition: template |
| 55 | + value_template: >- |
| 56 | + {{ trigger.entity_id == 'switch.pi_hole_2' |
| 57 | + and trigger.to_state.state == 'on' |
| 58 | + and states('switch.pi_hole') != 'on' }} |
| 59 | + sequence: |
| 60 | + - service: switch.turn_on |
| 61 | + target: |
| 62 | + entity_id: switch.pi_hole |
| 63 | + mode: single |
0 commit comments