# 2 bulbs, 1 button. Cycle trough all combinations, how?

Help,

I have 2 lightbublbs and one button.
With every single_click, I want to cycle through following 4 combinations

``````L1  L2
----------
off off
on  off
off on
on  on
``````

Can somebody help me with this setup in hass?
Where should I start?
New to home assistant, so a newbie level will be appreciated

kind regards,
Bart

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.

Cool!

I solved it differently:
I created 4 scenes

``````# -------------------------------------------
- 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
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.

What do you think? What is a best practice?

kind regards,
Bart

Go with whatever works best for you. Your solution requires:

1. input_select
2. scenes
3. automation

The solution I offered requires one automation. Here it is again using the added information you provided regarding the source of the trigger:

``````- id: '0x00158d0002f38837_click_right'
alias: '(S03) Switch MQTT button click: right'
trigger:
- platform: mqtt
topic: zigbee2mqtt/0x00158d0002f38837
condition:
- condition: template