Skip to content

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

License

Notifications You must be signed in to change notification settings

antokara/RPi-Pico-W-Water-Monitor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

67 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RPi Pico W Water Monitor

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.

prerequisites

Mosquitto MQTT broker

Mosquitto Installation

install the Mosquitto MQTT broker on HA

Mosquitto Options

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.

Mosquitto User

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

IDE

Until PlatformIO properly supports pico w, we will use the original Arduino IDE...

Arduino IDE

  1. download, extract and run the Linux zip (do not use the flatpak/snap it has issues with serial ports)
  2. follow guide for library installation
  3. follow guide for board installation
  4. tools -> Board -> Raspberry Pi RP2040 Boards(ver.) -> Raspberry PI Pico W
  5. tools -> Flash size -> 2MB (no FS) since we won't be using any file system
  6. tools -> WiFi Region-> USA
  7. disable WiFi debug output:
    1. tools -> Debug Level-> None
    2. tools -> Debug Port-> Disabled
    3. note that these changes require a re-upload to take effect
  8. very important, to enable auto-reset after the first upload/boot
    1. sudo usermod -a -G dialout "$USER"
    2. reboot
    3. groups should now list dialout (more info)
  9. hold the BOOTSEL button down while plugging in the Pico to your computer (more info)
  10. connect the board with the USB cable
  11. tools -> Port -> UF2 Board
  12. tools -> USB Stack -> Pico SDK (more info)
  13. tools -> Get Board Info (should not error and return at least the BN: Raspberry Pi Pico W)
  14. at this point, the sketch example Blink, should compile, upload and make the connected device blink
  15. after first upload+boot, the port should automatically change. If not: tools -> Port -> ttyAMC0
    1. if you need to manually reset the port: sudo stty -F /dev/ttyACM0 1200 and then select the port again

VS Code

  1. install VS Code
  2. make sure the Arduino and z-uno extensions are not installed or at least, disabled if installed
  3. install the PlatformIO extension
    1. on Chromebook
      1. sudo apt-get install python3-venv
      2. restart VSCode
      3. warning: it may take up to 10 minutes to finish the installation and all the pio commands to become available
  4. open Libraries of PIO from side panel, search for home-assistant-integration and install it
  5. install 99-platformio-udev.rules
    1. 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
    2. on Fedora
      1. sudo udevadm control --reload-rules && sudo udevadm trigger
    3. on Chromebook
      1. sudo service udev restart
    4. on Fedora/Chromebook
      1. sudo usermod -a -G dialout $USER
      2. sudo usermod -a -G plugdev $USER
    5. logout / login to O/S
    6. physically unplug and reconnect your board
      1. on Chromebook
        1. select connect to Linux on chromebook
        2. it should appear as PicoArduino in the Manage USB devices
        3. then, serial monitor can connect
  6. to initialize the project
    1. pio project init
    2. should give Project has been successfully updated!
  7. select the active project environment
    1. >PlatformIO: Switch Project Environment or from the bottom left corner of the IDE
    2. select USB (for first upload) or OTA (for subsequent ones but change the auth inside platformio.ini file)
  8. to build
    1. >PlatformIO: Build or pio run or from the bottom left corner of the IDE
    2. should result in [SUCCESS]
  9. to monitor the serial port for debugging
    1. >PlatformIO: Serial Monitor or from the bottom left corner of the IDE
    2. should open up a new Terminal with the serial monitor
  10. to upload
    1. >PlatformIO: Upload or from the bottom left corner of the IDE
    2. should show progress Loading into Flash: [====] 100% and [SUCCESS]
    3. if not, make sure you have installed the udev rules properly...
    4. 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

hostname

the device should get waterMonitor.local as a hostname on the local network

secrets

copy secrets.h.template to secrets.h and insert values

troubleshooting

debugging

  • 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

clear arduino compile cache

rm /tmp/arduino* -rf

upload through OTA fails

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.

references

  1. Raspberry Pi Pico W Home Assistant Starter Project Using arduino-pico
  2. Arduino-Pico documentation
  3. Arduino-Pico repo
  4. ArduinoHA documentation
  5. ArduinoHA repo

About

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

Topics

Resources

License

Stars

Watchers

Forks

Languages