rpi2home-assistant 2.3.0__py2.py3-none-any.whl

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.
@@ -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?
@@ -0,0 +1,16 @@
1
+ _raspy2mqtt_version.py,sha256=fpc6pwpIb6e3qF1WOyVnbUkHq-QnCDr_IHqJobzPyaw,18
2
+ raspy2mqtt/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ raspy2mqtt/circular_buffer.py,sha256=Tai1vZVy283WVsfeEU190cmIY3nn8ZiXgl8IsyaE1rk,5161
4
+ raspy2mqtt/config.py,sha256=UQLUc_xN6I7F2TLqmriTeanHvj5u_UaGiQjP0vLIqJ0,29076
5
+ raspy2mqtt/constants.py,sha256=LBLFJ41AIoerpWVhk3ras57g8bwPn-e32CFBGzMIwHc,2478
6
+ raspy2mqtt/gpio_inputs_handler.py,sha256=aWYz0PfR02GZ13voYbm7FrVdRJww6hPnPbIgaACMGTY,6851
7
+ raspy2mqtt/gpio_outputs_handler.py,sha256=56E2gZvgVrkY9DSZUv5TuZvj-8bK-WYNMDfoWRWNYZs,15052
8
+ raspy2mqtt/homeassistant_status_tracker.py,sha256=Lhbiy7T1FFubrzoCxtjhs4PvjZ3j4xwpF-VZaenWSCA,4323
9
+ raspy2mqtt/main.py,sha256=B3tiXsGre7zOR_nh7CTASLX1tHzdMUszDplWZy3cCbM,10306
10
+ raspy2mqtt/optoisolated_inputs_handler.py,sha256=i5agFjU-oztyCoqocFc8dOGGbWMeQfcGPG0FVCArYOo,13802
11
+ raspy2mqtt/stats.py,sha256=djerxFpBI-u5ou5-IKxfXue6V0A35L-Mw9b1RZKzFfI,1806
12
+ rpi2home_assistant-2.3.0.dist-info/METADATA,sha256=IbxcBzt9ZWnvXJGMQW34MojQ1PXPO-L8Mp_bBZx66CI,9211
13
+ rpi2home_assistant-2.3.0.dist-info/WHEEL,sha256=tkmg4JIqwd9H8mL30xA7crRmoStyCtGp0VWshokd1Jc,105
14
+ rpi2home_assistant-2.3.0.dist-info/entry_points.txt,sha256=09rc8Ngm8K0OG9S2gnHpF0GOI_BP4kjzY8MwpFAIGGE,58
15
+ rpi2home_assistant-2.3.0.dist-info/licenses/LICENSE,sha256=LNCMmwHYhpNMgfJd8r5KzZrf5Sqv2OsOOrQ39Jzahf8,1505
16
+ rpi2home_assistant-2.3.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.27.0
3
+ Root-Is-Purelib: true
4
+ Tag: py2-none-any
5
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ raspy2mqtt = raspy2mqtt.main:entrypoint
@@ -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.