[SOLVED] Daisy chainning/remote/slave for main HASS.IO instance - Use MQTT!

Hi All,

Does anyone know if it is possible to run a slave/remote instance of HASS.IO that reports/connect to a main HASS.IO system?

I would like to run several temperature and humidity sensors connected to a raspberry pi running HASS.IO around the house which will then connect to a main instance of HASS.IO.

Anyone been able to do this or know if it is possible?

3 Likes

I do this with a Raspberry Pi Zero. Setup MqTT server on the main instance. You will need to find MQTT instructions for HASS.io. I don’t use it so I only have instructions for Linux/Hassbian.

The second instance you enable MQTT statestream. Then you take the data from that remote instance and create the appropriate sensors.

Setup this on the remote instance:

Setup sensors on the main instance like this:
https://github.com/SilvrrGIT/HomeAssistant/blob/master/sensors.yaml#L362

3 Likes

Hi silvrr

Thank you - I have always been trying to stay well clear of MQTT but from what I can gather, the steep learning curve of MQTT is well worth the effort! I assume setting up MQTT server/client will open up a bucket load of possibilities?

I have seen a lot of headaches with MQTT but will give it a whirl, I mean, how hard can it be, I have somehow mastered HASS.IO!

Is MQTT the only option or does HASS.IO not have a native ‘slave’ mode?

And thanks for reminding me about the Pi Zero, I have so many Pi’s I lost count!

:slight_smile:

I stayed away from MQTT as I thought it was complex too. Once I understood it, I realized its incredibly simple.

Home Assistant used to have a Slave/Master option in the Docs but I think that is now gone and it didn’t work well anyway.

Another option is the rest API which is built into HA (I had forgotten about this)
If you will just pull a one or two sensors this makes sense. After to many the MQTT option is better IMO.

OK, will take your word as gospel on the MQTT front - might come back to you on this! :slight_smile: Not rocket science, is it?

There will be more than one sensor, the more the better - the whole REST API thing I have done, mastered that, but scrapped it in the end since I was trying to re-invent the wheel. This is why I like HASS.IO so much. I will hate the day when they start close source it and start charging.

Thank you for steering me in the right direction - much appreciated!

Sounds good. Ask away, there are lots of people on this forum with a lot of knowledge.

One item that tripped me up with my remote instance.

My main instance is as follows. Note I use 127.0.0.1 for the broker as I run my MQTT server on the same Pi as my main instance. If you run your broker on another Pi/Computer use the IP of that machine.

mqtt:
  broker: 127.0.0.1
  port: 1883
  client_id: home-assistant-1
  username: !secret mqttusername
  password: !secret mqttpassword

My remote instance looks like this.

Note that this one points to the IP of the main instance where my MQTT broker is running. Also note that it has a different client ID. This tripped me up in the beginning. New client ID for each instance.

mqtt:
  broker: 192.168.1.24
  port: 1883
  client_id: home-assistant-2
  username: !secret mqttusername
  password: !secret mqttpassword
1 Like

See, this is where I got lost with MQTT, I am from a server/client it background, so BROKER is the SERVER, right? and all the slaves will be clients plumbing back into the broker/server/main instance?

Think of the broker as the message board. Everything posts to that message board and everything reviews the status of the messages on that single message board.

A sensor, for example, like I linked above. Is just watching that single message board for anything pertaining to the state topic it was told to watch.

Hope that makes since, when I started thinking of it like this It really helped me understand MQTT.

OK: MQTT will be the next crocodile I will wrestle and tame with bare hands on a Sunday morning, before breakfast - challenge accepted!

Thank you.

Hi @silvrr

OK, I think this crocodile of a MQTT is getting the better of me, this is what I have:

On the main/master HASS.IO RPi configuration.yaml file I have:

mqtt:
  port: 1883

(I have tried the username and password as you suggested, but I am keeping it simple to start with)

On the second/slave RPi, I have this in the configuration.yaml file:

mqtt:
  broker: 192.168.0.62
  port: 1883
sensor: !include sensors.yaml

(where .62 is the main RPi)

And in the sensors.yaml file on the second/slave RPi I have:

  - platform: dht
    sensor: AM2302
    pin: 4
    monitored_conditions:
      - temperature
      - humidity

  - platform: mqtt
    state_topic: 'remote/sensor/dht_sensor_temperature/state'
    name: "Temperature"
    unit_of_measurement: "°C"

  - platform: mqtt
    state_topic: 'remote/sensor/dht_sensor_humidity/state'
    name: "Humidity"
    unit_of_measurement: "%"

Now, on the second/slave RPi I can see the following entries on the ‘Overview’ screen:

DHT Sensor Humidity -> this displays a value xx.x%
DHT Sensor Temperature -> this displays a value of xx.xx °C
Humidity -> no value
Temperature -> no value

On the main RPi - cannot see any values/entries from the slave, so I assume nothing is sent via MQTT from slave to master?

The logs on the slave is clean, but on the main RPi I get this:

2018-01-20 22:32:55 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File “/usr/lib/python3.6/asyncio/tasks.py”, line 180, in _step
result = coro.send(None)
File “/usr/lib/python3.6/site-packages/hbmqtt/broker.py”, line 342, in stream_connected
yield from self.client_connected(listener_name, StreamReaderAdapter(reader), StreamWriterAdapter(writer))
File “/usr/lib/python3.6/site-packages/hbmqtt/broker.py”, line 357, in client_connected
handler, client_session = yield from BrokerProtocolHandler.init_from_connect(reader, writer, self.plugins_manager, loop=self._loop)
File “/usr/lib/python3.6/site-packages/hbmqtt/mqtt/protocol/broker_handler.py”, line 129, in init_from_connect
connect = yield from ConnectPacket.from_stream(reader)
File “/usr/lib/python3.6/site-packages/hbmqtt/mqtt/packet.py”, line 228, in from_stream
variable_header = yield from cls.VARIABLE_HEADER.from_stream(reader, fixed_header)
File “/usr/lib/python3.6/site-packages/hbmqtt/mqtt/connect.py”, line 104, in from_stream
protocol_name = yield from decode_string(reader)
File “/usr/lib/python3.6/site-packages/hbmqtt/codecs.py”, line 65, in decode_string
length_bytes = yield from read_or_raise(reader, 2)
File “/usr/lib/python3.6/site-packages/hbmqtt/codecs.py”, line 54, in read_or_raise
raise NoDataException(“No more data”)
hbmqtt.errors.NoDataException: No more data

The above makes no sense to me at all, is there anything else that needs doing on the main or slave for seeing data on the main RPi?

Any help would be appreciated!

Ok, first, I don’t know Hassio so you will have to look up the answer for this. Is a MQTT broker installed on your main instance? If so then proceed to below. If not youve got to figure that out on HASSio

Remote instance config:

mqtt_statestream:
  base_topic: remote

mqtt:
  broker: 192.168.1.24
  port: 1883
  client_id: home-assistant-2
  username: username
  password: password

sensor:
  platform: dht
  sensor: DHT22
  pin: 4
  monitored_conditions:
    - temperature
    - humidity

That is the pertinent information. You setup your sensor like normal. Make sure it is working and displaying the correct output on the front end. Then setup MQTT and point it towards the broker on your main instance (192.168.1.24 in my case). Finally the MQTT state stream component is added and that sends every update of the DHT22 sensor. Select a unique base topic for this pi.

mqtt:
  broker: 127.0.0.1
  port: 1883
  client_id: home-assistant-1
  username: username
  password: password

Sensor:
  - platform: mqtt
    state_topic: 'remote/sensor/dht_sensor_temperature/state'
    name: "Temperature"
    unit_of_measurement: "°F"

  - platform: mqtt
    state_topic: 'remote/sensor/dht_sensor_humidity/state'
    name: "Humidity"
    unit_of_measurement: "%"

On the main instance you need MQTT setup. Then you setup the sensors on the main instance. The state topic then starts with the base topic you chose on the remote instance. (remote in my case) Then the platfrom in HA (sensor in this case). Then the entity name from the remote instance (dht_sensor_humidity) in this case.

From there it should be working.

I used this vidieo (which is setup based on hassbian) for setup. You don’t want to follow it but at the end there is info on testing the MQTT broker. Basically send a message to the broker and watch it come up on the subscription.

Hope that helps!

1 Like

Hey @silvrr - he shoots, he scores - thank you!!!

The penny just dropped! The one single issue I has was the ‘remote’ base_topic bit! Could not figure out what exactly it was for, but with the info above it all makes sense now!

I have been looking all over this today and now that you explained it, data is flowing and all is good in the (my) world!

Thank you very much - seriously appreciate the explanation and info!!!

Glad you got it working!

trying to do the same. But both remote and main are using HASSIO.

In HASSIo you use

mqtt:
  broker: 172.17.0.1

although my main is 192.168.1.12 and remote 192.168.1.238

how to solve this, possible?

Not framiliar with HASSio but…

The main instance should point to the loopback address for HASSio (assuming this is where your broker is running). If you have MQTT setup and working currently then it looks like 172.17.0.1 is correct.

On the remote instance is appears you would point to 192.168.1.12 if your broker is on the main HASSio instance. You want to use the IP address of your Pi where the broker is running.

I do not understand this.

My HASSIo on NUC address is 192.168.1.12
My HASSIO on pi3 address is 192.168.1.238

On both configuration.yaml I have
mqtt:
broker: 172.17.0.1

172.17.0.1, I think is a loopback address for Hassio, it just is looking at the broker running on the same machine.

You should only have one broker running. Whichever instance is running your broker should point to 172.17.0.1. The instance that is not running the broker should point to the instance running the broker.

is this mandatory?

Thing is that I use my HASSIo-PI3 as backup HA machine, if I do as you say I break many things (related to mqtt) on that machine

as zwave now I have on the “remote” unit

  • sensor
  • switch

my goal is to bring the values of the sensor and the status of the switch to the main instance. And from the main instance control the switch on the remote

I should have been more clear, there needs to be one broker that the remote instance is posting to and that the main instance is monitoring for updates. If your remote instance is posting to its own MQTT ‘message board’ and your main instance is monitoring its own ‘message board’ you will never have anything happen between the instances.

That being said, I think you will run into some difficulties having multiple brokers, I don’t know if HA is setup to monitor multiple brokers at the same time.