hass:high_availability
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
hass:high_availability [2020/06/03 09:59] – a | hass:high_availability [2021/08/13 23:36] (current) – a | ||
---|---|---|---|
Line 32: | Line 32: | ||
===== Active/ | ===== Active/ | ||
- | Only one instance | + | Only once instance |
+ | |||
+ | This starts off with a heartbeat automation that publishes the instances IP address every 60 seconds; | ||
+ | |||
+ | < | ||
+ | - id: ' | ||
+ | alias: HASS: | ||
+ | description: | ||
+ | trigger: | ||
+ | - platform: time_pattern | ||
+ | seconds: ' | ||
+ | condition: | ||
+ | - condition: state | ||
+ | entity_id: binary_sensor.active | ||
+ | state: ' | ||
+ | action: | ||
+ | - data: | ||
+ | payload: "{{ states(' | ||
+ | topic: home/ | ||
+ | service: mqtt.publish | ||
+ | </ | ||
+ | |||
+ | This works in concert with a binary_sensor that compares the published IP to the instance IP: | ||
+ | |||
+ | < | ||
+ | binary_sensor: | ||
+ | - platform: template | ||
+ | sensors: | ||
+ | active: | ||
+ | friendly_name: | ||
+ | value_template: | ||
+ | </ | ||
+ | |||
+ | Each automation then includes a condition to check the state of this sensor: | ||
+ | |||
+ | < | ||
+ | condition: | ||
+ | - condition: state | ||
+ | entity_id: binary_sensor.active | ||
+ | state: ' | ||
+ | </ | ||
+ | |||
+ | Control can be manually transferred between instances by calling the heartbeat automation on the standby instance. This immediately publishes the IP address, toggling the state of the binary sensor in each instance. | ||
+ | |||
+ | ===== Active/ | ||
+ | This is the previous method I used for transferring control between | ||
+ | |||
+ | The currently active instance was recorded in the following | ||
< | < | ||
Line 62: | Line 109: | ||
payload: !secret partner | payload: !secret partner | ||
retain: ' | retain: ' | ||
- | < | + | </code> |
Additionally, | Additionally, | ||
Line 105: | Line 152: | ||
This arrangement also allows for automations which should run regardless of whether the instance is active or not, or automations which run specifically when the instance is inactive. It does however require each automation to be modified with this condition, which may be onerous for an established setup. | This arrangement also allows for automations which should run regardless of whether the instance is active or not, or automations which run specifically when the instance is inactive. It does however require each automation to be modified with this condition, which may be onerous for an established setup. | ||
| | ||
+ | ==== Disabling/ | ||
+ | This method is a little more involved to implement, but does allow existing automations to be used unmodified. The first part of the puzzle is a script to create a group which contains all the current automations: | ||
+ | |||
+ | < | ||
+ | create_every_automation_group: | ||
+ | sequence: | ||
+ | - service: group.set | ||
+ | data_template: | ||
+ | object_id: every_automation | ||
+ | entities: '{{ states.automation | map(attribute='' | ||
+ | </ | ||
+ | |||
+ | With this group created we can now control the status of each automation with the '' | ||
+ | |||
+ | < | ||
+ | - id: ' | ||
+ | alias: HASS: | ||
+ | description: | ||
+ | trigger: | ||
+ | - entity_id: sensor.active | ||
+ | platform: state | ||
+ | to: !secret partner | ||
+ | condition: [] | ||
+ | action: | ||
+ | - data: {} | ||
+ | service: script.create_every_automation_group | ||
+ | - data: {} | ||
+ | entity_id: group.every_automation | ||
+ | service: automation.turn_off | ||
+ | - data: {} | ||
+ | entity_id: automation.hass_active | ||
+ | service: automation.turn_on | ||
+ | - id: ' | ||
+ | alias: HASS:Active | ||
+ | description: | ||
+ | trigger: | ||
+ | - entity_id: sensor.active | ||
+ | from: !secret partner | ||
+ | platform: state | ||
+ | condition: [] | ||
+ | action: | ||
+ | - data: {} | ||
+ | service: script.create_every_automation_group | ||
+ | - data: {} | ||
+ | entity_id: group.every_automation | ||
+ | service: automation.turn_on | ||
+ | </ | ||
+ | Note that after the instance is moved into standby, the last action of the HASS: |
hass/high_availability.1591149557.txt.gz · Last modified: 2020/06/03 09:59 by a