A Home Assistant monitor for water flow and pressure for leaks, with an optional water shutoff valve in case of emergencies. Powered by the Raspberry Pi Pico W board.
install the Mosquitto MQTT broker on HA
logins: []
require_certificate: false
certfile: fullchain.pem
keyfile: privkey.pem
customize:
active: false
folder: mosquitto
*Note that without a proper certificate, we can't enable the secure ports and we will have to enable and use the insecure 1883, 1884 ports.
go to HA user management and create a dedicated user, that will be used by our Mosquitto client.
Warning:
- changing the password, because it caches the credentials, requires:
- reload the Mosquitto broker integration first
- restart of the Mosquitto broker addon second
- otherwise you will get
Connection error: Connection Refused: not authorised. Error: The connection was refused.
- if you get only
Error: Connection refused
it means the port you try to use is not open (probably due to certificate issues), it does not mean the credentials are not correct
- certain special characters are not allowed (ie. the underscore is safe to use) and perhaps even very long passwords as well
- the user should not be an admin
- the user should only have access from local network
Until PlatformIO properly supports pico w, we will use the original Arduino IDE...
- download, extract and run the Linux zip (do not use the flatpak/snap it has issues with serial ports)
- follow guide for library installation
- follow guide for board installation
tools
->Board
->Raspberry Pi RP2040 Boards(ver.)
->Raspberry PI Pico W
tools
->Flash size
->2MB (no FS)
since we won't be using any file systemtools
->WiFi Region
->USA
- disable WiFi debug output:
tools
->Debug Level
->None
tools
->Debug Port
->Disabled
- note that these changes require a re-upload to take effect
- very important, to enable auto-reset after the first upload/boot
sudo usermod -a -G dialout "$USER"
- reboot
groups
should now listdialout
(more info)
- hold the BOOTSEL button down while plugging in the Pico to your computer (more info)
- connect the board with the USB cable
tools
->Port
->UF2 Board
tools
->USB Stack
->Pico SDK
(more info)tools
->Get Board Info
(should not error and return at least theBN: Raspberry Pi Pico W
)- at this point, the sketch example Blink, should compile, upload and make the connected device blink
- after first upload+boot, the port should automatically change. If not:
tools
->Port
->ttyAMC0
- if you need to manually reset the port:
sudo stty -F /dev/ttyACM0 1200
and then select the port again
- if you need to manually reset the port:
- install VS Code
- make sure the Arduino and z-uno extensions are not installed or at least, disabled if installed
- install the PlatformIO extension
- on Chromebook
sudo apt-get install python3-venv
- restart VSCode
- warning: it may take up to 10 minutes to finish the installation and all the pio commands to become available
- on Chromebook
- open Libraries of PIO from side panel, search for
home-assistant-integration
and install it - install 99-platformio-udev.rules
curl -fsSL https://raw.githubusercontent.com/platformio/platformio-core/master/scripts/99-platformio-udev.rules | sudo tee /etc/udev/rules.d/99-platformio-udev.rules
- on Fedora
sudo udevadm control --reload-rules && sudo udevadm trigger
- on Chromebook
sudo service udev restart
- on Fedora/Chromebook
sudo usermod -a -G dialout $USER
sudo usermod -a -G plugdev $USER
- logout / login to O/S
- physically unplug and reconnect your board
- on Chromebook
- select connect to Linux on chromebook
- it should appear as PicoArduino in the Manage USB devices
- then, serial monitor can connect
- on Chromebook
- to initialize the project
pio project init
- should give
Project has been successfully updated!
- select the active project environment
>PlatformIO: Switch Project Environment
or from the bottom left corner of the IDE- select USB (for first upload) or OTA (for subsequent ones but change the
auth
insideplatformio.ini
file)
- to build
>PlatformIO: Build
orpio run
or from the bottom left corner of the IDE- should result in
[SUCCESS]
- to monitor the serial port for debugging
>PlatformIO: Serial Monitor
or from the bottom left corner of the IDE- should open up a new Terminal with the serial monitor
- to upload
>PlatformIO: Upload
or from the bottom left corner of the IDE- should show progress
Loading into Flash: [====] 100%
and[SUCCESS]
- if not, make sure you have installed the udev rules properly...
- warning: Upload over USB is not possible currently on Chromebooks. Therefore, the first upload MUST take place from another O/S (ie. Fedora) and subsequent uploads can happen OTA from Chromebook
the device should get waterMonitor.local
as a hostname on the local network
copy secrets.h.template
to secrets.h
and insert values
- in
main.cpp
uncomment the#define SERIAL_DEBUG
and build/upload, to enable serial.print debug messages - alternatively, toggle the
waterMonitorDebug
switch from the controller, to enable MQTT print debug messages in the topics:debug:waterMonitor:pulseSensor
debug:waterMonitor:pressureSensor
rm /tmp/arduino* -rf
It is not always known why but uploading over WiFi directly to the device, can fail at random % and at random times. The same code and environment settings can fail or succeed just be retrying multiple times.
Restarting the device does not really help.
The most important thing to succeed with OTA updates, is the WiFi signal to be great. Otherwise, it may take up to 10 times/retries to succeed.