Sorry, work caught up with me. Anyways, here’s everything condensed and easily manageable.
automation
automation:
- alias: Double-switch automation
mode: parallel
trigger:
- platform: state
entity_id:
- sensor.living_room_wall_switch_action
action:
- service: script.my_over_complicated_setup
data:
sensor: "{{ trigger.entity_id }}"
script
script:
my_over_complicated_setup:
mode: parallel
fields:
sensor:
description: sensor being used
example: sensor.living_room_wall_switch_action
variables:
config:
sensor.living_room_wall_switch_action:
left_light: light.living_room_tv_light
right_light: light.living_room_table_light
left: scene.living_room_only_tv_light
right: scene.living_room_only_dining_light
both: scene.living_room_only_full_light
no_switches: scene.living_room_no_lights
continue: >
{{ config.get(sensor) is not None }}
left_light: >
{{ is_state(config.left_light, 'on') if continue else False }}
right_light: >
{{ is_state(config.right_light, 'on') if continue else False }}
target_scene: >
{{ config.get(sensor, {}).get(states(sensor)) }}
scene:
{% if continue %}
{% if left_light and right_light %}
{{ config.both }}
{% elif left_light and not right_light %}
{{ config.left }}
{% elif not left_light and right_light %}
{{ config.right %}
{% else %}
{{ config.no_switches }}
{% endif %}
expected_scene: >
{{ target_scene == scene }}
sequence:
- condition: template
value_template: "{{ continue and expected_scene }}"
- service: scene.turn_on
target:
entity_id: "{{ scene }}"
Then for each new sensor/light combos, just add to the config variables. For example, I want to add some_other_room…
trigger would change to:
- platform: state
entity_id:
- sensor.living_room_wall_switch_action
- sensor.some_other_room_switch_action
config in the script would change to:
config:
sensor.living_room_wall_switch_action:
left_light: light.living_room_tv_light
right_light: light.living_room_table_light
left: scene.living_room_only_tv_light
right: scene.living_room_only_dining_light
both: scene.living_room_only_full_light
no_switches: scene.living_room_no_lights
# Added my other room.
sensor.some_other_room_switch_action:
left_light: light.some_other_room_tv_light
right_light: light.some_other_room_table_light
left: scene.some_other_room_only_tv_light
right: scene.some_other_room_dining_light
both: scene.some_other_room_only_full_light
no_switches: scene.some_other_room_no_lights
Lastly, your single button UI check…
tap_action:
action: call-service
service: script.my_over_complicated_setup
service_data:
sensor: sensor.living_room_wall_switch_action
Much more managable.
To be honest, you have redundancy in it. I’m not sure why you check the lights to ensure you’re calling the correct scene. I’d just use the scene from the sensor. This is what that setup would look like
automation:
automation:
- alias: Double-switch automation
mode: parallel
trigger:
- platform: state
entity_id:
- sensor.living_room_wall_switch_action
action:
- service: script.my_over_complicated_setup
data:
sensor: "{{ trigger.entity_id }}"
expected: "{{ trigger.to_state.state }}"
script
script:
my_over_complicated_setup:
mode: parallel
fields:
sensor:
description: sensor being used
example: sensor.living_room_wall_switch_action
expected:
description: expected state
example: left
variables:
config:
sensor.living_room_wall_switch_action:
left_light: light.living_room_tv_light
right_light: light.living_room_table_light
left: scene.living_room_only_tv_light
right: scene.living_room_only_dining_light
both: scene.living_room_only_full_light
no_switches: scene.living_room_no_lights
continue: >
{{ config.get(sensor) is not None }}
target_scene: >
{{ config.get(sensor, {}).get(expected) }}
sequence:
- condition: template
value_template: "{{ continue }}"
- service: scene.turn_on
target:
entity_id: "{{ target_scene }}"
then the UI buttons
tap_action:
action: call-service
service: script.my_over_complicated_setup
service_data:
sensor: sensor.living_room_wall_switch_action
expected: left
FYI there may be is typos (EDIT: I Think i fixed them all), I pushed this out pretty quick but it should get the idea across.