Skip to content

Instantly share code, notes, and snippets.

@patrickdk77
Last active October 21, 2022 12:01
Show Gist options
  • Save patrickdk77/947799a3feaf4467df6fae359eb0afed to your computer and use it in GitHub Desktop.
Save patrickdk77/947799a3feaf4467df6fae359eb0afed to your computer and use it in GitHub Desktop.
Sprinkler System esphome
substitutions:
display_name: Sprinkler
heartbeat: 900s
esphome:
name: sprinkler
platform: ESP8266
board: d1_mini
board_flash_mode: dout
esp8266_restore_from_flash: true
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_pass
fast_connect: off
manual_ip:
static_ip: !secret ip_sprinkler
gateway: !secret ip_gateway
subnet: !secret ip_subnet
dns1: !secret ip_dns1
dns2: !secret ip_dns2
#captive_portal:
logger:
baud_rate: 0
# level: NONE
api:
# password: !secret portal_pass
ota:
# password: !secret portal_pass
web_server:
port: 80
#mqtt:
# broker: !secret mqtt_broker
# port: !secret mqtt_tls_port
# username: !secret mqtt_user
# password: !secret mqtt_pass
# discovery: true
# ssl_fingerprints:
# - !secret mqtt_fingerprint_sha1
# Zone1 Nothing
# Zone2
# Zone3
# Zone4 Back yard left side
# Zone5 Back yard back
# Zone6
# Zone7
# Zone8
# Zone9
# Zone10
# Zone11
# Zone12
sun:
latitude: !secret latitude
longitude: !secret longitude
time:
# - platform: homeassistant
- platform: sntp
timezone: !secret timezone
servers:
- !secret ip_ntp1
- !secret ip_ntp2
id: homeassistant_time
# on_time:
# - seconds: 0
# minutes: 10
# hours: 6,23
# then:
# - switch.turn_off: master_disable
# - delay: 5s
# - switch.turn_on: zone5
# - delay: 900s
# - switch.turn_off: zone5
# - delay: 5s
# - switch.turn_on: master_disable
# - delay: 5s
# - switch.turn_off: master_disable
# - delay: 5s
# - switch.turn_on: master_disable
# - seconds: 0
# minutes: 30
# hours: 8,17
# then:
# - switch.turn_on: zone8
# - delay: 300s
# - switch.turn_off: zone8
binary_sensor:
- platform: gpio
pin:
number: GPIO16
mode: INPUT #pullup doesn't work add 10k resistor
inverted: true
filters:
- delayed_on: 10s
- delayed_off: 10s
name: "${display_name} Rain Sense"
id: rain
on_state:
then:
- if:
condition:
binary_sensor.is_on: rain
then:
- switch.turn_off: relay_zone1
- switch.turn_off: relay_zone2
- switch.turn_off: relay_zone3
- switch.turn_off: relay_zone4
- switch.turn_off: relay_zone5
- switch.turn_off: relay_zone6
- switch.turn_off: relay_zone7
- switch.turn_off: relay_zone8
sn74hc595:
- id: 'sn74hc595_hub'
data_pin: GPIO12
clock_pin: GPIO14
latch_pin: GPIO13
oe_pin: GPIO0
sr_count: 1
switch:
- platform: template
name: "${display_name} Master Disable"
id: master_disable
restore_state: true
turn_on_action:
- switch.turn_off: relay_zone1
- switch.turn_off: relay_zone2
- switch.turn_off: relay_zone3
- switch.turn_off: relay_zone4
- switch.turn_off: relay_zone5
- switch.turn_off: relay_zone6
- switch.turn_off: relay_zone7
- switch.turn_off: relay_zone8
- switch.template.publish:
id: master_disable
state: ON
turn_off_action:
- switch.template.publish:
id: master_disable
state: OFF
- platform: gpio
internal: true
id: relay_zone1
restore_mode: ALWAYS_OFF
pin:
sn74hc595: sn74hc595_hub
number: 0
inverted: true
- platform: gpio
internal: true
id: relay_zone2
restore_mode: ALWAYS_OFF
pin:
sn74hc595: sn74hc595_hub
number: 1
inverted: true
- platform: gpio
internal: true
id: relay_zone3
restore_mode: ALWAYS_OFF
pin:
sn74hc595: sn74hc595_hub
number: 2
inverted: true
- platform: gpio
internal: true
id: relay_zone4
restore_mode: ALWAYS_OFF
pin:
sn74hc595: sn74hc595_hub
number: 3
inverted: true
- platform: gpio
internal: true
id: relay_zone5
restore_mode: ALWAYS_OFF
pin:
sn74hc595: sn74hc595_hub
number: 4
inverted: true
- platform: gpio
internal: true
id: relay_zone6
restore_mode: ALWAYS_OFF
pin:
sn74hc595: sn74hc595_hub
number: 5
inverted: true
- platform: gpio
internal: true
id: relay_zone7
restore_mode: ALWAYS_OFF
pin:
sn74hc595: sn74hc595_hub
number: 6
inverted: true
- platform: gpio
internal: true
id: relay_zone8
restore_mode: ALWAYS_OFF
pin:
sn74hc595: sn74hc595_hub
number: 7
inverted: true
- platform: template
name: "${display_name} Zone 1"
id: zone1
lambda: |-
if (id(relay_zone1).state) {
return true;
} else {
return false;
}
turn_on_action:
then:
if:
condition:
- binary_sensor.is_off: rain
- switch.is_off: master_disable
then:
- switch.turn_on: relay_zone1
- switch.template.publish:
id: zone1
state: ON
else:
- switch.template.publish:
id: zone1
state: OFF
turn_off_action:
- switch.turn_off: relay_zone1
- switch.template.publish:
id: zone1
state: OFF
- platform: template
name: "${display_name} Zone 2"
id: zone2
lambda: |-
if (id(relay_zone2).state) {
return true;
} else {
return false;
}
turn_on_action:
then:
if:
condition:
- binary_sensor.is_off: rain
- switch.is_off: master_disable
then:
- switch.turn_on: relay_zone2
- switch.template.publish:
id: zone2
state: ON
else:
- switch.template.publish:
id: zone2
state: OFF
turn_off_action:
- switch.turn_off: relay_zone2
- switch.template.publish:
id: zone2
state: OFF
- platform: template
name: "${display_name} Zone 3"
id: zone3
lambda: |-
if (id(relay_zone3).state) {
return true;
} else {
return false;
}
turn_on_action:
then:
if:
condition:
- binary_sensor.is_off: rain
- switch.is_off: master_disable
then:
- switch.turn_on: relay_zone3
- switch.template.publish:
id: zone3
state: ON
else:
- switch.template.publish:
id: zone3
state: OFF
turn_off_action:
- switch.turn_off: relay_zone3
- switch.template.publish:
id: zone3
state: OFF
- platform: template
name: "${display_name} Zone 4"
id: zone4
lambda: |-
if (id(relay_zone4).state) {
return true;
} else {
return false;
}
turn_on_action:
then:
if:
condition:
- binary_sensor.is_off: rain
- switch.is_off: master_disable
then:
- switch.turn_on: relay_zone4
- switch.template.publish:
id: zone4
state: ON
else:
- switch.template.publish:
id: zone4
state: OFF
turn_off_action:
- switch.turn_off: relay_zone4
- switch.template.publish:
id: zone4
state: OFF
- platform: template
name: "${display_name} Zone 5"
id: zone5
lambda: |-
if (id(relay_zone5).state) {
return true;
} else {
return false;
}
turn_on_action:
then:
if:
condition:
- binary_sensor.is_off: rain
- switch.is_off: master_disable
then:
- switch.turn_on: relay_zone5
- switch.template.publish:
id: zone5
state: ON
else:
- switch.template.publish:
id: zone5
state: OFF
turn_off_action:
- switch.turn_off: relay_zone5
- switch.template.publish:
id: zone5
state: OFF
- platform: template
name: "${display_name} Zone 6"
id: zone6
lambda: |-
if (id(relay_zone6).state) {
return true;
} else {
return false;
}
turn_on_action:
then:
if:
condition:
- binary_sensor.is_off: rain
- switch.is_off: master_disable
then:
- switch.turn_on: relay_zone6
- switch.template.publish:
id: zone6
state: ON
else:
- switch.template.publish:
id: zone6
state: OFF
turn_off_action:
- switch.turn_off: relay_zone6
- switch.template.publish:
id: zone6
state: OFF
- platform: template
name: "${display_name} Zone 7"
id: zone7
lambda: |-
if (id(relay_zone7).state) {
return true;
} else {
return false;
}
turn_on_action:
then:
if:
condition:
- binary_sensor.is_off: rain
- switch.is_off: master_disable
then:
- switch.turn_on: relay_zone7
- switch.template.publish:
id: zone7
state: ON
else:
- switch.template.publish:
id: zone7
state: OFF
turn_off_action:
- switch.turn_off: relay_zone7
- switch.template.publish:
id: zone7
state: OFF
- platform: template
name: "${display_name} Zone 8"
id: zone8
lambda: |-
if (id(relay_zone8).state) {
return true;
} else {
return false;
}
turn_on_action:
then:
if:
condition:
- binary_sensor.is_off: rain
- switch.is_off: master_disable
then:
- switch.turn_on: relay_zone8
- switch.template.publish:
id: zone8
state: ON
else:
- switch.template.publish:
id: zone8
state: OFF
turn_off_action:
- switch.turn_off: relay_zone8
- switch.template.publish:
id: zone8
state: OFF
sensor:
- platform: pulse_counter
pin: GPIO3
name: "${display_name} Water Consumption"
id: water_counter
update_interval: 10s
filters:
#- lambda: return (x / 3.78541 / 450.0);
- multiply: 0.000587049
- or:
- heartbeat: ${heartbeat}
- delta: 0.01
unit_of_measurement: "G/min"
accuracy_decimals: 2
- platform: total_daily_energy
name: "Daily Sprinkler Water Usage"
power_id: water_counter
unit_of_measurement: G
accuracy_decimals: 0
filters:
- multiply: 60
- or:
- heartbeat: ${heartbeat}
- delta: 1
- platform: wifi_signal
id: wifi_sig
name: "${display_name} RSSI"
unit_of_measurement: "dBm"
update_interval: 60s
filters:
- median:
window_size: 7
send_every: 5
send_first_at: 5
- or:
- heartbeat: 300s
- delta: 3
@patrickdk77
Copy link
Author

it works fine and the only change I plan on doing is removing the shift register with an i2c gpio module, as the shift register has proven to have too much interference and randomly flipping relays on sometimes. This has become better with soldering it, would probably be perfect with a custom pcb with the correct ground star for the shift register. But then most all of this logic applies either way.

@ionultd
Copy link

ionultd commented Jan 17, 2022

Could you explain for me: removing the shift register with an i2c gpio module

also: This has become better with soldering it

Thanks again for your work on this

@patrickdk77
Copy link
Author

https://electronics.stackexchange.com/questions/139759/emf-interference-on-arduino-and-breadboard-using-74hc595-shift-register-how-t

i2c is just more resistant and I haven't had this issue using them.
Such as the PCF8574 or MCP23017.

@ionultd
Copy link

ionultd commented Jan 17, 2022

Aaah right. So you intend to redesign the board or see if you can just replace the chip?

Oh yes and what is the value for 'timezone' to put in secrets as I am in New Zealand and am not sure what one would used here?
UTC+13:00
NZDT — New Zealand Daylight Time

@ionultd
Copy link

ionultd commented Mar 6, 2022

@patrickdk77 Was hoping you would reply to my above comment. Hopefully you are well and can reply.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment