GitBucket
4.20.0
Toggle navigation
Sign in
Files
Branches
1
Tags
Issues
Pull requests
Labels
Priorities
Milestones
Wiki
Forks
frozendragon
/
irrigation-system
Browse code
Fully works with one valve now
master
1 parent
9500c4b
commit
46a4ef454e02bb25f5c7bfd2e0a6e905c6c5b3ce
frozendragon
authored
11 hours ago
Patch
Showing
5 changed files
.idea/modules.xml
Makefile
code/irrigation-system-controller.cpp
code/irrigation-system-controller.h
config/irrigation-system-controller.yaml
Show notes
View
.idea/modules.xml
100644 → 0
<?xml version="1.0" encoding="UTF-8"?> <project version="4"> <component name="ProjectModuleManager"> <modules> <module fileurl="file://$PROJECT_DIR$/.idea/irrigation-system.iml" filepath="$PROJECT_DIR$/.idea/irrigation-system.iml" /> </modules> </component> </project>
Ignore Space
Show notes
View
Makefile
build: docker exec -it esphome esphome run /config/irrigation-system-controller.yaml --device /dev/ttyUSB0 clean: docker exec -it esphome rm -rf /root/.platformio
build: docker exec -it esphome esphome run /config/irrigation-system-controller.yaml clean: docker exec -it esphome rm -rf /root/.platformio
Ignore Space
Show notes
View
code/irrigation-system-controller.cpp
#include "esphome.h" #include "driver/gpio.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" struct Valve { gpio_num_t open_pin; gpio_num_t close_pin; bool open; bool motor_running; }; static Valve valve = { .open_pin = GPIO_NUM_19, .close_pin = GPIO_NUM_18, .open = false, .motor_running = false, }; void boot() { gpio_set_direction(GPIO_NUM_19, GPIO_MODE_OUTPUT); gpio_set_level(GPIO_NUM_19, 1); gpio_set_direction(GPIO_NUM_18, GPIO_MODE_OUTPUT); gpio_set_level(GPIO_NUM_18, 1); valve = { .open_pin = GPIO_NUM_19, .close_pin = GPIO_NUM_18, .open = false, .motor_running = false, }; } bool valveState() { return valve.open; } void valve_task(void *pvParameters) { gpio_num_t PIN = valve.open_pin; if (valve.open) { ESP_LOGI("custom", "Valve opening"); PIN = valve.open_pin; } else { ESP_LOGI("custom", "Valve closing"); PIN = valve.close_pin; } gpio_set_level(PIN, 0); vTaskDelay(pdMS_TO_TICKS(10000)); gpio_set_level(PIN, 1); ESP_LOGI("custom", "Valve no longer running"); valve.motor_running = false; vTaskDelete(NULL); } void switchValve() { if (valve.motor_running) { return; } valve.motor_running = true; valve.open = !valve.open; xTaskCreate( valve_task, "valve_task", 2048, NULL, 1, NULL ); }
#include "esphome.h" #include "driver/gpio.h" static bool initialized = false; static bool gpio5_state = false; void buttonTrigger() { if (!initialized) { gpio_set_direction(GPIO_NUM_5, GPIO_MODE_OUTPUT); gpio_set_level(GPIO_NUM_5, 0); initialized = true; gpio5_state = false; } gpio5_state = !gpio5_state; gpio_set_level(GPIO_NUM_5, gpio5_state); ESP_LOGI("custom", "GPIO5 state was: %d", gpio5_state); }
Ignore Space
Show notes
View
code/irrigation-system-controller.h
#pragma once bool valveState(); void boot(); void switchValve();
#pragma once void buttonTrigger();
Ignore Space
Show notes
View
config/irrigation-system-controller.yaml
esphome: name: irrigation-system-controller friendly_name: Irrigation System Controller includes: - /code/irrigation-system-controller.h - /code/irrigation-system-controller.cpp on_boot: priority: -100 then: - lambda: |- boot(); esp32: board: esp32dev framework: type: esp-idf # Enable logging logger: # Enable Home Assistant API api: encryption: key: "bSKjLfhQyC6tI0zZF9iM4UXQ1Sf5d8X/iav+qjslMuE=" ota: - platform: esphome password: "b61e6c3c33d4d56185f005a848d2eb7a" wifi: ssid: !secret wifi_ssid password: !secret wifi_password # Enable fallback hotspot (captive portal) in case wifi connection fails ap: ssid: "Irrigation-System-Controller" password: "wFAKhx25vkf5" switch: - platform: template name: "Irrigation Valve" lambda: |- return valveState(); turn_on_action: - lambda: |- switchValve(); turn_off_action: - lambda: |- switchValve(); captive_portal:
esphome: name: irrigation-system-controller friendly_name: Irrigation System Controller includes: - /code/irrigation-system-controller.h - /code/irrigation-system-controller.cpp esp32: board: esp32dev framework: type: esp-idf # Enable logging logger: # Enable Home Assistant API api: encryption: key: "bSKjLfhQyC6tI0zZF9iM4UXQ1Sf5d8X/iav+qjslMuE=" ota: - platform: esphome password: "b61e6c3c33d4d56185f005a848d2eb7a" wifi: ssid: !secret wifi_ssid password: !secret wifi_password # Enable fallback hotspot (captive portal) in case wifi connection fails ap: ssid: "Irrigation-System-Controller" password: "wFAKhx25vkf5" button: - platform: template name: Test Button on_press: - lambda: |- buttonTrigger(); switch: # - platform: gpio # name: "Open" # pin: GPIO5 # inverted: true - platform: gpio name: "Close" pin: GPIO18 inverted: true captive_portal:
Show line notes below