Skip to content

Commit eb3f022

Browse files
authored
Merge pull request #26 from hostcc/feat/modularize
feat!: Further modularize configuration
2 parents d77ab7e + 8895697 commit eb3f022

14 files changed

+141
-65
lines changed

README.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ the image below).
118118

119119
## How to use
120120

121+
### Minimal configuration for the stock hardware
122+
121123
Include following fragment to your ESPHome configuration (`sprinkler` name of
122124
the package could be anything), it is recommended to use specific release
123125
version (see
@@ -128,7 +130,6 @@ A temperature sensor is a prerequisite to the configuration, its ID should be
128130
passed via `temperature_sensor_id` substitution - it is only used by display
129131
component currently.
130132

131-
132133
```yaml
133134
substitutions:
134135
temperature_sensor_id: temperature_sensor
@@ -148,10 +149,21 @@ packages:
148149
The configuration could further be adjusted using substitutions, see
149150
[main.yaml](main.yaml) for details.
150151
151-
You can also remove certain portions of the configuration marked as `Optional`
152-
in [main.yaml](main.yaml) if you don't have particular hardware or need to use that
153-
functionality.
152+
### Full configuration including optional components
153+
154+
If you have optional hardware modifications (RTC, display) and would like to use it,
155+
you would rather use `full.yaml` instead of `main.yaml`:
156+
157+
```yaml
158+
packages:
159+
sprinkler: github://hostcc/esphome-config-sprinkler/full.yaml@<release version>
160+
```
154161

162+
### Further customization
163+
164+
You can also remove certain portions of the configuration marked as `Optional`
165+
in [full.yaml](full.yaml) and [main.yaml](main.yaml) if you don't have particular
166+
hardware or need to use that functionality.
155167

156168
## Sample installation
157169

buzzer.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
# Copyright (c) 2023 Ilia Sotnikov
3+
---
4+
esphome:
5+
platformio_options:
6+
build_flags:
7+
# Define the preprocessor macro indicating presence of buzzer
8+
# components so that dependent code could be conditional
9+
- '-DHAS_BUZZER'
10+
11+
switch:
12+
- platform: output
13+
name: Buzzer
14+
output: buzzer
15+
internal: true
16+
17+
output:
18+
- platform: rp2040_pwm
19+
pin: GPIO6
20+
# This gives ~2KHz output, by a reason this frequency is not in Hz
21+
frequency: 8000000
22+
id: buzzer

display.yaml

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ esphome:
1111
- '-DHAS_DISPLAY'
1212

1313
spi:
14+
id: display_spi
1415
clk_pin: GPIO2
1516
mosi_pin: GPIO3
1617
interface: hardware
@@ -108,10 +109,20 @@ display:
108109
);
109110
110111
// Symbols indicating state of water tank emptiness and rain sensor
112+
#ifdef HAS_CUSTOM_INPUTS
111113
it.printf(
112-
42, 22, material, TextAlign::TOP_CENTER, "%s%s%s",
113-
id(${water_tank_empty_id}).state ? "\U0000f6d5": "\U0000f6d6",
114-
id(${rain_sensor_id}).state ? "\U0000f176" : "\U0000e81a",
114+
30, 22, material, TextAlign::TOP_CENTER,
115+
"%s%s",
116+
${water_tank_empty_id}->state ? "\U0000f6d5": "\U0000f6d6",
117+
${rain_sensor_id}->state ? "\U0000f176" : "\U0000e81a"
118+
);
119+
#endif // HAS_CUSTOM_INPUTS
120+
121+
// Symbol indicating state of peripherals power relay, same vertical
122+
// position as the previous ones
123+
it.printf(
124+
66, 22, material, TextAlign::TOP_CENTER,
125+
"%s",
115126
id(${peripherals_power_off_relay_id}).state ? "\U0000e224" : ""
116127
);
117128
@@ -168,6 +179,7 @@ display:
168179
169180
- id: display_page2
170181
lambda: |-
182+
#ifdef USE_WIFI
171183
#include <esphome/components/wifi/wifi_component.h>
172184
using namespace esphome::wifi;
173185
@@ -180,8 +192,10 @@ display:
180192
84, 14, primary, TextAlign::CENTER_RIGHT, "%i dBm",
181193
global_wifi_component->wifi_rssi()
182194
);
183-
184-
} else {
195+
} else
196+
#endif // USE_WIFI
197+
// Always show WiFi disconnected symbol if WiFi is not used
198+
{
185199
it.print(0, 14, material, TextAlign::CENTER_LEFT, "\U0000e648");
186200
it.print(84, 14, primary, TextAlign::CENTER_RIGHT, " ");
187201
}

full.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
# Copyright (c) 2023 Ilia Sotnikov
3+
---
4+
packages:
5+
minimal: !include main.yaml
6+
# Optional packages, mostly for platform-specific or optional elements - the
7+
# `main.yaml` being agnostic could also be used for tests on other platforms
8+
# such as `host`
9+
inputs: !include inputs.yaml
10+
buzzer: !include buzzer.yaml
11+
display: !include display.yaml
12+
indicators: !include indicators.yaml
13+
rtc: !include rtc.yaml

indicators.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,16 @@ light:
4949
call.perform();
5050
return;
5151
};
52-
if (id(${rain_sensor_id}).state) {
52+
53+
#ifdef HAS_CUSTOM_INPUTS
54+
if (${rain_sensor_id}->state) {
5355
auto call = id(${led_id}).turn_on();
5456
call.set_effect("pulse_slow");
5557
call.set_color_brightness(${led_brightness});
5658
call.set_rgb(0.4, 1.0, 0.9);
5759
call.perform();
5860
return;
5961
};
62+
#endif // HAS_CUSTOM_INPUTS
63+
6064
id(${led_id}).turn_on();

inputs.yaml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
# SPDX-License-Identifier: Apache-2.0
22
# Copyright (c) 2023 Ilia Sotnikov
33
---
4+
esphome:
5+
platformio_options:
6+
build_flags:
7+
# Define the preprocessor macro indicating presence of custom inputs
8+
# so that dependent code could be conditional
9+
- '-DHAS_CUSTOM_INPUTS'
10+
411
binary_sensor:
512
- platform: gpio
613
id: ${rain_sensor_id}
@@ -15,7 +22,8 @@ binary_sensor:
1522
filters:
1623
- delayed_on: 100ms
1724
- delayed_off: 100ms
18-
publish_initial_state: true
25+
# Renamed from `publish_initial_state` in ESPHome 2025.7.0
26+
trigger_on_initial_state: true
1927
on_state:
2028
then:
2129
- lambda: !include
@@ -36,7 +44,8 @@ binary_sensor:
3644
filters:
3745
- delayed_on: 100ms
3846
- delayed_off: 100ms
39-
publish_initial_state: true
47+
# Same as above
48+
trigger_on_initial_state: true
4049
on_state:
4150
then:
4251
- lambda: !include
@@ -55,7 +64,7 @@ binary_sensor:
5564
filters:
5665
- delayed_on: 100ms
5766
- delayed_off: 100ms
58-
publish_initial_state: true
67+
trigger_on_initial_state: true
5968
- platform: gpio
6069
internal: true
6170
pin:
@@ -68,4 +77,5 @@ binary_sensor:
6877
filters:
6978
- delayed_on: 100ms
7079
- delayed_off: 100ms
71-
publish_initial_state: true
80+
# Same as above
81+
trigger_on_initial_state: true

main.yaml

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,15 @@
11
# SPDX-License-Identifier: Apache-2.0
22
# Copyright (c) 2023 Ilia Sotnikov
33
---
4-
substitutions:
5-
run_duration_uom: s
6-
run_duration_initial_value: '5'
7-
rain_sensor_id: rain_sensor
8-
rain_sensor_inverted: 'true'
9-
water_tank_empty_id: water_tank_empty
10-
water_tank_empty_inverted: 'true'
11-
peripherals_power_off_relay_id: relay_7
12-
pump_relay_id: relay_8
13-
valve_overlap: 1s
14-
pump_start_pump_delay: 1s
15-
pump_stop_valve_delay: 1s
16-
peripherals_power_refill_pulse_duration: 3s
17-
scheduled_start_wait_tank_full_duration: 60s
18-
led_id: led
19-
led_brightness: '0.5'
20-
display_backlight_id: display1_backlight
21-
display_page_when_active: display_page1
22-
display_page_show_duration: 3s
23-
display_id: display1
24-
display_rotation: '0'
25-
rtc_id: rtc_time
26-
timezone: UTC
27-
temperature_sensor_id: temperature
28-
294
packages:
5+
substitutions: !include substitutions.yaml
306
outputs: !include outputs.yaml
31-
inputs: !include inputs.yaml
32-
schedule: !include schedule.yaml # Optional
33-
display: !include display.yaml # Optional
34-
indicators: !include indicators.yaml # Optional
357
controllers: !include controllers.yaml
368
status_sensors: !include status_sensors.yaml
9+
schedule: !include schedule.yaml # Optional
3710
time: !include time.yaml # Optional
38-
rtc: !include rtc.yaml # Optional
3911

40-
# 2024.11.0 addresses security vulnerability
12+
# 2025.7.0 introduced change from `publish_initial_state` to
13+
# `trigger_on_initial_state` for `binary_sensor` component
4114
esphome:
42-
min_version: '2024.11.0'
15+
min_version: '2025.7.0'

outputs.yaml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,3 @@ switch:
3535
pin: GPIO14
3636
id: ${pump_relay_id}
3737
internal: true
38-
- platform: output
39-
name: Buzzer
40-
output: buzzer
41-
internal: true
42-
43-
output:
44-
- platform: rp2040_pwm
45-
pin: GPIO6
46-
# This gives ~2KHz output, by a reason this frequency is not in Hz
47-
frequency: 8000000
48-
id: buzzer

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
esphome==2025.9.1
1+
esphome==2025.10.3
22
pillow==10.4.0

schedule.yaml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,12 @@ dynamic_on_time:
226226
level: 'INFO'
227227
- wait_until:
228228
condition:
229-
binary_sensor.is_off: ${water_tank_empty_id}
229+
lambda: |-
230+
#ifdef HAS_CUSTOM_INPUTS
231+
return !${water_tank_empty_id}->state;
232+
#else
233+
return true;
234+
#endif
230235
timeout: ${scheduled_start_wait_tank_full_duration}
231236
- logger.log:
232237
format: 'schedule: Starting full sprinkler cycle'
@@ -252,7 +257,12 @@ dynamic_on_time:
252257
level: 'INFO'
253258
- wait_until:
254259
condition:
255-
binary_sensor.is_off: ${water_tank_empty_id}
260+
lambda: |-
261+
#ifdef HAS_CUSTOM_INPUTS
262+
return !${water_tank_empty_id}->state;
263+
#else
264+
return true;
265+
#endif
256266
timeout: ${scheduled_start_wait_tank_full_duration}
257267
- logger.log:
258268
format: 'schedule: Starting full sprinkler cycle'

0 commit comments

Comments
 (0)