Controlling LEGO hubs: a mqtt2pybricks gateway

This post is part 1 of 1 of  mqtt2pybricks gateway
  • Controlling LEGO hubs: a mqtt2pybricks gateway

We finally moved to a new home. Not an apartment on a 6th floor with dozens of crazy and noisy neighbors but a real house with a garden and a garage.

I also quit my job and I am taking a rest. So I finally have both time and opportunity to look into domotics.

I installed OpenHAB on a Raspberry Pi and started adding ‘things’ to get familiar with it. The first was a Nedis dehumidifier I bought a few months after moving – we moved to a place with its own micro-weather, lots of humidity, and my wife and the younger kid have allergies problems so I’m trying to keep humidity levels low.

Although the dehumidifier has builtin wi-fi we were using it just on manual mode but since it was easy to integrate with OpenHAB I started with it.

OpenHAB offers ‘bridges’ for several types of devices. This dehumidifier is a Tuya device so I added a Tuya bridge and found that I could read humidity and temperature values even when the dehumidifier was in standby mode (previously, to know the humidity level of the room I needed to turn it on to be shown on the display and just humidity, no temperature readings).

So I ordered two Tuya humidity+temperature sensors to monitor our bedroom and the #2 bedroom.

And then I added a older humidifier to OpenHAB through an also older wi-fi power plug. The humidifier has a ‘mechanic’ power switch so I left it always ON and control it from the power plug.

And then the third humidifier. But this one has a ‘digital’ power switch so you need to press it to turn it ON/OFF. And no builtin wi-fi. So a fingerbot-like gadget was needed. I chose a Switchbot Bot:

It is a Bluetooth BLE device, is supposed to be used with the SwitchBot Hub that works as a wi-fi to BLE gateway but I found a description of its API so used python to control it and created my own mqtt2switchbot gateway with a Raspberry Pi Zero 2W (using ‘bleak’ and ‘pahoo-mqtt’) and adding a MQTT broker to my OpenHAB server.

So I can control Bluetooth BLE devices from my domotics central.

And LEGO Hubs are BLE devices.

So the next obvious step was controlling LEGO from my domotics central 😀

2 comentários em “Controlling LEGO hubs: a mqtt2pybricks gateway”

  1. Hello,
    Excuse me for abruptly interrupting.
    I read “Decoding old LEGO infrared protocol” article with great interest.
    I was looking for information on controlling a 9V RC train with a Raspberry pi and came across this article.

    I tried to acquire a signal with Lirc as in your method, but the signal was not stable and the acquired Raw Data could not be used.
    PF control is working well with Lirc.
    I used your git hub project ‘Lego Old RC.conf’ but the 9V RC did not respond.
    Is the code for the 7897 9V RC train different from the code for the LEGO Old RC?
    Could you please let us know if you know the code for the 9V RC?

    1. Hello.
      This post is very old and I don’t remember all the details (and don’t have the equipment with me to confirm) but I think that never tested the old train remote. It is probably using a minor variation of the values used with the other 9V RC devices, like it happens with PF IR where you have a remote for trains that sends commands that keep the motor running.
      LIRC is also very old now… this days, I would look for a custom github project for Arduino or for the Pi to reliable capture the IR codes.

Deixe um comentário

O seu endereço de email não será publicado. Campos obrigatórios marcados com *