From 8d5ef398973422c33974a32ddd62a8f2d1d0688f Mon Sep 17 00:00:00 2001 From: Ilia Sotnikov Date: Wed, 2 Oct 2024 13:41:22 +0300 Subject: [PATCH] Allow RGB LED to be optional --- controllers.yaml | 24 ++++++++++++++++++---- indicators.yaml | 5 +++++ main.yaml | 2 +- script_rain_water_tank_sensors_action.yaml | 8 ++++++-- 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/controllers.yaml b/controllers.yaml index c3684f0..622f61a 100644 --- a/controllers.yaml +++ b/controllers.yaml @@ -20,7 +20,11 @@ sprinkler: } ${display_backlight_id}->turn_on(); #endif - - light.turn_on: ${led_id} + - lambda: |- + #ifdef HAS_RGB_LED + auto call = ${led_id}->turn_on(); + call.perform(); + #endif on_turn_off: - !include file: script_refill_tank.yaml @@ -30,7 +34,11 @@ sprinkler: condition: >- !id(disable_water_tank_refill).state && !id(water_tank_refill_after_each_valve).state - - light.turn_off: ${led_id} + - lambda: |- + #ifdef HAS_RGB_LED + auto call = ${led_id}->turn_off(); + call.perform(); + #endif - lambda: |- #ifdef HAS_DISPLAY ${display_backlight_id}->turn_off(); @@ -118,7 +126,11 @@ sprinkler: } ${display_backlight_id}->turn_on(); #endif - - light.turn_on: ${led_id} + - lambda: |- + #ifdef HAS_RGB_LED + auto call = ${led_id}->turn_on(); + call.perform(); + #endif on_turn_off: - !include file: script_refill_tank.yaml @@ -128,7 +140,11 @@ sprinkler: condition: >- !id(disable_water_tank_refill).state && !id(water_tank_refill_after_each_valve).state - - light.turn_off: ${led_id} + - lambda: |- + #ifdef HAS_RGB_LED + auto call = ${led_id}->turn_off(); + call.perform(); + #endif - lambda: |- #ifdef HAS_DISPLAY ${display_backlight_id}->turn_off(); diff --git a/indicators.yaml b/indicators.yaml index f4af540..41945ce 100644 --- a/indicators.yaml +++ b/indicators.yaml @@ -4,6 +4,11 @@ esphome: # Required for 'rp2040_pio_led_strip' component min_version: '2023.6.2' + platformio_options: + build_flags: + # Define the preprocessor macro indicating presence of RGB led so that + # dependent code could be conditional + - '-DHAS_RGB_LED' light: - platform: rp2040_pio_led_strip diff --git a/main.yaml b/main.yaml index e07f055..c342a2a 100644 --- a/main.yaml +++ b/main.yaml @@ -31,7 +31,7 @@ packages: inputs: !include inputs.yaml schedule: !include schedule.yaml # Optional display: !include display.yaml # Optional - indicators: !include indicators.yaml + indicators: !include indicators.yaml # Optional controllers: !include controllers.yaml status_sensors: !include status_sensors.yaml time: !include time.yaml # Optional diff --git a/script_rain_water_tank_sensors_action.yaml b/script_rain_water_tank_sensors_action.yaml index 7818885..71fa3c8 100644 --- a/script_rain_water_tank_sensors_action.yaml +++ b/script_rain_water_tank_sensors_action.yaml @@ -33,8 +33,10 @@ // Explicitly shutdown any running operation in case of rain, also turn on // LED indicating the condition #ifdef TRIGGERED_BY_${rain_sensor_id} - auto call = id(${led_id}).turn_on(); + #ifdef HAS_RGB_LED + auto call = ${led_id}->turn_on(); call.perform(); + #endif id(flowerbed_sprinklers).shutdown(); id(lawn_sprinklers).shutdown(); #endif @@ -74,9 +76,11 @@ // Turn off LED indicating that rain is detected #ifdef TRIGGERED_BY_${rain_sensor_id} - auto call = id(${led_id}).turn_off(); + #ifdef HAS_RGB_LED + auto call = ${led_id}->turn_off(); call.perform(); #endif + #endif // Resume any operation if any once water tank is full // NOTE: should be called after moving controller out of standby otherwise