I recently tried out a setup with my unipi neuron L303 with home assistant, a python-based open-source framework for integrating various IoT and home automation devices and services. Since it did turn out to be actually quite simple, I figured to share it here.
The general idea is to use the unipi neuron modbus server for accessing all I/O on the neuron. Home assistant can then communicate with its own hass modbus integration
Unipi neuron modbus server
The picture in this post helped a lot: basically, I had a (headless) raspbian stretch image where I installed evok on, which also installs the unipi neuron modbus server. As I understood it, all I/O on the I/O boards are connected over SPI and are continuously polled. The modbus TCP overlay is just a way to expose this information.
Home assistant setup
Installing home-assistant on the unipi is rather straightforward as it's specifically targeted for platforms such as the raspberry pi. The official hass installation docs now prefer you to use their docker-based installation hass.io. While I do like this idea (and will use this myself on the longer term), for testing purposes I decided to just use the old-style python-pip based installation.
Install pip (python package manager) for python3.
apt-get install python3-pip
Home assistant requires some specific python3-based features (e.g. async handling of events with
asyncio) ... and you should use python3 anyway.
Install home assistant
pip3 install --user homeassistant
--user option installs it in a folder of your own user.
Start running it:
You can now access it under
$NEURON_IP:8123 (default hass port)
When adding an integration (such as modbus), home assistant will automatically install the required dependencies for it (such as pymodbus).
Home assistant configuration
Now, how to glue these two together. Home assistant uses simple .yaml files for configuration. The main config file is
configuration.yaml; see hass configuration.yaml for more details. My config file was under
I did add the following lines to this file specifically for modbus (comments added)
# register the modbus-tcp platform
host: 127.0.0.1 # localhost; just check on this machine
port: 502 # default port number from modbus tcp neuron overlay
slave: 1 # field is required -- but not checked for modbus TCP
scan_interval: 0.1 # polling speed
- name: User programmable LED X1
coil: 8 # modbus register mapping
- name: User programmable LED X2
- name: User programmable LED X3
- name: User programmable LED X4
# reading a digital input
- platform: modbus
- name: Digital Input 21
This is only just a test setup where I can control the 4 test leds on the neuron and read out one of the digital inputs.
I was actually amazed myself how simple the setup was to integrate both platforms -- so great work on the hardware and the modbus TCP server overlay.
This was just a test setup for me, some more things I'd like to check:
- polling speed: the inputs respond rather slow atm, so I'd like to check how to increase the speed there. I'm curious where the bottleneck is; on the SPI polling or on home assistant polling the modbus server itself. On SPI level, I am curious whether it is possible to have more of a interrupt-based system.
- inputs as actual push buttons: the inputs should really toggle, rather than follow the input value. I know it's possible to manage this simply in home assistant, couldn't find it directly
- outputs: haven't checked driving the outputs yet. Is it actually possible to directly drive e.g. a 24V LED strip from the digital outputs (not relays -- the L303 only has limited outputs)