This seems to be the best I could come up with:
In my main config YAML file I have this:
substitutions:
name: esp-24-sprinkler
friendly_name: ESP-24-Sprinkler
static_ip_address: 192.168.0.3
esp8266:
board: esp01_1m
sn74hc595:
- id: 'sn74hc595_hub'
data_pin: GPIO14
clock_pin: GPIO13
latch_pin: GPIO12
oe_pin: GPIO05
sr_count: 3
packages:
connect: !include includes/connections.yaml
station_1: !include { vars: { station: 1, pin: 0 }, file: includes/package_sprinkler_switch.yaml }
station_2: !include { vars: { station: 2, pin: 1 }, file: includes/package_sprinkler_switch.yaml }
station_3: !include { vars: { station: 3, pin: 2 }, file: includes/package_sprinkler_switch.yaml }
station_4: !include { vars: { station: 4, pin: 3 }, file: includes/package_sprinkler_switch.yaml }
station_5: !include { vars: { station: 5, pin: 4 }, file: includes/package_sprinkler_switch.yaml }
station_6: !include { vars: { station: 6, pin: 5 }, file: includes/package_sprinkler_switch.yaml }
station_7: !include { vars: { station: 7, pin: 6 }, file: includes/package_sprinkler_switch.yaml }
station_8: !include { vars: { station: 8, pin: 7 }, file: includes/package_sprinkler_switch.yaml }
station_9: !include { vars: { station: 9, pin: 8 }, file: includes/package_sprinkler_switch.yaml }
station_10: !include { vars: { station: 10, pin: 9 }, file: includes/package_sprinkler_switch.yaml }
station_11: !include { vars: { station: 11, pin: 10 }, file: includes/package_sprinkler_switch.yaml }
station_12: !include { vars: { station: 12, pin: 11 }, file: includes/package_sprinkler_switch.yaml }
station_13: !include { vars: { station: 13, pin: 12 }, file: includes/package_sprinkler_switch.yaml }
station_14: !include { vars: { station: 14, pin: 13 }, file: includes/package_sprinkler_switch.yaml }
station_15: !include { vars: { station: 15, pin: 14 }, file: includes/package_sprinkler_switch.yaml }
station_16: !include { vars: { station: 16, pin: 15 }, file: includes/package_sprinkler_switch.yaml }
station_17: !include { vars: { station: 17, pin: 16 }, file: includes/package_sprinkler_switch.yaml }
station_18: !include { vars: { station: 18, pin: 17 }, file: includes/package_sprinkler_switch.yaml }
station_19: !include { vars: { station: 19, pin: 18 }, file: includes/package_sprinkler_switch.yaml }
station_20: !include { vars: { station: 20, pin: 19 }, file: includes/package_sprinkler_switch.yaml }
station_21: !include { vars: { station: 21, pin: 20 }, file: includes/package_sprinkler_switch.yaml }
station_22: !include { vars: { station: 22, pin: 21 }, file: includes/package_sprinkler_switch.yaml }
station_23: !include { vars: { station: 23, pin: 22 }, file: includes/package_sprinkler_switch.yaml }
station_24: !include { vars: { station: 24, pin: 23 }, file: includes/package_sprinkler_switch.yaml }
Then my include is just this:
substitutions:
max_time_on: 2h
switch:
- platform: gpio
name: "ESP Station $station"
id: station_$station
pin:
sn74hc595: sn74hc595_hub
number: $pin
on_turn_on:
- script.execute: on_turn_on_$station
on_turn_off:
- script.stop: on_turn_on_$station
script:
- id: on_turn_on_$station
mode: restart
then:
- logger.log: "$max_time_on timeout started for sprinker $station"
- delay: $max_time_on
- logger.log: "Auto-timeout sprinker $station after $max_time_on"
- switch.turn_off: station_$station
I tried to figure out if I could do any bash math so I didn’t need to have a separate $pin
variable, but no luck. Would be handy to have some kind of loop structure, but this is pretty easy to do.
Only addition might be to have a homeassistant.action:
that I could use to have HA notify me if a switch was turned off in this way. Of course, the purpose of this is to turn off the switch IF Home Assistant is not connected.