1
0
Fork 0
balcony watering system with raspberry pico w
Go to file
Manuel Kamper 3dbda1a293 main.py aktualisiert 2024-04-16 18:29:19 +02:00
3d Dateien hochladen nach „3d“ 2023-07-01 05:42:27 +00:00
images Dateien hochladen nach „images“ 2023-07-01 05:49:59 +00:00
kicad Dateien hochladen nach „kicad“ 2023-07-01 05:43:34 +00:00
LICENSE Initial commit 2023-07-01 05:03:34 +00:00
Logger.py Dateien hochladen nach „“ 2023-07-01 05:04:15 +00:00
NTP.py Dateien hochladen nach „“ 2023-07-01 05:04:15 +00:00
Networking.py Dateien hochladen nach „“ 2023-07-01 05:04:15 +00:00
OTA.py Dateien hochladen nach „“ 2023-07-01 05:43:03 +00:00
README.md „README.md“ ändern 2023-07-01 05:50:21 +00:00
TimeUtils.py Dateien hochladen nach „“ 2023-07-01 05:04:15 +00:00
configs.py Dateien hochladen nach „“ 2023-07-01 05:28:23 +00:00
main.py main.py aktualisiert 2024-04-16 18:29:19 +02:00
secrets.py Dateien hochladen nach „“ 2023-07-01 05:28:23 +00:00

README.md

raspberry-pico-balcony-watering

The goal of this project was to build an automated watering system for the vegetables on my balcony with soil moisture sensors. In addition, I included it into my home automation system FHEM.
You can manually turn on/off the watering pump, trigger a watering pulse (you can set the duration), turn on/off the automatic watering mode (this mode allows automatic watering, if soil moisture is below a threshold it triggers a watering pulse).
You can fully customize the parameters, for example the interval the system should read new soil moisture, what is the threshold for the soil moisture to be considered dry or wet

Setup

  1. Upload all *.py files to your Raspberry Pico W
  2. Set your wifi credentials in secrets.py file. Also set an api_key.
  3. Set values in configs.py file
  4. Be sure that you give your Pico W a static IP address on your router, so you know where the webservice is available and can configure it in FHEM

In the file configs.py set your configurations:
country: your countrycode (AT=Austria, DE=Germany...) (2-digit string)
ntp_host: set a ntp server (string url)
gmt_offset: offset to gmt for your timezone in hours (int)
auto_summertime: Enables changing to summertime (and back) automatically (True/False)
disable_wifi_powersavingmode: Wifi powersavingmode is enabled per default. Set to true to disable powersavingmode for Wifi (True/False)
api_port: Port on which the API is available (int)
log_housekeeping_days: Logfiles older than this value in days get deleted by housekeeping (int)
api_client_ip: Only this IP is allowed to use the API. Leave blank to allow all connections from all IPs (string)
pulse_duration: Duration of watering pulse (time between pump on and off) in seconds (int)
soil_moisture_measure_interval: Interval when to read new values from soil moisture sensors in minutes (int)
check_for_update: Interval when to check for OTA updates in minutes (int)
ota_host: Host for checking for OTA updates (http://ip-of-your-update-host) - leave empty to disable OTA updates

In the file secrets.py set your configurations:
ssid: Wifi name (string)
pw: Wifi password (string)
api: API key (string)

Hint: use openssl rand -hex 20 to generate the api_key

Hardware

You need the following parts:
Raspberry Pico W
Water pump
6mm water hose and mounting material
3 Soil moisture sensors
DC to DC converter
12 V PWM solar charge controller
30 Watt Solar panel
Waterlevel switch
12 V Battery
3D-printed waterhose clamps (see folder 3d)
3D-printed waterhose dripping tips (see folder 3d)
3D-printed case (see folder 3d)
Prototype PCB (see folder kicad)
Finder 36.11 5V Relais
LEDs, Resistors, Mounting hardware...

picture

Pico W API

You can configure the port, on which the API runs in configs.py in the 'api_port'-value. You also have to set an API-Key in secrets.py in the 'api'-value. Then you can call the API as follows:
http://servername/api_key/command[/json]

You can use the following commands:
wateron - Turns on the watering pump
wateroff - Turns off the watering pump
waterstate - Returns the state of the watering pump
waterpulse - Triggers the watering pump for the duration of pulse_duration (set it in configs.py)
autoon - Enables automatic watering mode
autooff - Disables automatic watering mode
autostate - Returns state of automatic watering mode
forcesoilread - Forces new readings from soil moisture sensors
waterlevel - Returns the level of the water tank
ping - Check if the API is up and running
stats - Returns some stats of the device
reboot - Reboots the device
logs - See logs of the device (you can add a number like .../stats/12 to see the latest 12 log lines) soils - See soil moisture of the device (usage like logs)

FHEM Integration

This is the Watering-HTTPMOD Device for FHEM. It shows status symbols and all readings from stats. You can manually trigger a watering pulse and enable/disable the automatic watering mode.

defmod Watering HTTPMOD 0
attr Watering devStateIcon full:zisterne_100 empty:zisterne_00 wet:water@green:wateringPulse dry:water@red:wateringPulse on:automatic@green:autoModeOff off:automatic@red:autoModeOn
attr Watering event-on-change-reading .*
attr Watering extractAllJSON 1
attr Watering fp_Wohnung 30,590,5,
attr Watering get05Name stats
attr Watering get05Poll 1
attr Watering get05URL http://watering-host/api_key/stats/json
attr Watering icon measure_water_meter
attr Watering room Start,Watering
attr Watering set01Name wateringOn
attr Watering set01NoArg 1
attr Watering set01URL http://watering-host/api_key/wateron
attr Watering set02Name wateringOff
attr Watering set02NoArg 1
attr Watering set02URL http://watering-host/api_key/wateroff
attr Watering set03Name wateringPulse
attr Watering set03NoArg 1
attr Watering set03URL http://watering-host/api_key/waterpulse
attr Watering set04FollowGet stats
attr Watering set04Name autoModeOn
attr Watering set04NoArg 1
attr Watering set04URL http://watering-host/api_key/autoon
attr Watering set05FollowGet stats
attr Watering set05Name autoModeOff
attr Watering set05NoArg 1
attr Watering set05URL http://watering-host/api_key/autooff
attr Watering stateFormat Watering_Soil_is \
Watering_Water_level_status \
Watering_Automatic_watering_Mode

Example of a notification to your Nextcloud Talk instance in case the water tank is empty.

defmod n_WateringWaterEmpty notify Watering:Watering_Water_level_status:.empty {\
fhem("set Talk msg Kein Wasser im Tank der Bewässerungsanlage!");;
}
attr n_WateringWaterEmpty room Watering