MQTT for Newb

Hi guys,

I have two HA. One in my house and one in my shed. The one in the shed is for getting bluetooth sensors from my greenhouse. I want those sensors to appear on my main HA but can’t figure out how to configure that. I found a remote home assistant plugin that used to work great but it doesn’t anymore. Can somebody explain to me how to configure what I want? Pretty sure MQTT is the way to do it but I don’t understand how to configure my component for that.

Thanks

I don’t use it (I have mine set up as a master/slave) but I hear a lot of people talking about using this:

If you want to know how to set up the master/slave then I can give you info on that.

I don’t really need the mqtt, master/slave would do what I need? If yes, go ahead please

Here is the instructions, you will need one automation on one of the HA’s, and statestream on the sensor HA and discovery setup the main HA.

###in main HA####

mqtt:
  broker: 192.168.2.12
  client_id: 3333
  discovery: true
  discovery_prefix: rpi1

###in sensor HA ##

mqtt:
  broker: 192.168.2.12
  client_id: 4444


mqtt_statestream:
  base_topic: rpi1
  publish_attributes: true
  publish_timestamps: true
  include:
    domains:
      - sensor

###in either HA###

#########################################################################################
#########################################################################################
automation mqtt_config_entity_creator_sensor:
  alias: mqtt_config_entity_creator_sensor
  trigger:
    - platform: mqtt
      topic: 'rpi1/sensor/#'
  condition:
    condition: template
    value_template:  "{{ trigger.topic.split('/')[3] == 'state' }}"   
  action:
    - service: mqtt.publish
      data_template:
        topic: "homeassistant/{{ trigger.topic.split('/')[1] }}/{{ trigger.topic.split('/')[2] }}/config"
#        payload: ""         
        payload: "{\"name\": \"{{ trigger.topic.split('/')[2]| replace('_', ' ') | title }}\",\"state_topic\": \"rpi3/{{ trigger.topic.split('/')[1] }}/{{ trigger.topic.split('/')[2] }}/state\" }"
        retain: true
#########################################################################################
#########################################################################################

Is the Home Assistant system in the shed used for anything other than simply receiving sensor data via Bluetooth? If not, it seems like an excessive amount of software infrastructure to simply collect sensor data … that you ultimately want to send to the house’s Home Assistant system.

The ironic part is that you’ll be using MQTT to ‘glue’ the two Home Assistant systems together. That’s the very same technology often used to read data directly from sensors or via Bluetooth-to-MQTT gateways like OpenMQTTGateway.

1 Like

No sorry. I should gave been clearer. Both methods use mqtt. They just use it in a different way.

Yes, the fact is, I have no power in the greenhouse and some Mi Flora sensors as well as a multisensor aeotec. Since I’m too far for bluetooth and z-wave, I have a Rpi3 in my shed (which has electricity) and I want to send the status of those sensors to my main HA in my home.

Thanks

If I understand you correctly, you have:

  • Bluetooth and zwave sensors in the greenhouse (no AC power available).
  • The transmitted sensor data is received by Home Assistant (on an RPi) in a nearby shed (AC power available).
  • Another Home Assistant system is in the house and the goal is to have it receive the sensor data collected by the system in the shed.

Virtually all solutions involve using MQTT as a means of sharing data between the two instances of Home Assistant. In light of that, my original idea was to replace the shed’s instance of HA with something simpler, something designed to receive Bluetooth-based data and relay it via MQTT. It involves far less configuration (and maintenance) that running a full-blown HA system in the shed.

HOWEVER, that idea is now rendered worthless by the fact you are also using zwave-based sensors in the greenhouse. The simple ‘gateway’ device I had in mind cannot handle zwave. So we’re back to the status quo of two HA systems needing to share data.

The commonly-used solution for connecting Home Assistant systems is MQTT Statestream. It would be used to make your shed-based HA system send all its sensor data via MQTT.

That’s one-half of the equation. The other half is to make the house-based HA system receive the MQTT data. In brief, you must create one MQTT sensor (on the house-based system) for each sensor you wish to monitor (on the shed-based system).

If you only have 2-3 sensors then it’s not much of hardship to manually define them on the house-based system. If you have ten or more then it can become a tedious task. The author of this post devised a fairly clever way of automatically adding the sensors using MQTT Discovery:

Wow thanks!

It would be nice to see an option to integrate two HA.

Lukas did create a pluging a while ago for that. Used to work great before the new Auth system

1 Like

I think that could still work. It uses websockets with api_password and, as far as I know, api_password is currently deprecated but not eliminated. But I may be wrong about that.

The advantage of Lukas Hetsenecker’s solution is it does not require the use of an MQTT broker (because it uses websockets).

The advantage of using MQTT Statestream is you don’t have to share all the entity data, you can specify a subset if you wish. That might not be relevant for you if your shed-based HA system is only monitoring the sensors you wish to share (and nothing else).