rpi2home-assistant 2.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. rpi2home_assistant-2.3.0/.github/workflows/docker-push.yml +27 -0
  2. rpi2home_assistant-2.3.0/.github/workflows/main.yml +67 -0
  3. rpi2home_assistant-2.3.0/.github/workflows/pypi-release.yml +51 -0
  4. rpi2home_assistant-2.3.0/.gitignore +6 -0
  5. rpi2home_assistant-2.3.0/Dockerfile +30 -0
  6. rpi2home_assistant-2.3.0/LICENSE +28 -0
  7. rpi2home_assistant-2.3.0/Makefile +136 -0
  8. rpi2home_assistant-2.3.0/PKG-INFO +201 -0
  9. rpi2home_assistant-2.3.0/README.md +182 -0
  10. rpi2home_assistant-2.3.0/config.yaml +166 -0
  11. rpi2home_assistant-2.3.0/docs/screenshot1.png +0 -0
  12. rpi2home_assistant-2.3.0/docs/seengreat-2ch-relay.png +0 -0
  13. rpi2home_assistant-2.3.0/docs/seq-microsystem-optoisolated-hat.png +0 -0
  14. rpi2home_assistant-2.3.0/docs/sunfounder-4ch-relay.png +0 -0
  15. rpi2home_assistant-2.3.0/poetry.lock +214 -0
  16. rpi2home_assistant-2.3.0/pyproject.toml +52 -0
  17. rpi2home_assistant-2.3.0/pytest.ini +5 -0
  18. rpi2home_assistant-2.3.0/renovate.json +6 -0
  19. rpi2home_assistant-2.3.0/requirements.txt +17 -0
  20. rpi2home_assistant-2.3.0/src/_raspy2mqtt_version.py +1 -0
  21. rpi2home_assistant-2.3.0/src/raspy2mqtt/__init__.py +0 -0
  22. rpi2home_assistant-2.3.0/src/raspy2mqtt/circular_buffer.py +122 -0
  23. rpi2home_assistant-2.3.0/src/raspy2mqtt/config.py +674 -0
  24. rpi2home_assistant-2.3.0/src/raspy2mqtt/constants.py +89 -0
  25. rpi2home_assistant-2.3.0/src/raspy2mqtt/gpio_inputs_handler.py +151 -0
  26. rpi2home_assistant-2.3.0/src/raspy2mqtt/gpio_outputs_handler.py +288 -0
  27. rpi2home_assistant-2.3.0/src/raspy2mqtt/homeassistant_status_tracker.py +100 -0
  28. rpi2home_assistant-2.3.0/src/raspy2mqtt/main.py +276 -0
  29. rpi2home_assistant-2.3.0/src/raspy2mqtt/optoisolated_inputs_handler.py +255 -0
  30. rpi2home_assistant-2.3.0/src/raspy2mqtt/stats.py +60 -0
  31. rpi2home_assistant-2.3.0/systemd/rpi2home-assistant.service +29 -0
  32. rpi2home_assistant-2.3.0/tests/__init__.py +0 -0
  33. rpi2home_assistant-2.3.0/tests/conftest.py +1 -0
  34. rpi2home_assistant-2.3.0/tests/docker-compose.yml +26 -0
  35. rpi2home_assistant-2.3.0/tests/integration-test-config.yaml +66 -0
  36. rpi2home_assistant-2.3.0/tests/mosquitto_container.py +154 -0
  37. rpi2home_assistant-2.3.0/tests/raspy2mqtt_container.py +48 -0
  38. rpi2home_assistant-2.3.0/tests/test_circular_buffer.py +162 -0
  39. rpi2home_assistant-2.3.0/tests/test_config.py +335 -0
  40. rpi2home_assistant-2.3.0/tests/test_integration_discovery.py +134 -0
  41. rpi2home_assistant-2.3.0/tests/test_integration_pubsub.py +165 -0
  42. rpi2home_assistant-2.3.0/tests/test_integration_reconn.py +70 -0
@@ -0,0 +1,27 @@
1
+ name: docker-push CI
2
+
3
+ on:
4
+ push:
5
+ # Pattern matched against refs/tags
6
+ tags:
7
+ - '*' # Push events to every tag not containing /
8
+
9
+ jobs:
10
+ docker_push:
11
+ runs-on: ubuntu-latest
12
+
13
+ steps:
14
+ - uses: actions/checkout@v4
15
+
16
+ - name: build and push Docker image
17
+ uses: mr-smithers-excellent/docker-build-push@v6
18
+ with:
19
+ # options related to BUILDing the docker image:
20
+ multiPlatform: true
21
+ platform: linux/amd64,linux/arm64,linux/arm/v7
22
+ image: rpi2home-assistant
23
+ addLatest: true
24
+ # options related to PUSHing the docker image:
25
+ registry: ghcr.io
26
+ username: ${{ github.actor }}
27
+ password: ${{ secrets.PAT_TOKEN_FOR_GITHUB }}
@@ -0,0 +1,67 @@
1
+ name: main CI
2
+
3
+ on:
4
+ push:
5
+ branches: [ main ]
6
+ pull_request:
7
+ branches: [ main ]
8
+
9
+ jobs:
10
+ # --------------------------------------------------------------------------
11
+ # build
12
+ # --------------------------------------------------------------------------
13
+ build:
14
+ runs-on: ubuntu-24.04
15
+
16
+ steps:
17
+ - uses: actions/checkout@v4
18
+ - name: install pypi-packaged dependencies
19
+ run: sudo pip3 install build
20
+
21
+ # test Python packaging
22
+ - name: package the pypi
23
+ run: |
24
+ python3 -m build
25
+
26
+ # --------------------------------------------------------------------------
27
+ # formatter_and_linter
28
+ # --------------------------------------------------------------------------
29
+ formatter_and_linter:
30
+ runs-on: ubuntu-24.04
31
+
32
+ steps:
33
+ - uses: actions/checkout@v4
34
+ - name: install pypi-packaged dependencies
35
+ run: sudo pip3 install black ruff
36
+ - name: run formatter
37
+ run: black . --check
38
+ - name: run linter
39
+ run: ruff check src/raspy2mqtt/
40
+
41
+ # --------------------------------------------------------------------------
42
+ # tests
43
+ # --------------------------------------------------------------------------
44
+ tests:
45
+ runs-on: ubuntu-24.04
46
+
47
+ steps:
48
+ - uses: actions/checkout@v4
49
+
50
+ # testcontainers 4.6.0 has introduced the MosquittoContainer, see
51
+ # https://github.com/testcontainers/testcontainers-python/releases/tag/testcontainers-v4.6.0
52
+ - name: install pypi-packaged dependencies for unit and integration tests
53
+ run: sudo pip3 install pytest 'testcontainers>=4.6.0' paho-mqtt aiomqtt schema
54
+
55
+ # FIXME: we should have all dependencies centralized in the TOML file and install them as:
56
+ # - name: Install dependencies
57
+ # run: |
58
+ # poetry install --no-interaction --with dev --all-extras
59
+ # poetry show --tree
60
+
61
+ - name: run unit tests
62
+ run: pytest -vvv -m unit
63
+
64
+ - name: build docker image
65
+ run: docker build -t rpi2home-assistant:latest .
66
+ - name: run integration tests
67
+ run: pytest -vvv --capture=no -m integration
@@ -0,0 +1,51 @@
1
+ name: pypi-release
2
+
3
+ on: push
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+
9
+ steps:
10
+
11
+ # setup python
12
+ - uses: actions/checkout@v4
13
+ - name: set up Python
14
+ uses: actions/setup-python@v5
15
+ with:
16
+ python-version: "3.x"
17
+ - name: install pypa/build
18
+ run: >-
19
+ python3 -m
20
+ pip install build --user
21
+
22
+ # package & store artifacts
23
+ - name: package the pypi
24
+ run: |
25
+ python3 -m build
26
+ - name: store the distribution packages
27
+ uses: actions/upload-artifact@v4
28
+ with:
29
+ name: python-package-distributions
30
+ path: dist/
31
+
32
+ publish-to-pypi:
33
+ # only publish to PyPI on tag pushes
34
+ if: startsWith(github.ref, 'refs/tags/')
35
+ needs:
36
+ - build
37
+ runs-on: ubuntu-latest
38
+ environment:
39
+ name: pypi
40
+ url: https://pypi.org/r/rpi2home-assistant
41
+ permissions:
42
+ id-token: write # IMPORTANT: mandatory for trusted publishing
43
+
44
+ steps:
45
+ - name: Download all the dists
46
+ uses: actions/download-artifact@v4
47
+ with:
48
+ name: python-package-distributions
49
+ path: dist/
50
+ - name: Publish distribution 📦 to PyPI
51
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,6 @@
1
+ dist/
2
+ src/raspy2mqtt/__pycache__/
3
+ tests/__pycache__/
4
+
5
+ # autogenerated by hatch-vcs:
6
+ src/_raspy2mqtt_version.py
@@ -0,0 +1,30 @@
1
+ # Stage 1: the builder
2
+ FROM python:3.11-slim AS builder
3
+
4
+ # NOTE: git is required to get the "hatch-vcs" plugin to work and produce the _raspy2mqtt_version.py file
5
+ RUN apt update && apt install -y git
6
+
7
+ WORKDIR /build
8
+ COPY requirements.txt pyproject.toml README.md /build/
9
+ ADD ./src ./src/
10
+ COPY ./.git ./.git/
11
+
12
+ RUN python -m pip install --upgrade pip
13
+ RUN pip install --target=/build/deps -r requirements.txt
14
+ RUN pip install build
15
+ RUN python -m build --wheel --outdir /build/wheel
16
+
17
+
18
+ # Stage 2: Create the final image
19
+ FROM python:3.11-slim
20
+
21
+ LABEL org.opencontainers.image.source=https://github.com/f18m/rpi2home-assistant
22
+
23
+ # install the wheel
24
+ WORKDIR /app
25
+ COPY --from=builder /build/wheel/*.whl .
26
+ RUN pip3 install --no-cache-dir *.whl
27
+
28
+ ENV PYTHONUNBUFFERED=1
29
+ ENTRYPOINT [ "raspy2mqtt" ]
30
+
@@ -0,0 +1,28 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2024, Francesco Montorsi
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ 3. Neither the name of the copyright holder nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,136 @@
1
+ #
2
+ # This Makefile can be used to install this project on a Raspbian OS.
3
+ # The specifics of Raspbian OS are that:
4
+ # * pip3 install <module-name> will not work and fail with msg:
5
+ # "error: externally-managed-environment [...]"
6
+ #
7
+ # So this makefile takes care of automating
8
+ # * creation of venv
9
+ # * installation of this project into that venv
10
+ # * distribution of config file in standard system folders
11
+ #
12
+
13
+ SHELL = /bin/bash
14
+
15
+ ifeq ($(BINDEST),)
16
+ BINDEST=/root
17
+ endif
18
+ ifeq ($(CFGDEST),)
19
+ CFGDEST=/etc
20
+ endif
21
+ ifeq ($(SYSTEMDUNITDEST),)
22
+ SYSTEMDUNITDEST=/lib/systemd/system/
23
+ endif
24
+ ifeq ($(CONFIG_FILE_FOR_DOCKER),)
25
+ # NOTE: please override this with a config file containing a valid MQTT broker config
26
+ CONFIG_FILE_FOR_DOCKER=$(shell pwd)/tests/integration-test-config.yaml
27
+ endif
28
+
29
+ all: build-wheel lint test
30
+
31
+ #
32
+ # TARGETS FOR DEPLOYING ON RaspBian
33
+ #
34
+
35
+ raspbian_install:
36
+ # check OS version
37
+ @if [[ `lsb_release -i -s 2>/dev/null` != "Raspbian" && `lsb_release -i -s 2>/dev/null` != "Debian" ]] || (( `lsb_release -r -s 2>/dev/null` < 12 )); then \
38
+ echo ; \
39
+ echo "** WARNING **" ; echo "THIS SOFTWARE HAS BEEN TESTED ONLY ON RASPBIAN 12 OR HIGHER AND REQUIRES PYTHON3.11" ; \
40
+ echo "CHECK IF THIS DISTRIBUTION IS OK... PROCEEDING BUT EXPECT ERRORS" ; \
41
+ echo ; \
42
+ else \
43
+ echo "Your operating system seems to be OK for rpi2home-assistant" ; \
44
+ fi
45
+ # install python venv
46
+ python3 -m venv $(BINDEST)/rpi2home-assistant-venv
47
+ $(BINDEST)/rpi2home-assistant-venv/bin/pip3 install .
48
+ # install app config (only if MISSING, don't overwrite customizations)
49
+ @if [[ -f $(CFGDEST)/rpi2home-assistant.yaml ]]; then \
50
+ echo "WARNING: a configuration file already exists; copying the updated one with .new suffix" ; \
51
+ cp -av config.yaml $(CFGDEST)/rpi2home-assistant.yaml.new ; \
52
+ else \
53
+ cp -av config.yaml $(CFGDEST)/rpi2home-assistant.yaml ; \
54
+ fi
55
+ # install systemd config
56
+ chmod 644 systemd/*.service
57
+ cp -av systemd/*.service $(SYSTEMDUNITDEST)/
58
+ systemctl daemon-reload
59
+
60
+ raspbian_enable_at_boot:
61
+ systemctl enable rpi2home-assistant.service
62
+ # this is assuming that the Debian package "pigpiod" is already installed:
63
+ systemctl enable pigpiod.service
64
+
65
+ raspbian_start:
66
+ systemctl start rpi2home-assistant.service
67
+ systemctl start pigpiod.service
68
+
69
+ raspbian_show_logs:
70
+ journalctl -u rpi2home-assistant
71
+
72
+ raspbian_update_dependencies:
73
+ $(BINDEST)/rpi2home-assistant-venv/bin/pip3 install --upgrade .
74
+
75
+ raspbian_uninstall:
76
+ @rm -fv $(SYSTEMDUNITDEST)/rpi2home-assistant.service
77
+ systemctl daemon-reload
78
+ @echo "Considering deleting also:"
79
+ @echo " $(CFGDEST)/rpi2home-assistant.yaml/*"
80
+ @echo " $(BINDEST)/rpi2home-assistant-venv"
81
+
82
+ #
83
+ # TARGETS FOR DEVELOPMENT
84
+ #
85
+
86
+ docker:
87
+ docker build -t rpi2home-assistant:latest .
88
+
89
+ run-docker:
90
+ @if [ ! -f $(CONFIG_FILE_FOR_DOCKER) ]; then \
91
+ echo "Could not find the config file $(CONFIG_FILE_FOR_DOCKER) to mount inside the docker... please specify a valid config file with CONFIG_FILE_FOR_DOCKER option." ; \
92
+ exit 3 ; \
93
+ fi
94
+ docker run --rm -ti --env DISABLE_HW=1 --network=host \
95
+ -v $(CONFIG_FILE_FOR_DOCKER):/etc/rpi2home-assistant.yaml \
96
+ rpi2home-assistant:latest
97
+
98
+ run-mosquitto:
99
+ docker run -d --publish 1883:1883 \
100
+ --volume $$(pwd)/tests/integration-test-mosquitto.conf:/mosquitto/config/mosquitto.conf \
101
+ eclipse-mosquitto:latest
102
+
103
+ test: unit-test integration-test
104
+
105
+ unit-test:
106
+ ifeq ($(REGEX),)
107
+ pytest -vvv --log-level=INFO -m unit
108
+ else
109
+ pytest -vvvv --log-level=INFO -s -m unit -k $(REGEX)
110
+ endif
111
+
112
+ # NOTE: during integration-tests the "testcontainers" project will be used to spin up
113
+ # both a Mosquitto broker and the rpi2home-assistant docker, so make sure you don't
114
+ # have a Mosquitto broker (or other containers) already listening on the 1883 port
115
+ # when using this target:
116
+ integration-test:
117
+ ifeq ($(REGEX),)
118
+ pytest -vvvv --log-level=INFO -s -m integration
119
+ else
120
+ pytest -vvvv --log-level=INFO -s -m integration -k $(REGEX)
121
+ endif
122
+
123
+ build-wheel:
124
+ python3 -m build --wheel --outdir dist/
125
+
126
+ test-wheel:
127
+ rm -rf dist/ && \
128
+ pip3 uninstall -y rpi2home-assistant && \
129
+ $(MAKE) build-wheel && \
130
+ pip3 install dist/rpi2home_assistant-*py3-none-any.whl
131
+
132
+ format:
133
+ black .
134
+
135
+ lint:
136
+ ruff check src/raspy2mqtt/
@@ -0,0 +1,201 @@
1
+ Metadata-Version: 2.4
2
+ Name: rpi2home-assistant
3
+ Version: 2.3.0
4
+ Summary: Raspberry PI to Home Assistant bridge through MQTT for wired sensors/actuators
5
+ Project-URL: Homepage, https://github.com/f18m/rpi2home-assistant
6
+ Project-URL: Bug Tracker, https://github.com/f18m/rpi2home-assistant/issues
7
+ Author-email: Francesco Montorsi <francesco.montorsi.nospam@gmail.com>
8
+ License-File: LICENSE
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Programming Language :: Python :: 3
12
+ Requires-Dist: aiomqtt==2.4.0
13
+ Requires-Dist: gpiozero==2.0.1
14
+ Requires-Dist: pigpio==1.78
15
+ Requires-Dist: pyyaml==6.0.2
16
+ Requires-Dist: schema==0.7.7
17
+ Requires-Dist: sm16inpind==1.0.1
18
+ Description-Content-Type: text/markdown
19
+
20
+ # rpi2home-assistant
21
+
22
+ This project provides a Python daemon to **transform a [Raspberry PI](https://www.raspberrypi.com/) into a bridge between GPIO inputs/outputs and HomeAssistant, through MQTT**.
23
+ In particular this software allows to:
24
+ * sample low-voltage inputs from Raspberry GPIO pins directly (with no isolation/protection/HAT), publish them on MQTT and get them exposed to Home Assistant as [binary sensors](https://www.home-assistant.io/integrations/binary_sensor.mqtt/);
25
+ * sample a wide range of electrical signals (voltages) from 3V-48V AC or DC, using a dedicated Raspberry HAT, publish them on MQTT and get them exposed to Home Assistant as [binary sensors](https://www.home-assistant.io/integrations/binary_sensor.mqtt/);
26
+ * expose Raspberry GPIO output pins in Home Assistant as [switches](https://www.home-assistant.io/integrations/switch.mqtt/) or as [buttons](https://www.home-assistant.io/integrations/button.mqtt/) to e.g. activate relays, using a dedicated Raspberry HAT / relay board or just drive low-voltage electrical devices;
27
+
28
+ All these features are implemented in an [Home Assistant](https://www.home-assistant.io/)-friendly fashion.
29
+ For example, this utility requires **no configuration on Home Assistant-side** thanks to [MQTT discovery messages](https://www.home-assistant.io/integrations/mqtt/#mqtt-discovery) that are automatically published and let Home Assistant automatically discover the devices. In other words you will just need to prepare 1 configuration file (the _rpi2home-assistant_ config file) and that's it.
30
+ All properties of the exposed devices (names, icons, descriptions, etc) can be provided/customized in the _rpi2home-assistant_ config file.
31
+
32
+ An example of a panel of sensors/actuators created using _rpi2home-assistant_ in Home Assistant 2024.5 (sensor/switch/button names have been blurred for privacy reasons; binary sensor status is shown in Italian language):
33
+
34
+ ![Home Assistant screenshot](/docs/screenshot1.png?raw=true "Home Assistant screenshot")
35
+
36
+
37
+ # Prerequisites
38
+
39
+ This software is meant to run on a Raspberry PI.
40
+ In addition to standard GPIOs, _rpi2home-assistant_ **optionally** provides specific support for the following hat:
41
+
42
+ ![Sequent Microsystem 16 opto-insulated inputs HAT](/docs/seq-microsystem-optoisolated-hat.png?raw=true "Sequent Microsystem 16 opto-insulated inputs HAT")
43
+
44
+ * [Sequent Microsystem 16 opto-insulated inputs HAT](https://sequentmicrosystems.com/collections/all-io-cards/products/16-universal-inputs-card-for-raspberry-pi). This hat allows to sample a wide range of electrical signals (voltages) from 3V-48V AC or DC. _rpi2home-assistant_ exposes the sampled values over MQTT, to ease their integration as (binary) sensors in Home Assistant.
45
+
46
+ <!--
47
+ Note that Sequent Microsystem board is connecting the pin 37 (GPIO 26) of the Raspberry Pi
48
+ to a pushbutton. This software monitors this pin, and if pressed for more than the
49
+ desired time, issues the shut-down command to the Raspberry PI board.
50
+ -->
51
+
52
+ The suggested way to use a RaspberryPI to drive external loads is through the use of **relay boards**.
53
+ There are a number of alternatives available on the market. The majority of them is really simple and
54
+ ask for the 3.3V or 5V power supply and then connect to the RaspberryPI through GPIO pins either
55
+ active high or active low.
56
+ A couple of suggested hats exposing relays are:
57
+
58
+ ![SeenGreat 2CH output opto-insulated relay HAT](/docs/seengreat-2ch-relay.png?raw=true "SeenGreat 2CH output opto-insulated relay HAT")
59
+
60
+ * [SeenGreat 2CH output opto-insulated relay HAT](https://seengreat.com/wiki/107/).
61
+
62
+ ![Sunfounder 4CH output opto-insulated relay HAT](/docs/sunfounder-4ch-relay.png?raw=true "Sunfounder 4CH output opto-insulated relay HAT")
63
+
64
+ * [Sunfounder 4 Channel 5V Relay Module](http://wiki.sunfounder.cc/index.php?title=4_Channel_5V_Relay_Module).
65
+
66
+
67
+ Beyond that, this software is meant to be compatible with all 40-pin Raspberry Pi boards
68
+ (Raspberry Pi 1 Model A+ & B+, Raspberry Pi 2, Raspberry Pi 3, Raspberry Pi 4,
69
+ Raspberry Pi 5).
70
+
71
+ Software prerequisites are:
72
+ * you must have an **MQTT broker** running somewhere (e.g. a Mosquitto broker);
73
+ * **Python >= 3.11**; for Raspberry it means you must be using Debian bookworm 12 or [Raspberry Pi OS](https://www.raspberrypi.com/software/operating-systems/) 12 or higher;
74
+ * there is no particular constraint on the Home Assistant version, even if the project is continuously tested
75
+ almost only against the latest Home Assistant version available.
76
+
77
+ # Documentation
78
+
79
+ ## How to install on a Raspberry Pi with Debian Bookworm 12
80
+
81
+ The [Raspberry Pi OS](https://www.raspberrypi.com/software/operating-systems/) does not allow to install Python software using `pip`.
82
+ Trying to install a Python package that way leads to an error like:
83
+
84
+ ```
85
+ error: externally-managed-environment [...]
86
+ ```
87
+
88
+ That means that to install Python software, a virtual environment has to be used.
89
+ This procedure automates the creation of the venv and has been tested on Raspberry Pi OS 12 (bookworm).
90
+ Just copy-paste on your raspberry each command:
91
+
92
+ ```
93
+ sudo su
94
+ # python3-dev is needed by a dependency (rpi-gpio) which compiles native C code
95
+ # pigpiod is a package providing the daemon that is required by the pigpio GPIO factory
96
+ apt install git python3-venv python3-dev pigpiod
97
+ cd /root
98
+ git clone https://github.com/f18m/rpi2home-assistant.git
99
+ cd rpi2home-assistant/
100
+ make raspbian_install
101
+ make raspbian_enable_at_boot
102
+ make raspbian_start
103
+ ```
104
+
105
+ Then of course it's important to populate the configuration file, with the specific pinouts for your raspberry HATs
106
+ (see [Preqrequisites](#prerequisites) section).
107
+
108
+ ## Configuration file
109
+
110
+ The configuration file of _rpi2home-assistant_ is of course `/etc/rpi2home-assistant.yaml`.
111
+ During the installation the default config file with dummy options is installed.
112
+ It is useful to showcase the syntax. See [config.yaml](config.yaml) for
113
+ the full documentation of the configuration options.
114
+
115
+ ## Permissions
116
+
117
+ This python code needs to run as `root` due to ensure access to the Raspberry I2C and GPIO peripherals.
118
+
119
+ ## Logs
120
+
121
+ After starting the application you can verify from the logs whether it's running successfully:
122
+
123
+ ```
124
+ journalctl -u rpi2home-assistant --since="5min ago"
125
+ ```
126
+
127
+ ## Deploy/test with Docker
128
+
129
+ This project also provides a multi-arch docker image to ease testing.
130
+ You can launch this software into a docker container by running:
131
+
132
+ ```
133
+ docker run -d \
134
+ --volume <your config file>:/etc/rpi2home-assistant.yaml \
135
+ --privileged --hostname $(hostname) \
136
+ ghcr.io/f18m/rpi2home-assistant:<latest version>
137
+ ```
138
+
139
+ However please note that using Docker on a Raspberry PI is probably an overkill for this application,
140
+ so the preferred way to save CPU is to install using a dedicated Python venv (see above).
141
+
142
+
143
+ # Development
144
+
145
+ This section contains information useful in case you want to hack/collaborate on the project.
146
+ Patches/improvements and new features are welcome.
147
+
148
+ This project uses `poetry` as build system (https://python-poetry.org/) so the 'build' is as simple as:
149
+
150
+ ```
151
+ python3 -m build
152
+ ```
153
+
154
+ To develop changes you can create a branch and push changes there. Then:
155
+
156
+ ```
157
+ make format
158
+ make lint
159
+ make docker
160
+ make unit-test
161
+ make integration-test
162
+ ```
163
+
164
+ To validate locally your changes.
165
+
166
+ Finally, once ready, check out your branch on your raspberry and then run:
167
+
168
+ ```
169
+ python3 -m venv ~/rpi2home-assistant-venv
170
+ ~/rpi2home-assistant-venv/bin/pip3 install .
171
+ source ~/rpi2home-assistant-venv/bin/activate
172
+ cd <checkout_folder>/raspy2mqtt
173
+ ./raspy2mqtt -c /etc/rpi2home-assistant.yaml
174
+ ```
175
+
176
+ Alternatively you can test manually on your local machine by running:
177
+
178
+ ```
179
+ make run-mosquitto
180
+
181
+ nano myconfig.yaml # stick the Mosquitto port exposed locally inside the config file
182
+ make run-docker CONFIG_FILE_FOR_DOCKER=myconfig.yaml
183
+ ```
184
+
185
+
186
+
187
+ # Useful links
188
+
189
+ * [Sequent Microsystem 16 opto-insulated inputs python library](https://github.com/SequentMicrosystems/16inpind-rpi)
190
+ * [aiomqtt python library](https://github.com/sbtinstruments/aiomqtt)
191
+ * [AsyncIO tutorial](https://realpython.com/python-concurrency/#asyncio-version)
192
+ * [Home Assistant](https://www.home-assistant.io/)
193
+
194
+ Very similar project, more flexible and much bigger, targeting specific sensor boards:
195
+ * [mqtt-io](https://github.com/flyte/mqtt-io)
196
+
197
+
198
+ # TODO
199
+
200
+ - Eventually get rid of GPIOZERO + PIGPIOD which consume CPU and also force use of e.g. the queue.Queue due to
201
+ the multithreading issues; replace these 2 parts with direct Raspberry PI GPIO access?