User Tools

Site Tools


hass:high_availability

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
hass:high_availability [2020/06/03 10:32] ahass:high_availability [2021/08/13 23:36] (current) a
Line 32: Line 32:
  
 ===== Active/Standby State ===== ===== Active/Standby State =====
-Only one instance must be active at time. This requires a method for transferring control between instances. The simplest method for achieving this is a MQTT topic indicating which instance is active.+Only once instance should be active at any given time. This requires a way of suppressing the automations from running, as well as detected when the active instance has failed. 
 + 
 +This starts off with a heartbeat automation that publishes the instances IP address every 60 seconds; 
 + 
 +<code> 
 +- id: '1583253390883' 
 +  alias: HASS:Heartbeat 
 +  description: '' 
 +  trigger: 
 +  - platform: time_pattern 
 +    seconds: '0' 
 +  condition: 
 +  - condition: state 
 +    entity_id: binary_sensor.active 
 +    state: 'on' 
 +  action: 
 +  - data: 
 +      payload: "{{ states('sensor.local_ip') }}" 
 +      topic: home/hass/active 
 +    service: mqtt.publish 
 +</code> 
 + 
 +This works in concert with a binary_sensor that compares the published IP to the instance IP: 
 + 
 +<code> 
 +binary_sensor: 
 +  - platform: template 
 +    sensors: 
 +      active: 
 +        friendly_name: "Active IP" 
 +        value_template: "{{ states('sensor.partner') == states('sensor.local_ip') or is_state('sensor.partner', 'OFFLINE') or is_state('sensor.partner', 'unavailable') }}" 
 +</code> 
 + 
 +Each automation then includes a condition to check the state of this sensor: 
 + 
 +<code> 
 +  condition: 
 +  - condition: state 
 +    entity_id: binary_sensor.active 
 +    state: 'on' 
 +</code> 
 + 
 +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/Standby State (Old method) ===== 
 +This is the previous method I used for transferring control between the two instances. It had the advantage of not needing condition in each automation, but could get itself unstuck if all of the automations failed to enable or disable correctly. 
 + 
 +The currently active instance was recorded in the following MQTT topic:
  
 <code> <code>
Line 62: Line 109:
     payload: !secret partner     payload: !secret partner
     retain: 'false'     retain: 'false'
-<code>+</code>
  
 Additionally, to cover the scenario for a sudden loss of service, such as a crash or an ungraceful shutdown a heartbeat automation is used. Additionally, to cover the scenario for a sudden loss of service, such as a crash or an ungraceful shutdown a heartbeat automation is used.
hass/high_availability.1591151547.txt.gz · Last modified: 2020/06/03 10:32 by a