Integrating BrewBlox with Home Assistant?

I use both BrewBlox and Home Assistant (HA) and I’m happy with them both. I’d be ‘delighted’ if I could take the data from BrewBlox live and sense it in Home Assistant :slight_smile: This would allow me to do alarms and other automation that HA does naturally. Both use MQTT, both are likely to be used by people at home, so I think it’s a good fit.

Has anyone done any work on this or maybe knows how to shoot the BrewBlox MQTT data off to another MQTT server?

My solution is to use node-red and the BrewBlox api. But if anyone have a solution that uses the MQTT directly I’m also interested.

https://www.home-assistant.io/docs/mqtt/discovery/ seems the relevant approach for sharing data brewblox -> HASS.

https://www.home-assistant.io/docs/mqtt/broker/ suggests that if you want to, you can reuse the brewblox MQTT broker for HASS.

I could have a look at setting up a relay service that unpacks MQTT messages from the Spark, transforms them, and publishes the result to a different broker + topic.

This would require some more specific use cases on how you want to use it. I’m only vaguely familiar with HASS myself.

Thanks guys. Bob, I’m using the MQTT provided with HA to do discovery and control of switches, so that works very neatly. I’ve not had a problem with that. I had in mind trying to push BrewBlox data to that MQTT, so your relay suggestion would certainly make sense to me and would provide a link for other Automation systems too.

I did use my own MQTT broker ages back as the HA one had issues (for me anyway). Those have been sorted out some time back and the inbuilt add on for MQTT is very solid. So is the one with BrewBlox too :slight_smile:

I’d prefer to use the relay idea to keep things separate, but I suspect you have a bunch of higher priority work on currently!

HA and BrewBlox run on the same docker host, so I’m hoping it would be quite easy to flick over and at least try it out. So I’d be up for trying to access the BrewBlox MQTT as the master one - is there anything that indicates how to do this from an external app? I’ve really used BrewBlox as a black box that does everything without trying to access any of the internals.

Kristianj - thanks for the thought. I’d like to avoid too many changes to my at this point.

David

Disable the HA broker, and run brewblox-ctl service expose eventbus 1883:1883.

That depends on how much work it’d be. Can you describe what data you’d want from brewblox, and what messages should be sent to HA?

Sure thing. What I had in mind was that BrewBlox would expose all the sensors it has to MQTT for discovery by HA and subsequent updates. I only really have experience of BrewBlox in a simple fridge, so seeing sensors called Fridge Setting and current value, Heat PWM value and Heat Pin State would be good starting points. If I can see those in HA, then I could try something like setting up an HA automation which sends an alarm if the current value was less than (say) 15 degrees (in case something has gone wrong). Or looking at an unused air temperature 1-wire sensor and using that to display the temperature in HA of a bread warming box I’ve made up.

Sure one could go much further and try to feed actions back into BrewBlox, but I would think a read only interface to current BrewBlox sensor values would be what most people would need and would be very safe.

I’ll make an issue to set up a service that publishes sensor values, setpoint settings, digital actuator states, and PWM values.
Those can be filtered automatically by type, and do not require user configuration.

Not sure about ETA. Filtering and publishing the data is ~1h work, but setting up and testing the HA side will take longer.

Great news Bob. I’d be very happy to do any testing you need :slight_smile:

I am a HA user as well and have a Eclipse Mosquito MQTT broker running (HA and BrewBlox run on separate Pis) https://hub.docker.com/_/eclipse-mosquitto. Happy to test to provide any HA how-to documents. My requirements are the same as @david.medland-slater.

The brewblox eventbus service is a mosquitto broker where we enabled MQTT over websockets.

If I understand docs correctly, then assuming the existence of Ferment Fridge Sensor and Ferment Beer Sensor on service spark-one, we’d first want to publish to:

topic:
homeassistant/sensor/brewblox/spark-one__Ferment_Fridge_Sensor/config
data:

{
  "device_class": "temperature", 
  "name": "Ferment Fridge Sensor",
  "state_topic": "homeassistant/brewblox/spark-one/state", 
  "unit_of_measurement": "°C", 
  "value_template": "{{ value_json.Ferment_Fridge_Sensor }}" 
}

topic:
homeassistant/sensor/brewblox/spark-one__Ferment_Beer_Sensor/config
data:

{
  "device_class": "temperature", 
  "name": "Ferment Beer Sensor",
  "state_topic": "homeassistant/brewblox/spark-one/state", 
  "unit_of_measurement": "°C", 
  "value_template": "{{ value_json.Ferment_Beer_Sensor }}" 
}

Then every time data is published, we publish

topic:
homeassistant/brewblox/spark-one/state
data:

{
  "Ferment_Fridge_Sensor": 20.7,
  "Ferment_Beer_Sensor": 21.35
}

Edit: turns out that HA has a functional docker image, so setup was trivial. I manually published some test messages, and my assumptions about configuration appear to be mostly correct (I updated the config in post).

I pushed out a proof of concept: it publishes all sensors and setpoints.

To add it to brewblox, edit your docker-compose.yml file, and add a service

  hass:
    image: brewblox/brewblox-hass:develop
    restart: unless-stopped

If your MQTT broker lives on another host, add

    command: '--hass-mqtt-host=HOSTNAME'

If the concept works, I can add data from various other block types, but any significant work will have to happen at a later time.

1 Like

So fast :slight_smile:

To avoid doing an update, I did a brewblox-ctl service pull hass
and got an error as shown below. A full restart did the same thing. In the end I did do an upgrade, but got the same message about the manifest. Any thoughts on what I’ve missed out Bob?

Pulling hass … error

ERROR: for hass manifest for brewblox/brewblox-hass:develop not found: manifest unknown: manifest unknown
ERROR: manifest for brewblox/brewblox-hass:develop not found: manifest unknown: manifest unknown
Command ‘docker-compose pull hass’ returned non-zero exit status 1.

Looks like I forgot to add it to the list of automatically built images. I rectified that now, and the build should be done about 10 mins from now.

Yes, that would be the best way to go about it.

Edit to show log file upload is here:
https://termbin.com/40rkv

OK good progress - the unless_stopped needs to be an unless-stopped and the service started up OK. I cannot see any logins on the HA mqtt add-on from the BrewBlox side. Other services which use this like OpenZwave are pushing data through as they usually do.

On the BrewBlox hassio container, I can see the following if this helps at all:

2020/10/05 22:30:56 INFO     brewblox_service.service        Service name: hass,
2020/10/05 22:30:56 INFO     brewblox_service.service        Service info:  @ Mon Oct  5 20:28:07 UTC 2020,
2020/10/05 22:30:56 INFO     brewblox_service.service        Service config: {'host': '0.0.0.0', 'port': 5000, 'bind_http_server': True, 'output': None, 'name': 'hass', 'debug': False, 'eventbus_host': None, 'eventbus_port': None, 'mqtt_protocol': 'mqtt', 'mqtt_host': 'eventbus', 'mqtt_port': None, 'mqtt_path': '/eventbus', 'history_topic': 'brewcast/history', 'state_topic': 'brewcast/state', 'hass_mqtt_protocol': 'mqtt', 'hass_mqtt_host': 'eventbus', 'hass_mqtt_port': None, 'hass_mqtt_path': '/eventbus'},
2020/10/05 22:30:56 INFO     brewblox_service.mqtt           Starting <EventHandler for mqtt://eventbus:1883>,
2020/10/05 22:30:56 INFO     brewblox_service.mqtt           listen(brewcast/state/#),
2020/10/05 22:30:56 INFO     brewblox_service.mqtt           subscribe(brewcast/state/#),
2020/10/05 22:30:56 INFO     brewblox_service.mqtt           <EventHandler for mqtt://eventbus:1883> connected,
2020/10/05 22:30:56 INFO     brewblox_hass.relay             Received 17 blocks from spark-one,
2020/10/05 22:30:56 INFO     brewblox_hass.relay             publishing new sensor: Air Sensor,
2020/10/05 22:30:56 ERROR    brewblox_service.mqtt           Exception handling MQTT callback for brewcast/state/spark-one: ConnectionError(Publish error="The client is not currently connected.", topic="homeassistant/sensor/spark-one__AirSensor/config"),
2020/10/05 22:31:00 INFO     brewblox_hass.relay             Received 17 blocks from spark-one,
2020/10/05 22:31:00 INFO     brewblox_hass.relay             publishing new sensor: Air Sensor,
2020/10/05 22:31:00 INFO     brewblox_hass.relay             publishing new sensor: Fermentor Sensor

You mentioned you were using a separate mosquitto instance for HA? You’ll need to use the --hass-mqtt-host argument to set that. By default, the hass service pushes events to the brewblox eventbus.

To get a detailed view at what’s being sent, I can recommend http://mqtt-explorer.com/.

Thanks Bob. In that past I did use another MQTT, but I’ve been using the HA ad-on one for some time now. The add-on and it’s configuration is this one:

Another add on which uses this ‘inbuilt’ mqtt add-on is OpenZwave which has no specific configuration if you are using the MQTT of HA. I think that is the same setup as you use.

Leave it with me to use the tool you mentioned - many thanks for the steer and I’ll report back.

Here is where I have got to so far. Just to recap on the setup. I have a machine with hostname dockerarch running docker with both BrewBlox and HA installed with their respective standard setups. If I specify the hass service with no hass-mqtt, the log file for the BrewBlox hass service shows:

2020/10/06 08:40:07 INFO     brewblox_service.service        Service config: {'host': '0.0.0.0', 'port': 5000, 'bind_http_server': True, 'output': None, 'name': 'hass', 'debug': False, 'eventbus_host': None, 'eventbus_port': None, 'mqtt_protocol': 'mqtt', 'mqtt_host': 'eventbus', 'mqtt_port': None, 'mqtt_path': '/eventbus', 'history_topic': 'brewcast/history', 'state_topic': 'brewcast/state', 'hass_mqtt_protocol': 'mqtt', 'hass_mqtt_host': 'eventbus', 'hass_mqtt_port': None, 'hass_mqtt_path': '/eventbus'},
2020/10/06 08:40:07 INFO     brewblox_service.mqtt           Starting <EventHandler for mqtt://eventbus:1883>,
2020/10/06 08:40:07 INFO     brewblox_service.mqtt           Starting <EventHandler for mqtt://eventbus:1883>,
2020/10/06 08:40:07 INFO     brewblox_service.mqtt           listen(brewcast/state/#),
2020/10/06 08:40:07 INFO     brewblox_service.mqtt           subscribe(brewcast/state/#),
2020/10/06 08:40:10 INFO     brewblox_service.mqtt           <EventHandler for mqtt://eventbus:1883> connected,
2020/10/06 08:40:10 INFO     brewblox_service.mqtt           <EventHandler for mqtt://eventbus:1883> connected,
2020/10/06 08:40:25 INFO     brewblox_hass.relay             Received 17 blocks from spark-one,
2020/10/06 08:40:25 INFO     brewblox_hass.relay             publishing new sensor: Air Sensor,

To me this indicates that if you don’t put an explicit external mqtt server, the relay is reading from mqtt://eventbus:1883 and writing to the same place.

If I add the command: ‘–hass-mqtt-host=dockerarch’ to the docker-compose.yml (i.e. still pointing to the same host as runs docker with both apps installed, then I get the following in the hass_1 log:

2020/10/06 08:53:17 INFO     brewblox_service.service        Service name: hass,
2020/10/06 08:53:17 INFO     brewblox_service.service        Service info:  @ Mon Oct  5 20:28:07 UTC 2020,
2020/10/06 08:53:17 INFO     brewblox_service.service        Service config: {'host': '0.0.0.0', 'port': 5000, 'bind_http_server': True, 'output': None, 'name': 'hass', 'debug': False, 'eventbus_host': None, 'eventbus_port': None, 'mqtt_protocol': 'mqtt', 'mqtt_host': 'eventbus', 'mqtt_port': None, 'mqtt_path': '/eventbus', 'history_topic': 'brewcast/history', 'state_topic': 'brewcast/state', 'hass_mqtt_protocol': 'mqtt', 'hass_mqtt_host': 'dockerarch', 'hass_mqtt_port': None, 'hass_mqtt_path': '/eventbus'},
2020/10/06 08:53:17 INFO     brewblox_service.mqtt           Starting <EventHandler for mqtt://eventbus:1883>,
2020/10/06 08:53:17 INFO     brewblox_service.mqtt           Starting <EventHandler for mqtt://dockerarch:1883>,
2020/10/06 08:53:17 INFO     brewblox_service.mqtt           listen(brewcast/state/#),
2020/10/06 08:53:17 INFO     brewblox_service.mqtt           subscribe(brewcast/state/#),
2020/10/06 08:53:25 INFO     brewblox_service.mqtt           <EventHandler for mqtt://eventbus:1883> connected,
2020/10/06 08:53:34 INFO     brewblox_hass.relay             Received 17 blocks from spark-one,
2020/10/06 08:53:34 INFO     brewblox_hass.relay             publishing new sensor: Air Sensor,
2020/10/06 08:53:34 ERROR    brewblox_service.mqtt           Exception handling MQTT callback for brewcast/state/spark-one: ConnectionError(Publish error="The client is not currently connected.", topic="homeassistant/sensor/spark-one__AirSensor/config"),
2020/10/06 08:53:39 INFO     brewblox_hass.relay             Received 17 blocks from spark-one,
2020/10/06 08:53:39 INFO     brewblox_hass.relay             publishing new sensor: Air Sensor,
2020/10/06 08:53:39 ERROR    brewblox_service.mqtt           Exception handling MQTT callback for brewcast/state/spark-one: ConnectionError(Publish error="The client is not currently connected.", topic="homeassistant/sensor/spark-one__AirSensor/config"),

To me this indicates the relay is reading from the BrewBlox eventbus and writing to the HA mqtt, but hasn’t connected and so gets rejected. I hooked up the mqtt-explorer (very handy, thanks once again), on the same docker host and directed it to use docker-arch:1883. If I do this, no traffic is shown at all. However, if I create a username and password on the HA mqtt and connect with mqtt-explorer using that username and password, I get see regular HA mqtt traffic. (Hurrah!)

So it looks to me as though if you don’t specify an mqtt host with the hass service, the relay doesn’t connect and write internally to the HA mqtt, but instead connects and writes to the BrewBlox eventbus. If you explicitly point to the docker host:1883, then HA rejects the client connection without a username and password.

I suspect from your explanation Bob, this behavior is unexpected and that with no explicit mqttt_host on the service, the relay should read from the BrewBlox eventbus and write to the HA mqtt? I’m not seeing that, but if there turns out to be a way of adding a username/password to the connection request to the HA explicitly specified mqtt, I bet it would burst into life.

I’d have to add support for setting username and password on mqtt, but that’s no big deal.

The issue with eventbus vs dockerarch is caused by docker networking settings.

You’re running the hass and eventbus services in the same compose. This means they are connected to the same docker-generated network (probably called brewblox_default_1). In this network, port 1883 is open on the eventbus service, but ports opened to this network are not accessible on the host by default.

If you set dockerarch as host, then it tries you access the host, not the eventbus service directly.
You can choose to let the eventbus service listen on a host port, but these settings are not currently present in your docker-compose.yml file.

Depending on preferences, I can add some arguments to the hass service for username/password login, or you can disable the mqtt broker in HA, and run
brewblox-ctl service expose eventbus 1883:1883
to equalize eventbus:1883 and dockerarch:1883.

Thanks for that Bob - I think adding a username/password would be a better option as that gives HA users, and other home automation products using mqtt, the choice. Not everyone would be comfortable with anonymous logins and having that choice will make it more likely people give this a go.

If there is a more elegant way of installing BrewBlox which avoids this problem and allowing it to use the HA mqtt without a login, especially for a proof of concept, I’d be happy to do that. I didn’t consciously chose to install ‘in the same compose’. I installed HA following their method, followed the BrewBlox install in a the same way and that’s how I got to where I am. I’m happy to reinstall BrewBlow another, ‘better’ way.

Either works for me as I suspect you will get feedback from other interested parties too.

Oh, it wasn’t a problem. Being ‘in the same compose’ means nothing more than that the hass and eventbus services are defined in the same docker-compose.yml file, and have access to the same network.
The isolation offered by docker-compose is part of why we use it. It allows us to (for example) run multiple spark services without having to worry about port conflicts.

I added a quick local fix for setting username/passwd.
You can set the username/password in brewblox/.env, where they won’t be logged in brewblox-ctl log:

HASS_MQTT_USERNAME=changeme
HASS_MQTT_PASSWORD=changeme

To use the values, add the following configuration to the hass service in docker-compose.yml:

   environment:
     - HASS_MQTT_USERNAME
     - HASS_MQTT_PASSWORD