Need Help: Automation - If, Else if possible?

Hello again,

i’ve got several Automation for Switch in deconz events but:
Is it possible to create an Automation for two light with Else if Like? Why? I want to use a single Switch (only single click) to Control 2 Lights. 1 in, 1 Off 2 on, both on and both Off.

  • If light.1 = Off and light.2=Off Then Turn on light.1

  • Else If light.1 = on and light.2=Off Then Turn off light.1 and Turn on light.2

  • Else If light.1 = off and light.2=On Then Turn on light.1

  • Else If light.1 = on and light.2=on Then Turn off light.1 and Turn off light.2

Sorry for my poor english.

So, if I read it right

  • the logic for light 1 always toggles (first bullet light 1 is off, turn it on - second bullet on, turn it off - third its off turn it on, fourth its on, turn it off)
  • the logic for light 2 is always turning on if both bulbs are in different states, and off if they’re the same.

So I’d do it like this…

trigger:
  platform: state
  entity_id: YOUR BUTTON
  to: 'on' 
action:
  - service: >
      {% if states('light.1') != states('light.2') %} light.turn_on
      {% else %} light.turn_off {% endif %} 
    entity_id: light.2 
  - service: light.toggle
    entity_id: light.1

Edited this like 3 times now because I keep confusing myself :see_no_evil: - I’m pretty certain it’s right though, give it a go :slightly_smiling_face:

1 Like

You can do this with choose:

action:
- choose:
  - conditions:
    - condition: state
      entity_id: 
      - light.one
      - light.two
      state: 'off'
    sequence:
    - service: light.turn_on
      data:
        entity_id: light.one
  - conditions:
    - condition: state
      entity_id: light.one
      state: 'on'
    - condition: state
      entity_id: light.two
      state: 'off'
    sequence:
    - service: light.turn_off
      data:
        entity_id: light.one
    - service: light.turn_on
      data:
        entity_id: light.one
  - conditions:
    - condition: state
      entity_id: light.one
      state: 'off'
    - condition: state
      entity_id: light.two
      state: 'on'
    sequence:
    - service: light.turn_on
      data:
        entity_id: light.one
  - conditions:
    - condition: state
      entity_id: 
      - light.one
      - light.two
      state: 'on'
    sequence:
    - service: light.turn_off
      data:
        entity_id: 
        - light.one
        - light.two

It is longer than using a template, but significantly more flexible

Thanks a lot, it´s working:

alias: kueche6-1_doppelt
description: ''
trigger:
  - platform: event
    event_type: deconz_event
    event_data:
      id: kueche6
      event: 1004
condition: []
action:
  - service: >-
      {% if states('switch.kuchenlampe') != states('light.kuchenblock') %}
      light.turn_on  {% else %} light.turn_off {% endif %} 
    entity_id: light.kuchenblock
    data: {}
  - service: switch.toggle
    entity_id: switch.kuchenlampe
mode: restart

Is it possible to add color and brightness for light.kuchenblock? I tried to add in in data, but then the automation stopped working.

BG,
Niels

1 Like

Thanks for sequence, will try next week. If i unterstand it right i can expand it for three or more lights / switches.

You can expand that as far as you want