ESPHome Device (Part 2 of 2)
# Define Sprinkler Zones - Shift Register starts with Pin #0
switch:
- platform: gpio
name: "Sprinkler Zone 1"
icon: "mdi:sprinkler"
id: zone_1
restore_mode: ALWAYS_OFF
pin:
sn74hc595: sprinkler_sn74hc595
number: 0
inverted: false
mode: output
on_turn_on:
then:
- if:
condition:
lambda: |-
return (id(active_zone) != 'z');
then:
#- switch.turn_off: zone_1
- switch.turn_off: zone_2
- switch.turn_off: zone_3
- switch.turn_off: zone_4
- switch.turn_off: zone_5
- switch.turn_off: zone_6
- switch.turn_off: zone_7
- switch.turn_off: zone_8
- switch.turn_off: zone_9
- switch.turn_off: zone_10
- switch.turn_off: zone_11
- switch.turn_off: zone_12
- switch.turn_on: led_1
- globals.set:
id: active_zone
value: '1'
on_turn_off:
- switch.turn_off: led_1
- globals.set:
id: active_zone
value: '99'
- platform: gpio
name: "Sprinkler Zone 2"
icon: "mdi:sprinkler"
id: zone_2
restore_mode: ALWAYS_OFF
pin:
sn74hc595: sprinkler_sn74hc595
number: 1
inverted: false
mode: output
on_turn_on:
then:
- if:
condition:
lambda: |-
return (id(active_zone) != 'z');
then:
- switch.turn_off: zone_1
#- switch.turn_off: zone_2
- switch.turn_off: zone_3
- switch.turn_off: zone_4
- switch.turn_off: zone_5
- switch.turn_off: zone_6
- switch.turn_off: zone_7
- switch.turn_off: zone_8
- switch.turn_off: zone_9
- switch.turn_off: zone_10
- switch.turn_off: zone_11
- switch.turn_off: zone_12
- switch.turn_on: led_2
- globals.set:
id: active_zone
value: '2'
on_turn_off:
- switch.turn_off: led_2
- globals.set:
id: active_zone
value: '99'
- platform: gpio
name: "Sprinkler Zone 3"
icon: "mdi:sprinkler"
id: zone_3
restore_mode: ALWAYS_OFF
pin:
sn74hc595: sprinkler_sn74hc595
number: 2
inverted: false
mode: output
on_turn_on:
then:
- if:
condition:
lambda: |-
return (id(active_zone) != 'z');
then:
- switch.turn_off: zone_1
- switch.turn_off: zone_2
#- switch.turn_off: zone_3
- switch.turn_off: zone_4
- switch.turn_off: zone_5
- switch.turn_off: zone_6
- switch.turn_off: zone_7
- switch.turn_off: zone_8
- switch.turn_off: zone_9
- switch.turn_off: zone_10
- switch.turn_off: zone_11
- switch.turn_off: zone_12
- switch.turn_on: led_3
- globals.set:
id: active_zone
value: '3'
on_turn_off:
- switch.turn_off: led_3
- globals.set:
id: active_zone
value: '99'
- platform: gpio
name: "Sprinkler Zone 4"
icon: "mdi:sprinkler"
id: zone_4
restore_mode: ALWAYS_OFF
pin:
sn74hc595: sprinkler_sn74hc595
number: 3
inverted: false
mode: output
on_turn_on:
then:
- if:
condition:
lambda: |-
return (id(active_zone) != 'z');
then:
- switch.turn_off: zone_1
- switch.turn_off: zone_2
- switch.turn_off: zone_3
#- switch.turn_off: zone_4
- switch.turn_off: zone_5
- switch.turn_off: zone_6
- switch.turn_off: zone_7
- switch.turn_off: zone_8
- switch.turn_off: zone_9
- switch.turn_off: zone_10
- switch.turn_off: zone_11
- switch.turn_off: zone_12
- switch.turn_on: led_4
- globals.set:
id: active_zone
value: '4'
on_turn_off:
- switch.turn_off: led_4
- globals.set:
id: active_zone
value: '99'
- platform: gpio
name: "Sprinkler Zone 5"
icon: "mdi:sprinkler"
id: zone_5
restore_mode: ALWAYS_OFF
pin:
sn74hc595: sprinkler_sn74hc595
number: 4
inverted: false
mode: output
on_turn_on:
then:
- if:
condition:
lambda: |-
return (id(active_zone) != 'z');
then:
- switch.turn_off: zone_1
- switch.turn_off: zone_2
- switch.turn_off: zone_3
- switch.turn_off: zone_4
#- switch.turn_off: zone_5
- switch.turn_off: zone_6
- switch.turn_off: zone_7
- switch.turn_off: zone_8
- switch.turn_off: zone_9
- switch.turn_off: zone_10
- switch.turn_off: zone_11
- switch.turn_off: zone_12
- switch.turn_on: led_5
- globals.set:
id: active_zone
value: '5'
on_turn_off:
- switch.turn_off: led_5
- globals.set:
id: active_zone
value: '99'
- platform: gpio
name: "Sprinkler Zone 6"
icon: "mdi:sprinkler"
id: zone_6
restore_mode: ALWAYS_OFF
pin:
sn74hc595: sprinkler_sn74hc595
number: 5
inverted: false
mode: output
on_turn_on:
then:
- if:
condition:
lambda: |-
return (id(active_zone) != 'z');
then:
- switch.turn_off: zone_1
- switch.turn_off: zone_2
- switch.turn_off: zone_3
- switch.turn_off: zone_4
- switch.turn_off: zone_5
#- switch.turn_off: zone_6
- switch.turn_off: zone_7
- switch.turn_off: zone_8
- switch.turn_off: zone_9
- switch.turn_off: zone_10
- switch.turn_off: zone_11
- switch.turn_off: zone_12
- switch.turn_on: led_6
- globals.set:
id: active_zone
value: '6'
on_turn_off:
- switch.turn_off: led_6
- globals.set:
id: active_zone
value: '99'
- platform: gpio
name: "Sprinkler Zone 7"
icon: "mdi:sprinkler"
id: zone_7
restore_mode: ALWAYS_OFF
pin:
sn74hc595: sprinkler_sn74hc595
number: 6
inverted: false
mode: output
on_turn_on:
then:
- if:
condition:
lambda: |-
return (id(active_zone) != 'z');
then:
- switch.turn_off: zone_1
- switch.turn_off: zone_2
- switch.turn_off: zone_3
- switch.turn_off: zone_4
- switch.turn_off: zone_5
- switch.turn_off: zone_6
#- switch.turn_off: zone_7
- switch.turn_off: zone_8
- switch.turn_off: zone_9
- switch.turn_off: zone_10
- switch.turn_off: zone_11
- switch.turn_off: zone_12
- switch.turn_on: led_7
- globals.set:
id: active_zone
value: '7'
on_turn_off:
- switch.turn_off: led_7
- globals.set:
id: active_zone
value: '99'
- platform: gpio
name: "Sprinkler Zone 8"
icon: "mdi:sprinkler"
id: zone_8
restore_mode: ALWAYS_OFF
pin:
sn74hc595: sprinkler_sn74hc595
number: 7
inverted: false
mode: output
on_turn_on:
then:
- if:
condition:
lambda: |-
return (id(active_zone) != 'z');
then:
- switch.turn_off: zone_1
- switch.turn_off: zone_2
- switch.turn_off: zone_3
- switch.turn_off: zone_4
- switch.turn_off: zone_5
- switch.turn_off: zone_6
- switch.turn_off: zone_7
#- switch.turn_off: zone_8
- switch.turn_off: zone_9
- switch.turn_off: zone_10
- switch.turn_off: zone_11
- switch.turn_off: zone_12
- switch.turn_on: led_8
- globals.set:
id: active_zone
value: '8'
on_turn_off:
- switch.turn_off: led_8
- globals.set:
id: active_zone
value: '99'
- platform: gpio
name: "Sprinkler Zone 9"
icon: "mdi:sprinkler"
id: zone_9
restore_mode: ALWAYS_OFF
pin:
sn74hc595: sprinkler_sn74hc595
number: 8
inverted: false
mode: output
on_turn_on:
then:
- if:
condition:
lambda: |-
return (id(active_zone) != 'z');
then:
- switch.turn_off: zone_1
- switch.turn_off: zone_2
- switch.turn_off: zone_3
- switch.turn_off: zone_4
- switch.turn_off: zone_5
- switch.turn_off: zone_6
- switch.turn_off: zone_7
- switch.turn_off: zone_8
#- switch.turn_off: zone_9
- switch.turn_off: zone_10
- switch.turn_off: zone_11
- switch.turn_off: zone_12
- switch.turn_on: led_9
- globals.set:
id: active_zone
value: '9'
on_turn_off:
- switch.turn_off: led_9
- globals.set:
id: active_zone
value: '99'
- platform: gpio
name: "Sprinkler Zone 10"
icon: "mdi:sprinkler"
id: zone_10
restore_mode: ALWAYS_OFF
pin:
sn74hc595: sprinkler_sn74hc595
number: 9
inverted: false
mode: output
on_turn_on:
then:
- if:
condition:
lambda: |-
return (id(active_zone) != 'z');
then:
- switch.turn_off: zone_1
- switch.turn_off: zone_2
- switch.turn_off: zone_3
- switch.turn_off: zone_4
- switch.turn_off: zone_5
- switch.turn_off: zone_6
- switch.turn_off: zone_7
- switch.turn_off: zone_8
- switch.turn_off: zone_9
#- switch.turn_off: zone_10
- switch.turn_off: zone_11
- switch.turn_off: zone_12
- switch.turn_on: led_10
- globals.set:
id: active_zone
value: '10'
on_turn_off:
- switch.turn_off: led_10
- globals.set:
id: active_zone
value: '99'
- platform: gpio
name: "Sprinkler Zone 11"
icon: "mdi:sprinkler"
id: zone_11
restore_mode: ALWAYS_OFF
pin:
sn74hc595: sprinkler_sn74hc595
number: 10
inverted: false
mode: output
on_turn_on:
then:
- if:
condition:
lambda: |-
return (id(active_zone) != 'z');
then:
- switch.turn_off: zone_1
- switch.turn_off: zone_2
- switch.turn_off: zone_3
- switch.turn_off: zone_4
- switch.turn_off: zone_5
- switch.turn_off: zone_6
- switch.turn_off: zone_7
- switch.turn_off: zone_8
- switch.turn_off: zone_9
- switch.turn_off: zone_10
#- switch.turn_off: zone_11
- switch.turn_off: zone_12
- switch.turn_on: led_11
- globals.set:
id: active_zone
value: '11'
on_turn_off:
- switch.turn_off: led_11
- globals.set:
id: active_zone
value: '99'
- platform: gpio
name: "Sprinkler Zone 12"
icon: "mdi:sprinkler"
id: zone_12
restore_mode: ALWAYS_OFF
pin:
sn74hc595: sprinkler_sn74hc595
number: 11
inverted: false
mode: output
on_turn_on:
then:
- if:
condition:
lambda: |-
return (id(active_zone) != 'z');
then:
- switch.turn_off: zone_1
- switch.turn_off: zone_2
- switch.turn_off: zone_3
- switch.turn_off: zone_4
- switch.turn_off: zone_5
- switch.turn_off: zone_6
- switch.turn_off: zone_7
- switch.turn_off: zone_8
- switch.turn_off: zone_9
- switch.turn_off: zone_10
- switch.turn_off: zone_11
#- switch.turn_off: zone_12
- switch.turn_on: led_12
- globals.set:
id: active_zone
value: '12'
on_turn_off:
- switch.turn_off: led_12
- globals.set:
id: active_zone
value: '99'
###################################################################
# Define Sprinkler Zone LEDs - Shift Register starts with Pin #0 #
# On the physical board, LEDs are using 220 Ohm resistors #
###################################################################
- platform: gpio
name: "Sprinkler Zone 1 LED"
icon: "mdi:led-outline"
id: led_1
restore_mode: ALWAYS_OFF
pin:
sn74hc595: sprinkler_sn74hc595_led
number: 0
inverted: false
- platform: gpio
name: "Sprinkler Zone 2 LED"
icon: "mdi:led-outline"
id: led_2
restore_mode: ALWAYS_OFF
pin:
sn74hc595: sprinkler_sn74hc595_led
number: 1
inverted: false
- platform: gpio
name: "Sprinkler Zone 3 LED"
icon: "mdi:led-outline"
id: led_3
restore_mode: ALWAYS_OFF
pin:
sn74hc595: sprinkler_sn74hc595_led
number: 2
inverted: false
- platform: gpio
name: "Sprinkler Zone 4 LED"
icon: "mdi:led-outline"
id: led_4
restore_mode: ALWAYS_OFF
pin:
sn74hc595: sprinkler_sn74hc595_led
number: 3
inverted: false
- platform: gpio
name: "Sprinkler Zone 5 LED"
icon: "mdi:led-outline"
id: led_5
restore_mode: ALWAYS_OFF
pin:
sn74hc595: sprinkler_sn74hc595_led
number: 4
inverted: false
- platform: gpio
name: "Sprinkler Zone 6 LED"
icon: "mdi:led-outline"
id: led_6
restore_mode: ALWAYS_OFF
pin:
sn74hc595: sprinkler_sn74hc595_led
number: 5
inverted: false
- platform: gpio
name: "Sprinkler Zone 7 LED"
icon: "mdi:led-outline"
id: led_7
restore_mode: ALWAYS_OFF
pin:
sn74hc595: sprinkler_sn74hc595_led
number: 6
inverted: false
- platform: gpio
name: "Sprinkler Zone 8 LED"
icon: "mdi:led-outline"
id: led_8
restore_mode: ALWAYS_OFF
pin:
sn74hc595: sprinkler_sn74hc595_led
number: 7
inverted: false
- platform: gpio
name: "Sprinkler Zone 9 LED"
icon: "mdi:led-outline"
id: led_9
restore_mode: ALWAYS_OFF
pin:
sn74hc595: sprinkler_sn74hc595_led
number: 8
inverted: false
- platform: gpio
name: "Sprinkler Zone 10 LED"
icon: "mdi:led-outline"
id: led_10
restore_mode: ALWAYS_OFF
pin:
sn74hc595: sprinkler_sn74hc595_led
number: 9
inverted: false
- platform: gpio
name: "Sprinkler Zone 11 LED"
icon: "mdi:led-outline"
id: led_11
restore_mode: ALWAYS_OFF
pin:
sn74hc595: sprinkler_sn74hc595_led
number: 10
inverted: false
- platform: gpio
name: "Sprinkler Zone 12 LED"
icon: "mdi:led-outline"
id: led_12
restore_mode: ALWAYS_OFF
pin:
sn74hc595: sprinkler_sn74hc595_led
number: 11
inverted: false
##########################################################
# Display Configuration - using Waveshare 2.9" V2 ePaper #
##########################################################
# SPI bus for Waveshare epaper display
spi:
clk_pin: GPIO18 #yellow wire
mosi_pin: GPIO23 #blue wire (din)
display:
- platform: waveshare_epaper
id: mydisplay
rotation: 270
#reset_duration: 200ms
reset_pin: GPIO16 #(RX2) white wire - optional
dc_pin: GPIO17 #(TX2) green wire
cs_pin: GPIO05 #orange wire
busy_pin: GPIO19 #purple wire - optional
model: 2.90inv2 #296 x 128 pixels
#update_interval: 30s
#full_update_every: 1
reset_duration: 2ms
update_interval: 1s
full_update_every: 3600
lambda: |-
// Prints Date and Time in top left corner with rectangle box
it.strftime(3,2, id(font4), "%a %b %d %I:%M %p", id(homeassistant_time).now());
it.printf(160,2, id(font4), "%s", id(displaystatus).state.c_str());
it.rectangle(0, 0, 296, 18);
// Prints WiFi Strength
if (id(wifi_level).state >= -50) {
it.printf(290, 9, id(display_icons_20), TextAlign::CENTER_RIGHT, "\U000F08BE");}
if (id(wifi_level).state >= -60) {
it.printf(290, 9, id(display_icons_20), TextAlign::CENTER_RIGHT, "\U000F08BD");}
if (id(wifi_level).state >= -70) {
it.printf(290, 9, id(display_icons_20), TextAlign::CENTER_RIGHT, "\U000F08BC");}
if (id(wifi_level).state >= -90) {
it.printf(290, 9, id(display_icons_20), TextAlign::CENTER_RIGHT, "\U000F08BF");}
// Schedule Header
it.print(4, 19, id(font1), "Schedule");
it.line(2, 36, 72, 36);
it.print(152,19, id(font1), "Days / Zones");
it.line(120, 36, 294, 36);
// Schedule 1
it.print(4,44, id(font3), "1");
it.printf(22, 39, id(font2), "%s", id(s1displaymasterstate).state.c_str());
it.printf(140,39, id(font2), "%s", id(s1displaydays).state.c_str());
it.printf(22,55, id(font2), "%s", id(s1starttime).state.c_str());
it.printf(120, 55, id(font2), "%s",id(s1displayzones).state.c_str());
it.line(2, 71, 294, 71);
// Schedule 2
it.print(4, 78, id(font3), "2");
it.printf(22, 73, id(font2), "%s", id(s2displaymasterstate).state.c_str());
it.printf(138, 73, id(font2), "%s",id(s2displaydays).state.c_str());
it.printf(22,89, id(font2), "%s", id(s2starttime).state.c_str());
it.printf(120, 89, id(font2), "%s",id(s2displayzones).state.c_str());
it.rectangle(0, 106, 296, 22);
// Weather Condition
if (id(weather_icon).state == "clear-night") {
it.printf(3, 107, id(conditions_22), "\U000F0594");}
if (id(weather_icon).state == "cloudy") {
it.printf(3, 107, id(conditions_22), "\U000F0590");}
if (id(weather_icon).state == "partlycloudy") {
it.printf(3, 107, id(conditions_22), "\U000F0595");}
if (id(weather_icon).state == "fog") {
it.printf(3, 107, id(conditions_22), "\U000F0591");}
if (id(weather_icon).state == "hail") {
it.printf(3, 107, id(conditions_22), "\U000F0592");}
if (id(weather_icon).state == "lightning") {
it.printf(3, 107, id(conditions_22), "\U000F0593");}
if (id(weather_icon).state == "lightning-rainy") {
it.printf(3, 107, id(conditions_22), "\U000F067E");}
if (id(weather_icon).state == "pouring") {
it.printf(3, 107, id(conditions_22), "\U000F0596");}
if (id(weather_icon).state == "rainy") {
it.printf(3, 107, id(conditions_22), "\U000F0597");}
if (id(weather_icon).state == "snowy") {
it.printf(3, 107, id(conditions_22), "\U000F0F36");}
if (id(weather_icon).state == "snowy-rainy") {
it.printf(3, 107, id(conditions_22), "\U000F067F");}
if (id(weather_icon).state == "sunny") {
it.printf(3, 107, id(conditions_22), "\U000F0599");}
if (id(weather_icon).state == "windy") {
it.printf(3, 107, id(conditions_22), "\U000F059D");}
if (id(weather_icon).state == "windy-variant") {
it.printf(3, 107, id(conditions_22), "\U000F059E");}
if (id(weather_icon).state == "exceptional") {
it.printf(3, 107, id(conditions_22), "\U000F0F38");}
it.print(31, 110, id(font2), "Precip:");
it.printf(75, 108, id(font1), "%.2f", id(precipitation).state); //Need to fix - set up Visual Crossing WeatherToday
it.print(109, 112, id(font_10), "in");
// Active Zone & Time Remaining
it.print(123, 110, id(font2), "Act Zone:");
it.printf(185, 108, id(font1), "%s", id(displayactivezone).state.c_str());
//it.print(185, 108, id(font1), "??"); //Need to fix
it.print(206, 110, id(font2), "Mins Rem:");
it.printf(270, 108, id(font1), "%s", id(displaytimeremaining).state.c_str());
//it.print(270, 108, id(font1), "??"); //Need to fix