Raspberry Pi GPIO

Hello,

My current HA is setup on an ubuntu VM. I have just purchased a Pi to play with some home automation projects.

To control the GPIO on the Pi does HA have to be installed directly on the Pi its self? Or can I control the GPIO from my Ubuntu installation over my local LAN?

Regards
Ross

you could run an additional copy of HA on the pi using the mqtt eventstream component to allow the two to talk to each other

I did look into that approach and looks like the best way forwards.

Do I need to have home assistant installed on the Pi too then? Can I not just install MQTT on the Pi and have it talk back to HA on my ubuntu VM?

To use GPIO components, HA has to be running on the PI.

The best approach would be to have your devices/programs on your PI communicate to HA either through MQTT or the HA rest API.

Personally, I prefer MQTT as it is supported by many systems, and I have easily switch from OpenHab to HA as a result.

Running as second HA instance is overkill in this situation.

Ah ok,

So just to make sure I understand this this is how I picture it in my head now.

I have my main HA on an Ubuntu VM

I will then also install HA and MQTT on the Raspberry Pi to control the GPIO pins on the board.

Lets say I want to control a Relay on the Pi, I will setup in the HA configuration.yaml file on the Pi to trigger the relay using MQTT.

Back at my Ubuntu HA install, I will setup an on off switch to send a MQTT request to the Pi which will then trigger the Home assistant switch I setup on the Raspberry Pi’s home assistant?

Is that correct?

Almost, but without the second HA instance, which is unncessary if you use MQTT. I suggest you have your programs on the PI communicate directly with your one HA installation on Ubuntu, through MQTT.

I suggest you set up an MQTT broker (such as mosquitto or mosca or use the one built in to HA) on the Ubuntu Server.

For relays on the Pi, the program running on the pi will ‘subscribe’ to messages from the broker.

On your HA install, set up an MQTT switch to send an MQTT message to the broker, which will distribute it to whichever programs have subscribed to listen to that message.

Right…

I got confused because you said I also need HA installed on the Pi to be able to control the GPIO pins.

So I can just install MQTT on the Pi and then have MQTT installed also on the ubuntu box to send the MQTT requests to the MQTT server on the Pi which will trigger a GPIO pin to set off a relay?

You can control the IO pins from any program. Duplicating all of HA on the Pi just to do that is overkill.

I guess I need to step back and make sure that when you said you wanted to ‘play with some home automation projects’, you are quite happy doing a little coding, because I am actually suggesting you write, or more likely find and modify, a program to subscribe to the MQTT messages and update the GPIO pins.

A quick internet search shows the code at the end of this thread is doing almost what you want, so you would need to copy this it and modify it. You may be able to find another program closer to your needs if you search more.

I hope I haven’t make this look too daunting - it really isn’t, but it seems a far better approach than duplicating HA just to control GPIO pins.

Hey,

I only got the PI yesterday but I managed to setup a basic circuit using an LED connected to a breadboard and write a small python script to flash the LED on and off.

Looking at the code on the link you provided it seems I just add the MQTT bit I need to that same python file so that it responds to the MQTT requests from the Ubuntu HA switch?

That’s it.:slight_smile:

Great,

Ill give that a go and see how I get on over the weekend :slight_smile: Thanks for your help!

Publish your code here when you’re done!