Integrate Arduinos without modules plugged to a distant Raspberry

Hi everyone,

I have a bunch of arduino nano at hand (no bluetooth, wifi or ethernet modules left), and a raspberry pi wiredly connected to lan in a location out of wifi’s range.

I’m struggling to find how i could make the arduino’s pins available in Home Assistant through the USB conexion of the remote raspberry.
Some kind of USB Proxy ?
Has someone already achieved something similar ?

I know it would be much easier to extend wifi and buy some ESP32, or add modules to the nanos but i wonder if i can achieve the same with what i have at hand. I also have other single-use rpis on the network, on which i could apply the same setup to use all the nanos.

Thanks in advance

You could connect the remote PI to your instance via MQTT, Some of the stuff I have done:

GitHub - SirGoodenough/ThermoPI: Use a Raspberry PI connected to one or more temperature sensors to send the results to a Home Assistant Instance via MQTT Discovery..

GitHub - SirGoodenough/ThermoPI-Cottage: Python Script for sending 12 W1 1 wire sensors into a Home Assistant Instance via MQTT Discovery..

Thanks a lot, your were really helpful !

That made me realize that and how i could skip the microcontroller in many cases and use the rpi directly instead. I’ve tried with usb arduino too though cuz i’m bigheaded and wanted to confirm it would work :slight_smile:
Then, your projects are really clear to see where to start to go the MQQT way.

What do you mean with “too fast break things” in your comments @Sir_Goodenough ?
I’m still wondering how to adjust the py script to get some readings asap (from the rpi or an arduino), for instance to track physical button press or IR command received.
I’ve checked that the on2message MQTT consumption callback was not impacted by the sleep between readings in the main script. I’d like to achieve something similar by using timers to limit only sensors readings while reading and publishing other ones in “real time”.
Do you think that would break it ?

As for the possibilities, here’s the of options I’ve seen and.or tested so far :

Using pins of a remote Raspberry already in use (not HA OS)

  • I think the remote rpi gpio integration is no longer working… Shame that would have been easy to setup
    This is what made me try the secondary HA rpi before discovering your approach
  • Your approach with python and MQTT works like a charm with various sensors
    I’m still wondering how I would need to adapt it to get for some usecases

Using pins on a dedicated Remote Raspberry with (secondary) Home Assistant OS (and share entities)
Tried as a workaround to the non working integration, I’ll keep on looking into this setup as i think it could help to have this rpi as a “physical home assistant extender” with USB, wifi, bluetooth…

  • HACS compnents RPI Gpio
    For binary sensors readings and switches controlled by HAonly, it seems to work just fine and was really easy to setup.
    I didn’t test to use the pins as triggers (buttons) though
  • Your python/MQQT Approach
    Working fine here too, can be used on other sensors, and installed without issue on home assistant OS (no apt-get required, just some pip install for plugins)
  • Some Gpio devices dedicated integrations
    Such as 1 wire which should work out of the box with the DHT11 sensor I had laying around and used to test mqtt and arduino
    Not tested yet
  • GPIO IR receiver and emitter ?
    No success so far. I probably miss an obvious workaround.
    I was stuck on the device setup since all tutos i’m used to go through installs like “sudo apt-get install ir-keytable -y” which are not possible on this OS

Using Arduino plugged in USB to a rpi
I got it working by mixing your approach with python serial communication with the arduino
This is the tuto i used to mix it with your code

Probably not super robust but i had no issue so far
I’m still working on it to implement and test two-ways communication

  • On the duino, i just use :
    – Serial.println to output mys sensors data with some prefix that make it easy to filter and identify in python
    – Serial.readStringUntil to receive inputs from python (like commands for IR emission)
    – the arduino-timer library to expose sensors reading only periodically while it keeps listening for Serial inputs all the time
  • in Python i just had to
    – adapt the yaml to my settings needs (arduino mount path, serial baud speed),
    – replaced your rpi readings by Serial reading and value parsing
    – or the motor controls by serial inputs when receiving MQTT messages

Not sure if this is any help to you Firmata - Home Assistant