Connecting two Hass.io instances on different networks

Hey guys, first time on the forums! I’ve been using Hass.io for a while now and am loving what it can do around the house. I have recently added a RP3 with Hass.io to my office setup, and am wondering how I can connect my office instance to show up in my home instance? To have the same control over lights/blinds/sensors/media etc from home and vice versa.

From what I’ve read MQTT Eventstream seems like the option to run with? My experience with MQTT has all been internal and I’m not quite sure how to point one device on a different network to the other. Any help or suggestions on how I could achieve this?

Thanks

All you’d need to do is connect both HA instances to an MQTT broker. Set sensors in the receiving HA to reads from MQTT, and get the sensind HA instance to publish values to MQTT…

Basically long story short, you create an automation on your office instance so that each time one of your lights changes status, you publish its state to MQTT
You set another automation that reads from the same MQTT Topic and control your light based on the Topic value.
In your Home HA you create MQTT Light entities that allow you to publish and get the status of your office ights.
Hope that makes sense

1 Like

Eventstream component is automatic connection over mqtt

Statestream component is similar

App deamon is also available for this

I have a single main frontends. All other(3 currently). HA instances feed events to that. I run all automations on the single main instance

1 Like

Oh that’s nice, thanks :slight_smile:

1 Like

Forgot to mention.

They show up as entities in the connected Main instance. I create a group view so that the remote HA instance has its own tab(or integrate them in other group views)

1 Like

well I managed to get the MQTT servers pointed to each other, they now show all devices upon reboot of either HA instance, however if no device is used they will drop off until the next event trigger.

So if I wanted to reliably control my office lights from home, you’re saying I would need to create an MQTT Light in my home instance? Would that duplicate the light showing in my main instance?

The goal being that I can just connect to one interface from my phone or whatever to be able to control all devices in any location reliably.

Thanks for the help so far guys, really helpful and much appreciated!

I have 4 Ha’s connect to each other with statestream: I essentially pick up any sensor needed on a HA from another with mqtt sensor. To control another HA, I use this script. (created yesterday) It takes the input of the entities names and uses homeassistant.turn_on to control it, like for switches / scripts. I am going to adapt it so it takes more inputs for which HA or the service needed.

You can use it in a shell command like this

shell_command:
  rpi3: /Library/Frameworks/Python.framework/Versions/3.6/bin/python3 /Users/xxx/.homeassistant/rpi3.py {{ entity }}"


import argparse
import requests
import simplejson as json


parser = argparse.ArgumentParser()
parser.add_argument("e")
args = parser.parse_args()


url = "http://192.168.2.100:8123/api/services/homeassistant/turn_on"
data = {"entity_id": args.e}
headers = {'Content-type': 'application/json'}
r = requests.post(url, data=json.dumps(data), headers=headers)

This is a python script that can control other HA instances through its api.

shell_command:
  post: /Library/Frameworks/Python.framework/Versions/3.6/bin/python3 /Users/xxx/.homeassistant/post.py {{ ip }} {{ service }} {{ entity }}

use the shell command like this

      service: shell_command.post
      data:
        ip: '192.168.2.186:8123'
        service: 'homeassistant/turn_on'
        entity: 'switch.kitchen_light'

and post.py in .homeassistant directory

import argparse
import requests
import simplejson as json


parser = argparse.ArgumentParser()
parser.add_argument("ip")
parser.add_argument("service")
parser.add_argument("entity")
args = parser.parse_args()


url = "http://"+args.ip+"/api/services/"+args.service
data = {"entity_id": args.entity}
headers = {'Content-type': 'application/json'}
r = requests.post(url, data=json.dumps(data), headers=headers)

Honestly I use 4 different methods as I started this before some component we’re available then change some to test function just for fun. For detail function of statestream I need to look at config and compare. Yes, eventstream disappear. I use eventstream for alarm sensor connected gpio so this was actually nice because only tripped sensor would show(feature not bug)

I set up sensor+switch on friends gated entry.
I use normal mqtt for this sending from RemoteHA. Main HA use mqtt switch for Control this. There is automation at Remote HA to send the sensor state change and listen for Switch ON mqtt message.

I use separate mqtt server(docker) for connect these

You can accomplish above with statestream by pairing mqtt cover or other component in main HA that persists. OR script/etc to uodate state and make remain in front end. Honestly method to use depends on preference. For 2 or 3 entity I might just do some automations and entity pairs(main and remote) but if many I would use statestream.