Multiple scenes for a single bulb with a quad controller

OK, I’ve been struggling with an automation that I knew was going to be a challenge. The funny thing is, the end result is quite basic and simple, but it’s sort of overwhelmed me trying to figure it out.

Here’s the basics:

  1. I have an RGB Hue bulb
  2. I have a quad button MOES zigbee controller that can trigger automations

The quad controller is labeled “Bright” on button 1, “Dim” on button 2, and “Blue” on button 3.
For the bulb, brightness of 130 is bright, 17 is dim, and 120 is blue. I figured that’s enough to figure out what the current state is.

Desired operations:
If the light is OFF, activate the appropriate scene based on the button. This part is easy.

If the light is ON, activate the scene if it’s DIFFERENT than the current scene. In other words:
If the lamp is bright, and button 2 is pressed, make it dim
If the lamp is bright, and button 3 is pressed, make it blue
And if the lamp is bright, and button 1 is pressed (bright) then turn it off. Basically a toggle.

And so on for the other buttons too.

Here’s the logic I have been trying:

For activating scenes if the bulb is off, that’s done and easy (choose based on a template ID).

If the bulb is on:
If button 1 is pressed, check the brightness and if it’s 130 (bright) then turn the light off
If button 2 is pressed, and the brightness is NOT 17 then set the “dim” scene
if button 3 is pressed, and the brightness is NOT 120 then set the “blue” scene
and so on… but this seems like a bad way to do this (?)

I think it’s just a logic thing but it’s not coming to me at the moment. If the above is right, then I am a little stuck on how to actually check the brightness value.

Do I use a “numeric_state” somehow, or a template? And what’s with the “above” and “below” but no “equals”? Maybe a template can be used to match a brightness value exactly?

I’ve been looking at templates but it’s unclear to me what I need to do to use the brightness as a condition to decide what to do.

Thanks for any advice here!

Dennis

OK, spent a little time thinking about it and did it the most logical way I came up with, but I’m sure there are better more elegant solutions. This works exactly as I wanted it to, as described, but seems “bulky” or bloated. But maybe this is just a good way to get this done?

alias: "Testing: Multi dim quad buttons"
description: ""
trigger:
  - platform: device
    domain: mqtt
    device_id: cd03f5fe7
    type: action
    subtype: 1_single
    discovery_id: action_1_single
    id: "1"
  - platform: device
    domain: mqtt
    device_id: cd03f5fe7
    type: action
    subtype: 2_single
    discovery_id: action_2_single
    id: "2"
  - platform: device
    domain: mqtt
    device_id: cd03f5fe7
    type: action
    subtype: 3_single
    discovery_id: action_3_single
    id: "3"
condition: []
action:
  - choose:
      - conditions:
          - condition: state
            entity_id: light.fr_hue_color_tv_left
            state: "off"
        sequence:
          - choose:
              - conditions:
                  - condition: trigger
                    id: "1"
                sequence:
                  - service: scene.turn_on
                    target:
                      entity_id: scene.testing_hue_bulb_bright
                    metadata: {}
              - conditions:
                  - condition: trigger
                    id: "2"
                sequence:
                  - service: scene.turn_on
                    target:
                      entity_id: scene.testing_hue_bulb_dim
                    metadata: {}
              - conditions:
                  - condition: trigger
                    id: "3"
                sequence:
                  - service: scene.turn_on
                    target:
                      entity_id: scene.testing_hue_blue
                    metadata: {}
      - conditions:
          - condition: numeric_state
            entity_id: light.fr_hue_color_tv_left
            above: 129
            below: 131
            attribute: brightness
        sequence:
          - choose:
              - conditions:
                  - condition: trigger
                    id: "1"
                sequence:
                  - service: light.turn_off
                    data: {}
                    target:
                      entity_id: light.fr_hue_color_tv_left
              - conditions:
                  - condition: trigger
                    id: "2"
                sequence:
                  - service: scene.turn_on
                    target:
                      entity_id: scene.testing_hue_bulb_dim
                    metadata: {}
              - conditions:
                  - condition: trigger
                    id: "3"
                sequence:
                  - service: scene.turn_on
                    target:
                      entity_id: scene.testing_hue_blue
                    metadata: {}
      - conditions:
          - condition: numeric_state
            entity_id: light.fr_hue_color_tv_left
            above: 16
            below: 18
            attribute: brightness
        sequence:
          - choose:
              - conditions:
                  - condition: trigger
                    id: "1"
                sequence:
                  - service: scene.turn_on
                    target:
                      entity_id: scene.testing_hue_bulb_bright
                    metadata: {}
              - conditions:
                  - condition: trigger
                    id: "2"
                sequence:
                  - service: light.turn_off
                    data: {}
                    target:
                      entity_id: light.fr_hue_color_tv_left
              - conditions:
                  - condition: trigger
                    id: "3"
                sequence:
                  - service: scene.turn_on
                    target:
                      entity_id: scene.testing_hue_blue
                    metadata: {}
      - conditions:
          - condition: numeric_state
            entity_id: light.fr_hue_color_tv_left
            attribute: brightness
            above: 119
            below: 121
        sequence:
          - choose:
              - conditions:
                  - condition: trigger
                    id: "1"
                sequence:
                  - service: scene.turn_on
                    target:
                      entity_id: scene.testing_hue_bulb_bright
                    metadata: {}
              - conditions:
                  - condition: trigger
                    id: "2"
                sequence:
                  - service: scene.turn_on
                    target:
                      entity_id: scene.testing_hue_bulb_dim
                    metadata: {}
              - conditions:
                  - condition: trigger
                    id: "3"
                sequence:
                  - service: light.turn_off
                    data: {}
                    target:
                      entity_id: light.fr_hue_color_tv_left
mode: single