Extending the raspberry GPIO pins

I am on a single raspberry and HA is installed on it in a virtual environment on Rapsbian.

I have reached a point where I have occupied all of the GPIO pins :stuck_out_tongue:
I have ds18b20 sensors (they require a single pin) and I have 16 reed switches for my doors and windows.

Now, I need more pins to add more sensors (PIRs are my next step and who knows what else in the future)
I already have a second raspberry sitting in my drawer and I have no use for it.
What is the best approach to have it reading the extra pins I need for HA to handle?
I dont have MQTT because I havent fully understood it so I didnt bother since everything I want is working perfectly without it. From a little search I have done in this forum, it looks like I have to install HA on the 2nd RPI and have it send the status of the pins via MQTT.
I dont mind setting MQTT but I would like to avoid it if there is another way. Unless someone cares to explain to me why it is useful, safe and how it works.

There are plenty of guides to MQTT on the internet, but this is one I have a link to

You can do it that way, but its a very heavyweight approach. All you are doing is getting the state of gpio pins and sending MQTT messages, and using HA to do just that is overkill. This project does exactly what you need, and no more
flyte/pi-mqtt-gpio: Expose the Raspberry Pi GPIO pins over MQTT. Also works with external GPIO modules such as the PCF8574 chip.

1 Like

Thank you very much for the guides! They are very helpful! I now understand how it works! Do you use MQTT? Any suggestions on which broker I should use? Anything else I should be aware of before I start expanding my GPIO pins this weekend?

I along with most people here, use mosquitto

sudo apt install mosquitto

is all you need to get it running. You can add passwords if you like, but it seems unnecessary on a local network.

If you are running HA on the same machine as the broker, you can use localhost as the address in configuration.yaml

mqtt:
    broker: localhost

The best way of debugging mqtt is to follow the messages with a client. mosquitto_sub or mqtt.fx are popular clients, and if you subscribe to topic # you see all the messages being sent to the broker.

to install mosquitto_sub

sudo apt install mosquitto-clients
1 Like

Alright, Yesterday I freshly installed raspbian on my spare RPI and have it updated to the latest version.
I installed mosquitto too.

I now have some questions, please bare with me:

I havent connected any sensors yet, but I am trying to publish my CPU temperature over mqtt and have HA read this.
I read your guide and I understood all the theory behind MQTT.
But now as I am starting to practicing with it I am getting confused.
I am trying to figure out how to create topics.
2 Theories are in my head right now:

  • The topic is auto created when I publish something from a sensor.
  • The topic has to be pre defined on a file I cant seem to find…

Edit: I was preparing a full set of questions but I accidentally clicked the post button and there you go… :smile:

I will ask more later :slight_smile:

There is no configuration file to define topics. Topics are defined when they are sent by the client.