I created (and still use) an integration to do “master/slave” HA through MQTT:
It handles all this automagically