Yes, the overlap is part of the issue. Essentially, I want to override the switch method and when it is called first turn off all the valves, then turn on the requested sprinkler valve.
I did try a “kludge” where I created input_boolean helpers to indirectly call the valve switches. That way I could run the code to turn off all valves before turning on the requested valve.
Here switch.sprinkler_valve_group
is a group helper with all the valves, and the automation below first turns that off (therefore turning all valves off), then turns on the requested sprinkler valve (by string replacing the input_boolean name).
This is just a test with three valves:
alias: "Test: trigger on any switch"
description: ""
trigger:
- platform: state
entity_id:
- input_boolean.toggle_1
- input_boolean.toggle_2
- input_boolean.toggle_3
to: "on"
condition: []
action:
- service: switch.turn_off
target:
entity_id: switch.sprinkler_valve_group
data: {}
- delay:
hours: 0
minutes: 0
seconds: 2
milliseconds: 0
- service: input_boolean.turn_on
target:
entity_id: |
{{ trigger.entity_id }}
- service: switch.turn_on
target:
entity_id: >
{{ trigger.entity_id|replace('input_boolean.toggle','switch.sprinkler_valve') }}
mode: single
So, input_boolean.toggle_2
turns on switch.sprinkler_valve_2
.
That delay and turning on the input_boolean (which is what triggered the automation) is in case the valve is already on (see next automation).
Now, to keep the input_boolean helpers in sync, need to turn those off when a valve is turned off:
alias: "Test: turn off helper"
description: ""
trigger:
- platform: state
entity_id:
- switch.sprinkler_valve_1
- switch.sprinkler_valve_2
- switch.sprinkler_valve_2
to: "off"
condition: []
action:
- service: input_boolean.turn_off
target:
entity_id: >
{{ trigger.entity_id|replace('switch.sprinkler_valve','input_boolean.toggle') }}
data: {}
mode: queued
In other words, when the first automation calls the group helper switch.sprinkler_valve_group
and turns off all the valves, each one then triggers this second automation and turns off the associated input_boolean helper.
All this feels very hackish and fragile and not worth actually using.
One disappointing thing is that it would be nice to trigger on the group helper, but then trigger.entity_id
is the group’s ID, not the actual member of the group. It would be handy to abstract away the collection of valves.
Also, it doesn’t appear I can create a group helper for a collection of input_boolean helpers.
Have to rethink the approach or give up.