Domoticz MicroPython Projects

In this subforum you can show projects you have made, or you are busy with. Please create your own topic.

Moderator: leecollings

rwblinn
Posts: 72
Joined: Wednesday 10 June 2015 21:36
Target OS: Raspberry Pi / ODroid
Domoticz version: 4
Location: Hamburg (Germany)/Middelburg (NL)
Contact:

Domoticz MicroPython Projects

Post by rwblinn »

To share my Domoticz MicroPython Projects Workbook (GitHub).

Purpose
To explore how to use the MicroPython programming language running on embedded hardware interfacing with the Domoticz Home Automation System.

The core of the projects uses the Raspberry Pi Pico W microcontroller, with components like actuators & sensors.
The microcontroller is acting as a web server or MQTT Auto Discovery client communicating or via Bluetooth Low Energy with the Domoticz Home Automation System.

The intention is to provide some practical guidance, inspire ideas .. but not to explain Domoticz nor programming languages.

Prerequisites
It is expected to have basic knowledge of
  • Domoticz Home Automation System.
  • Domoticz Automation Event system dzVents & Lua.
  • Programming languages Python and MicroPython.
  • Raspberry Pi Pico / Pico W and ESP microcontrollers.
  • Thonny Integrated Development Environment.
  • JavaScript Object Notation (JSON).
  • Message Queuing Telemetry Transport MQTT and MQTT Auto Discovery.
  • Bluetooth Low Energy (BLE).
  • Node-RED Low-code programming for event-driven applications.
Remarks
  • This is a working document = conceptual changes & new idea’s whilst progressing.
  • There might be better solutions = changes depend on the author’s learning curve.
  • To-Do actions are tagged with [TODO].
  • Hard- and Software versions are subject to change.
  • Drawings created with Fritzing.
  • Sources to be found in the GitHub repository folder src.
Concept
The concept starts with the MicroPython editor (Thonny) running on the development device (Notebook with Windows 11).

Connected to the development device is a Microcontroller Unit (MCU) with external components (actuators & sensors).
For the Pico W projects, the Pico Breadboard Kit or the Pico IO Shield is used. These are a rather handy boards, not only for experimenting but also for building prototypes.

The MCU communicates with the Domoticz Test System via HTTP or MQTT.
The MCU acts as a
  • Web Server by sending HTTP GET/POST requests to connected clients or receiving HTTP GET/POST requests from connected clients,
  • MQTT Auto Discovery Client by publishing device configuration or state messages and subscribing to state messages.
The connected clients can be any client (like a Web Browser, Node-RED or Application), but for this book the client is a dedicated Domoticz Test System running on a Raspberry Pi 4B 4GB with Raspberry Pi OS version 11 (bullseye).

The Domoticz hardware and related devices are added, either manually via the “Dummy Hardware Controller” or automatic via the “MQTT Auto Discovery Client Gateway with LAN interface” depending on the requirements of the project as described in this book.

Note
Whilst starting to write this book, most of the devices are virtual sensors assigned to the Dummy Hardware Controller, but also gradually start to use the (new) MQTT Auto Discovery feature.

The Automation events are developed in dzVents (Domoticz Easy Events).
Event scripting with dzVents is well integrated in Domoticz and good documentation with many examples is available.
The Domoticz editor (GUI > Setup > More Options > Events) is used to develop and test the scripts (My Automation Scripts).

In addition, Node-RED and MQTT broker mosquitto (with clients mosquitto_pub and mosquitto_sub) are running on the Raspberry Pi.

The software is regularly updated to stay at the latest versions – for Domoticz the release channel Beta is used.

Components
  • 1x Raspberry Pi Pico W 2022.
  • 1x Pico Breadboard Kit GeeekPi with LEDs (LED1-4), Pushbuttons (K1 - K4), Buzzer (not used for now).
  • 1x Pico IO Shield KEYESTUDIO.
  • 1x ESP32-WROOM-32 (OpenMQTTGateway).
  • 1x DHT22 - Temperature & Humidity sensor.
  • 1x LCD display - I2C 20 columns x 4 rows.
  • 1x LCD display - 1.14 inch 240x135 resolution (Waveshare Pico-LCD-1.14).
  • 1x LCD display - 3.5 inch 480x320 resolution (Waveshare Pico-ResTouch-LCD-3.5).
  • 1x TM1637 - 4-digit 7-segment LED display (I2C).
  • 1x Servo Motor - Tower Pro Micro Servo 9g SG90.
  • 1x RFID-RC522 – Reader for MIFARE RFID Cards and Tokens.
  • 1x TM1638 LED&KEY - 8x 7-segment decimal LED component with 8x individual LEDs and 8x push buttons.
  • 1x PIR Motion Sensor.
  • 1x Potentiometer.
  • 2x DS18B20 – 1-wire digital thermometers.
  • 1x 28BYJ-48 Stepper Motor with ULN2003 motor driver.
  • 1x HC-SR04 Ultrasonic Distance Sensor.
  • 1x IKEA VINDRIKTNING Air Quality sensor.
Credits
THANKS to the developers of the Raspberry Pi & ESP Microcontroller, Domoticz Home Automation System, MicroPython Language, Libraries & Tools and to all sharing related information. Without these, it would not be possible to write this document.

Licence
GNU GENERAL PUBLIC LICENSE v3.0.
The information shared for personal use only - use at your own risk (see LICENSE).
Last edited by rwblinn on Tuesday 30 January 2024 10:41, edited 10 times in total.
User avatar
waltervl
Posts: 5375
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Domoticz MicroPython Projects

Post by waltervl »

If the connected hardware device could send and receive mqtt messages according Domoticz (Home assistant) Autodiscover protocol the device would create and maintain its own domoticz devices. No need to create virtual devices and scripting in Domoticz.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
rwblinn
Posts: 72
Joined: Wednesday 10 June 2015 21:36
Target OS: Raspberry Pi / ODroid
Domoticz version: 4
Location: Hamburg (Germany)/Middelburg (NL)
Contact:

Re: Domoticz MicroPython Projects

Post by rwblinn »

Thanks for the hint = appreciated.
[EDIT 20230426] First MQTT Auto Discovery projects created. See next post.

Added to my ToDo list:
MicroPython MQTT client on the embedded hardware which can publish discovery messages for the connected component(s) and subscribes to associated Domoticz device(s) messages.

Will start simple using a DHT22 temperature sensor connected to a Raspberry Pi Pico W and see how it goes ... but need to read the documentation https://www.home-assistant.io/integrati ... -discovery first and look into the Domoticz source https://github.com/domoticz/domoticz/bl ... scover.cpp on how "things" work.
See this post viewtopic.php?f=82&t=40249 starting to explore ...
Last edited by rwblinn on Monday 08 January 2024 10:52, edited 3 times in total.
rwblinn
Posts: 72
Joined: Wednesday 10 June 2015 21:36
Target OS: Raspberry Pi / ODroid
Domoticz version: 4
Location: Hamburg (Germany)/Middelburg (NL)
Contact:

Re: Domoticz MicroPython Projects

Post by rwblinn »

Update 20230425
See post #1.
  • NEW: Project Button Control MQTT Autodiscover.
  • NEW: Project DHT22 Temperature & Humidity MQTT Autodiscover.
  • NEW: Project LCD Text Input. Inspired by this post. Thanks for sharing.
  • NEW: Config added WARNING constant.
  • NEW: Server added function connect2 to connect to the network without socket.
  • NEW: Appendix MQTT Auto Discovery.
  • UPD: Renamed chapters Projects, ESP8266 to Pico W Projects, ESP8266 Projects.
  • UPD: Renamed project ButtonSwitchLight to ButtonControl.
  • UPD: Minor changes.
Last edited by rwblinn on Monday 08 January 2024 10:53, edited 3 times in total.
User avatar
waltervl
Posts: 5375
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Domoticz MicroPython Projects

Post by waltervl »

Good idea to try MQTT Autodiscover...
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Derik
Posts: 1601
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: Domoticz MicroPython Projects

Post by Derik »

Nice project..
When i have holidays.. Will try to get my Sunblinds working with a stepper motor
So the blinds, blinds the sun when in am in the bathroom, And when i a am not, the blinds ging to open. So the sun can heat my Bathroom:-)

Are there perhaps al great other projects?
Can i buy cLone Pico boards?
Or is esp 32 better?
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups
rwblinn
Posts: 72
Joined: Wednesday 10 June 2015 21:36
Target OS: Raspberry Pi / ODroid
Domoticz version: 4
Location: Hamburg (Germany)/Middelburg (NL)
Contact:

Re: Domoticz MicroPython Projects

Post by rwblinn »

Derik wrote: Thursday 27 April 2023 16:43 Nice project..
Thanks.
Derik wrote: Thursday 27 April 2023 16:43 Will try to get my Sunblinds working with a stepper motor
So the blinds, blinds the sun when in am in the bathroom, And when i a am not, the blinds ging to open. So the sun can heat my Bathroom:-)
Added to my ToDo list the project Stepper Motor.
This project will use (again) a Raspberry Pi Pico W and a 28BYJ-48 Stepper Motor with ULN2003 motor driver.
Status: Started building a prototype as already got the components.
Wrote the class STEPPER to control the motor driver. Created Domoticz virtual device Blinds handled by Automation event dzVents.
Derik wrote: Thursday 27 April 2023 16:43 Can i buy cLone Pico boards? Or is esp 32 better?
The projects uses original Raspberry Pi Pico W, but also a clone to test. So far working fine. MicroPython integration is working well.
ESP32 with MicroPython not tested so far. Did few tests with ESP8266, but found slower and also issues (memory, functions) using the MicroPython picozero library.
rwblinn
Posts: 72
Joined: Wednesday 10 June 2015 21:36
Target OS: Raspberry Pi / ODroid
Domoticz version: 4
Location: Hamburg (Germany)/Middelburg (NL)
Contact:

Re: Domoticz MicroPython Projects

Post by rwblinn »

Update 20230506
See post #1.
  • NEW: Project Stepper Motor with several solutions Selector Switch Angle Move, Blind Simulation, Timer Run Stop.
  • UPD: Minor changes.
Last edited by rwblinn on Monday 08 January 2024 10:52, edited 3 times in total.
rwblinn
Posts: 72
Joined: Wednesday 10 June 2015 21:36
Target OS: Raspberry Pi / ODroid
Domoticz version: 4
Location: Hamburg (Germany)/Middelburg (NL)
Contact:

Re: Domoticz MicroPython Projects

Post by rwblinn »

Update 20230517
See post #1.
  • NEW: Project Distance Sensor HC-SR04 HTTP API/JSON.
  • NEW: Project Distance Sensor HC-SR04 MQTT Auto Discovery.
  • NEW: Project IKEA VINDRIKTNING Air Quality sensor with several solutions.
  • UPD: Minor changes.
Last edited by rwblinn on Monday 08 January 2024 10:52, edited 1 time in total.
rwblinn
Posts: 72
Joined: Wednesday 10 June 2015 21:36
Target OS: Raspberry Pi / ODroid
Domoticz version: 4
Location: Hamburg (Germany)/Middelburg (NL)
Contact:

Re: Domoticz MicroPython Projects

Post by rwblinn »

Update 20231227
See post #1 (GitHub).
  • NEW: Project PICOES - Bluetooth Low Energy Environment (BLE) Sensor publishing to Domoticz using MQTT Auto Discovery.
  • UPD: Minor changes.
The project PICOES purpose is to
  • create a Bluetooth Low Energy (BLE) environment sensor using the Raspberry Pi Pico W.
  • advertise in regular intervals, the environment data temperature, humidity & pressure, and sensor battery level.
  • simulate, as a proof-of-concept, data advertised instead using connected sensors sending real data.
  • create and update a Domoticz Temp+Humidity+Baro (including the battery level) device using the MQTT Auto Discovery feature.
  • explore how to integrate the OpenMQTTGateway into Domoticz.
  • explore how to use the MQTT Explorer.
Last edited by rwblinn on Monday 08 January 2024 10:51, edited 3 times in total.
Derik
Posts: 1601
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: Domoticz MicroPython Projects

Post by Derik »

Thanks for the great work!! Love this project
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups
rwblinn
Posts: 72
Joined: Wednesday 10 June 2015 21:36
Target OS: Raspberry Pi / ODroid
Domoticz version: 4
Location: Hamburg (Germany)/Middelburg (NL)
Contact:

Re: Domoticz MicroPython Projects

Post by rwblinn »

Update 20240108
See post #1 (GitHub).
  • NEW: Project PICOACT - Bluetooth Low Energy Environment (BLE) Actuator publishing pushbutton state to Domoticz using MQTT Auto Discovery.
  • NEW: Project BLE Scanner - Tool (Python3) to scan for BLE devices and return a JSON object (array) with device data.
  • UPD: Minor changes.
The project PICOACT purpose is to
  • create a Bluetooth Low Energy (BLE) actuator using the Raspberry Pi Pico W Microcontroller.
  • advertise the actuator changed state.
  • auto create and update the state of Domoticz device(s) using the MQTT Auto Discovery feature.
The project BLE Scanner emerged from scanning for BLE devices MAC addresses.
Created is a tool, developed in Python3 with Bleak, to scan for Bluetooth Low Energy (BLE) single or multiple devices and return a JSON object (array) holding the list of devices found with address, name and optional advertised data.

For Domoticz created some Automation script examples written in dzVents, which executes the BLE Scanner (blescanner.py) and decodes the returned sensor data used to update a Domoticz device, like Temp + Humidity (created from the Domoticz Hardware Controller Dummy).
Tested with the sensors: Govee 5075 and the Xiaomi Mi Thermometer with Custom Firmware (ATC).
The tool can be found on GitHub.

Note: This tool could also be used to create a sensor plugin, like for the Govee 5075. The script blescanner.py is then executed as a subprocess (subprocess.check_output) and its returned data decoded by the plugin. Created a first prototype which runs fine.

PS: Thanks for feedback :)
Derik
Posts: 1601
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: Domoticz MicroPython Projects

Post by Derik »

Is this working with apple airtags??
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups
rwblinn
Posts: 72
Joined: Wednesday 10 June 2015 21:36
Target OS: Raspberry Pi / ODroid
Domoticz version: 4
Location: Hamburg (Germany)/Middelburg (NL)
Contact:

Re: Domoticz MicroPython Projects

Post by rwblinn »

I do not have Apple AirTags but found info on the OpenMQTTGateway forum.
With that, expect the BLE Scanner will find Apple AirTags.
If you have some, give a try with the command

Code: Select all

python blescanner.py -a 1
and check the key advertisementdata.
Approach:
  • Turn Airtag(s) off
  • Run BLE Scanner and copy output to an editor
  • Turn single Airtag on
  • Run BLE Scanner and copy output to an editor
  • Check if there is an additional BLE device found with "advertisementdata": {"manufacturer_data": true, "0X4C": "HEX DATA" ...
  • If AirTag found, then matter of decoding the data (see previous link).
PS: Tested the BLE Scanner with AirPods: Found, but do not have the data format.
rwblinn
Posts: 72
Joined: Wednesday 10 June 2015 21:36
Target OS: Raspberry Pi / ODroid
Domoticz version: 4
Location: Hamburg (Germany)/Middelburg (NL)
Contact:

Re: Domoticz MicroPython Projects

Post by rwblinn »

Update 20240122
See post #1 (GitHub).
  • NEW: Project LCD480x320 - LCD display 3.5-inch 480x320 resolution displaying selective Domoticz device data via Domoticz HTTP API/JSON.
  • UPD: Minor changes.
The project LCD480x320 purpose is to explore how to connect and use an LCD 3.5-inch display with 480x320 resolution and to develop demos displaying selective Domoticz device data via Domoticz HTTP API/JSON GET/POST requests (Pico W runs as a web server).

Screenshot Demo Projects Selection

Solution
The Waveshare display Pico-ResTouch-LCD-3.5 is used.
The demos are based upon the MicroPython GUI library micropython-micro-gui. This library has no touch support, therefor the demos are display-only. The micro-gui library has a variety of standard widgets but have developed some first custom widgets (experimental) as well. This enables to create more complex solutions = an option for future projects.
Last edited by rwblinn on Tuesday 13 February 2024 11:30, edited 3 times in total.
Derik
Posts: 1601
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: Domoticz MicroPython Projects

Post by Derik »

rwblinn wrote: Monday 08 January 2024 10:45 Update 20240108
See post #1 (GitHub).
  • NEW: Project PICOACT - Bluetooth Low Energy Environment (BLE) Actuator publishing pushbutton state to Domoticz using MQTT Auto Discovery.
  • NEW: Project BLE Scanner - Tool (Python3) to scan for BLE devices and return a JSON object (array) with device data.
  • UPD: Minor changes.
The project PICOACT purpose is to
  • create a Bluetooth Low Energy (BLE) actuator using the Raspberry Pi Pico W Microcontroller.
  • advertise the actuator changed state.
  • auto create and update the state of Domoticz device(s) using the MQTT Auto Discovery feature.
The project BLE Scanner emerged from scanning for BLE devices MAC addresses.
Created is a tool, developed in Python3 with Bleak, to scan for Bluetooth Low Energy (BLE) single or multiple devices and return a JSON object (array) holding the list of devices found with address, name and optional advertised data.

For Domoticz created some Automation script examples written in dzVents, which executes the BLE Scanner (blescanner.py) and decodes the returned sensor data used to update a Domoticz device, like Temp + Humidity (created from the Domoticz Hardware Controller Dummy).
Tested with the sensors: Govee 5075 and the Xiaomi Mi Thermometer with Custom Firmware (ATC).
The tool can be found on GitHub.

Note: This tool could also be used to create a sensor plugin, like for the Govee 5075. The script blescanner.py is then executed as a subprocess (subprocess.check_output) and its returned data decoded by the plugin. Created a first prototype which runs fine.

PS: Thanks for feedback :)

MMm what do i need for ble hardware devcice to run ble on the pico? Or is in the pico everything i need?
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups
rwblinn
Posts: 72
Joined: Wednesday 10 June 2015 21:36
Target OS: Raspberry Pi / ODroid
Domoticz version: 4
Location: Hamburg (Germany)/Middelburg (NL)
Contact:

Re: Domoticz MicroPython Projects

Post by rwblinn »

Derik wrote: Tuesday 23 January 2024 10:15 MMm what do i need for ble hardware devcice to run ble on the pico? Or is in the pico everything i need?
The Pico W supports Bluetooth Classic and Bluetooth Low Energy (BLE). No additional components required.
See the Raspberry Pi announcement: https://www.raspberrypi.com/news/new-fu ... or-pico-w/

Ensure to flash the latest stable MicroPython firmware for the Pico W:
https://micropython.org/download/RPI_PICO_W/

After flashing, copy the content of the archive bleactuator.zip folder MicroPython to the Pico W.

Send me a PM if you need more help.
Last edited by rwblinn on Thursday 25 January 2024 18:26, edited 1 time in total.
Derik
Posts: 1601
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: Domoticz MicroPython Projects

Post by Derik »

mmm Was thinking o simple...
Only.. is there a example of steps i need to do, first run [ orderd wrong pic, without wifi]
Now the good onzes.. only... Where to start, how to flash
Then how to set wif etc
And the how to put a on a script in to the pico

If you can help me great
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups
rwblinn
Posts: 72
Joined: Wednesday 10 June 2015 21:36
Target OS: Raspberry Pi / ODroid
Domoticz version: 4
Location: Hamburg (Germany)/Middelburg (NL)
Contact:

Re: Domoticz MicroPython Projects

Post by rwblinn »

Derik wrote: Thursday 25 January 2024 14:19 If you can help me great
To get to the basics of the Raspberry Pi Pico/Pico W and MicroPython recommend, the documentation provided by the Raspberry Pi foundation.
I have used that to get going.

First getting-started-with-the-pico followed by get-started-pico-w then ready to start with MicroPython.

Send you also a PM.
rwblinn
Posts: 72
Joined: Wednesday 10 June 2015 21:36
Target OS: Raspberry Pi / ODroid
Domoticz version: 4
Location: Hamburg (Germany)/Middelburg (NL)
Contact:

Re: Domoticz MicroPython Projects

Post by rwblinn »

Update 20240130
See post #1 (GitHub).
  • NEW: Project LCD114 - LCD display 1.14 inch 240x135 resolution + Joystick & User Keys acting as Domoticz Mini Controller for selective Domoticz devices.
  • UPD: Appendix > Hints.
This project explores how to connect and use the Waveshare Pico-LCD-1.14.
This is a 1.14inch LCD Display Module for the Raspberry Pi Pico, 65K Colors, 240×135, SPI, joystick and two user keys.
Developed is a Domoticz Mini Controller which enables to select a Domoticz device from a group of Domoticz devices, show the current value and set a new value. As an example: controlled can be Domoticz devices from type Setpoint & Light.
The Raspberry Pi Pico W runs as a RESTful server to communicate with the Domoticz system via HTTP API/JSON requests.
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests