I don’t know what you are using to detect the single-click so I’ve skipped that part (trigger) in the automation. Here’s my suggestion for the action:
action:
- service: light.toggle
entity_id: light.l1
- service_template: >
{% set L2 = 1 if is_state('light.l2', 'on') else 0 %}
{% set L1 = 1 if is_state('light.l1', 'on') else 0 %}
{% set n = (L2 * 2) + L1 + 1 %}
{% set next = 0 if n > 3 else n %}
light.turn_{{'on' if next > 1 else 'off'}}
entity_id: light.l2
Here is the result of swapping your table’s two columns:
L2 L1
----------
off off 0 0 zero
off on 0 1 one
on off 1 0 two
on on 1 1 three
The sequence is counting from zero to three in binary.
L1 is easy to control because all we need to do is toggle its state.
L2 is a bit more challenging. We need to calculate the binary number. If it is greater than 1 then it needs to be turned on, else it is turned off.
# -------------------------------------------
- name: Lamp Peter Frans s1
entities:
light.Lamp_Peter_Frans_01: off
light.Lamp_Peter_Frans_02: off
- name: Lamp Peter Frans s2
entities:
light.Lamp_Peter_Frans_01: off
light.Lamp_Peter_Frans_02: on
- name: Lamp Peter Frans s3
entities:
light.Lamp_Peter_Frans_01: on
light.Lamp_Peter_Frans_02: off
- name: Lamp Peter Frans s4
entities:
light.Lamp_Peter_Frans_01: on
light.Lamp_Peter_Frans_02: on
An input select
# ===============================================
# INPUT_SELECT
# ===============================================
input_select:
lamp_peter_frans:
name: Light Mode
options:
- scene 1
- scene 2
- scene 3
- scene 4
initial: scene 1
icon: mdi:format-list-bulleted
And an automation:
# ==================================================
# VERSCHILLENDE AUTOMATIONS VOOR DE LAMP VAN PETER FRANS
# ==================================================
# De waarde van de input_select bepaalt welke scene wordt uitgevoerd
# Onderaan de automatisatie die door de waarden van de input_select cyclet
# -------------------------------------------
- alias: Lamp_Peter_Frans_s1
trigger:
- platform: state
entity_id: input_select.lamp_peter_frans
to: scene 1
action:
entity_id: scene.Lamp_Peter_Frans_s1
service: scene.turn_on
# -------------------------------------------
- alias: Lamp_Peter_Frans_s2
trigger:
- platform: state
entity_id: input_select.lamp_peter_frans
to: scene 2
action:
entity_id: scene.Lamp_Peter_Frans_s2
service: scene.turn_on
# -------------------------------------------
- alias: Lamp_Peter_Frans_s3
trigger:
- platform: state
entity_id: input_select.lamp_peter_frans
to: scene 3
action:
entity_id: scene.Lamp_Peter_Frans_s3
service: scene.turn_on
# -------------------------------------------
- alias: Lamp_Peter_Frans_s4
trigger:
- platform: state
entity_id: input_select.lamp_peter_frans
to: scene 4
action:
entity_id: scene.Lamp_Peter_Frans_s4
service: scene.turn_on
wich is triggerd by another automation:
# ==================================================
# GLOBALE TRIGGER: XIAOMI SWITCH S03
# ==================================================
# door op de rechterknop te klikken
# doorloop je alle mogelijke combinaties van de lamp
- id: '0x00158d0002f38837_click_right'
alias: '(S03) Switch MQTT button click: right'
trigger:
- platform: mqtt
topic: zigbee2mqtt/0x00158d0002f38837
condition:
- condition: template
value_template: '{{ "right" == trigger.payload_json.click}}'
action:
entity_id: input_select.lamp_peter_frans
service: input_select.select_next
For me it feels more “natural” and working with scenes and gives more flexibility.