Hi everybody,
I have two instances of Home Assistant running on two different rpi 3B+, one in my home and one at my parent’s house, so they work on different networks.
I menaged how to access remotely to them using the DuckDNS add-on of Hass.io, but I need a sort of communication between them. I want to control some switches at my parent’s house or vice-versa.
I read some informations about mqtt statestream and eventstream, but I didn’t understand if they can be used on different brokers and different networks.
Can someone help me?
I’ve attempted to do something similar just using HomeAssistant’s REST API and the Rest component. Ie, one instance uses the REst component to talk to the other instance’s API. You could then do the reverse for two way control. For my situation, this was better than having full linking of both instances with eventstream.
However -
I get a LOT of errors about Rest service not available. And I don’t think it is the internet connection at either end.
Here’s an overview of the how to do it using MQTT Statestream. Before we get started, it’s important to understand that your Home Assistant system and your parents’ Home Assistant system need to connect to a common MQTT broker. Alternately, each system has its own MQTT broker and they are bridged (how to bridge MQTT brokers is out of scope for now). If you can’t have a common broker, or bridged brokers, then you can’t use MQTT to connect the two systems. Look into using REST and Home Assistant’s API.
On your parents’ Home Assistant system, configure the MQTT Statestream component, listing only the entities you wish to use (otherwise it will publish the state of every entity in the system). In this example, it includes only one entity (light.kitchen
).
mqtt_statestream:
base_topic: parents_house
include:
entities:
- light.kitchen
Now whenever the state changes for light.kitchen
, it will be published to: parents_house/light/kitchen/state
On your Home Assistant system, you create a new MQTT Light that subscribes to parents_house/light/kitchen/state
light:
- platform: mqtt
name: "Parents Kitchen"
state_topic: "parents_house/light/kitchen/state"
command_topic: "parents_house/light/kitchen/command"
Now you have a light entity (light.parents_kitchen
) that displays the status of your parents’ kitchen light. However, to control it, you need to create an automation on your parents’ Home Assistant system. The automation is triggered by changes to the topic parents_house/light/kitchen/command
and uses the received payload to turn the kitchen light on or off.
automation:
- alias: remote_kitchen_light_control
trigger:
- platform: mqtt
topic: "parents_house/light/kitchen/command"
action:
- service_template: "light.turn_{{trigger.payload | lower}}"
entity_id: light.kitchen
Remember, if you can’t have a common MQTT broker, or bridged brokers, then MQTT can’t be used as a connection method.
You’re awesome. Now I can totally understand how it works.
But I think I cannot have a common broker. How can I bridge the two brokers?
Disclaimer: I have not used MQTT bridging but I have researched it for connecting two Home Assistant systems (located far apart).
If you have a VPN connecting your network to your parents network, then you may be able to bridge the two brokers directly. I’m considering using Zerotier for this purpose because it seems like the easiest to implement.
Without a VPN, you need a ‘middleman’ MQTT Broker in the cloud. Two bridges are created:
Your broker <--bridge--> Cloud broker <--bridge--> Parents' broker
The ‘bridge’ is just software configuration. You instruct your broker to share topics with another broker.
There are free cloud-based MQTT services available but the ‘free tier’ usually does not offer bridging. For example, CloudMQTT’s free ‘Cute Cat’ plan doesn’t allow bridging but it is available in their cheapest paid plan. adafruit.io offers a free cloud-based MQTT broker but I can’t find anything in their documentation that discusses bridging.
Be sure to use SSL to secure the communications between local and cloud-based brokers.
The following threads discuss connecting a local MQTT broker to a cloud-based broker:
MQTT Bridge
SNIPS MQTT Bridging
This thread discusses bridging to Adafruit.io’s MQTT broker as a means of providing free SMS from IFTTT. Bridging is discussed about halfway through the first post.
Hi, I tested the mqtt statestream, but I noticed that if I’m using the same configuration for the mqtt broker, it doesn’t require anything else.
Here’s my configuration:
mqtt:
broker: xxx.duckdns.org
username: !secret mqtt_username
password: !secret mqtt_password
port: xxxx
It’s the same for all my Home assistant and it works well for all the switches.
Can I have some security issues or something like that?
Did you have to open/forward a port for this?
is there a step to step for Connect two Home Assistant’s together (on different networks) iam 2 week with my HA
& I have tried all this stuff but cant get any of it to work !! thanks for any help !
jeff
I realize this isn’t exactly what the topic is about - but another possible way to bridge devices on two different networks is to use multiple SmartThings hubs. I’m personally doing this - with a SmartThings hub installed both at home and and work. Leveraging the SmartThings integration in my single instance of HA allows me to see devices both at work and at home.
ST does have handlers to allow you to use native Zwave/Zigbee devices, as well as others (Wemo, TPLink, etc.). Anyhow, just my $.02, unsure if it fits anyone’s exact use-case - but works for me
question -can you have a siren at work trigger from a water sensor at home with this setup - not the way I want to go, but would like to know? iam sure you can through HA ? thanks