Need a sample for a "simple button" blueprint

I’m looking for a blueprint that can do the following:
Let’s say I have a smartswith that provides only

  single-click
  long-press

What the blueprint is supposed to do

single-click: 
	toggle light (turn off or turn on on at last recorded light intensity)
long-press: 
	turn on light (at last recorded light intensity) AND
	if initial brightness < 50% 
		start "brightness up" 
		stop at single-click or brightness = 100% 
	if initial brightness > 50%
		start "brightness-down"
		stop at single click or brightness = 1%
long-press (within 1 sec of previous long-press): 
	turn on light (at last recorded light intensity) AND
	if previous action "brightness-down":
		start "brightness-up"
		stop at single click or brightness = 100%
	if previous action brightness-up:
		start brightness-down
		stop at single click or brightness = 1%

Is anybody aware of such a blueprint and/or automation?

Kind regards
bartplessers

I’d like to share an automation I’ve created for the Xiaomi/Aqara Wireless Mini Switch (WXKG11LM). You can find more details about this “simple button” here: Aqara WXKG11LM control via MQTT | Zigbee2MQTT

Before setting up this automation, you’ll need to create two helper entities:

  1. input_text.minibutton_last_state
  2. input_text.minibutton_last_controlled_entity

This automation supports the following button actions:

  • Single press
  • Double press
  • Triple press
  • Quintuple press
  • Many press
  • Hold

For the single, double, triple, quintuple, and many press actions, I’ve set them up to toggle different lights in my home. Feel free to adjust these to control whatever devices suit your needs.

The hold action is used to dim or brighten the last controlled light. This is particularly useful when you want to adjust the brightness after turning on a light without having to use a separate control.

Feel free to modify this automation to fit your specific needs. I hope you find it useful!

alias: Minibutton with Dimming
description: "Control lights with a mini button"
mode: parallel

triggers:
  - platform: state
    entity_id:
      - sensor.0x54ef441000a859fe_action

actions:
  # Store the button state. Essential for the hold function.
  - choose:
      - conditions:
          - condition: template
            value_template: "{{ trigger.to_state.state != '' }}"
        sequence:
          - service: input_text.set_value
            target:
              entity_id: input_text.minibutton_last_state
            data:
              value: "{{ trigger.to_state.state }}"

  # Handle all button presses
  - choose:
      # Single press: Toggle office lights
      - conditions:
          - condition: template
            value_template: "{{ trigger.to_state.state == 'single' }}"
        sequence:
          - service: light.toggle
            target:
              entity_id: light.office_lights
          - service: input_text.set_value
            target:
              entity_id: input_text.minibutton_last_controlled_entity
            data:
              value: light.office_lights

      # Double press: Toggle living room hues
      - conditions:
          - condition: template
            value_template: "{{ trigger.to_state.state == 'double' }}"
        sequence:
          - service: light.toggle
            target:
              entity_id: light.all_hue_bulbs
          - service: input_text.set_value
            target:
              entity_id: input_text.minibutton_last_controlled_entity
            data:
              value: light.all_hue_bulbs
      # triple press: livingroom_all_spots
      - conditions:
          - condition: template
            value_template: "{{ trigger.to_state.state == 'triple' }}"
        sequence:
          - service: light.toggle
            target:
              entity_id: light.livingroom_all_spots_2
          - service: input_text.set_value
            target:
              entity_id: input_text.minibutton_last_controlled_entity
            data:
              value: light.livingroom_all_spots_2

      # Quintuple press: living_room_all_lights
      - conditions:
          - condition: template
            value_template: "{{ trigger.to_state.state == 'quintuple' }}"
        sequence:
          - service: script.toggle_living_room_lights
          - service: input_text.set_value
            target:
              entity_id: input_text.minibutton_last_controlled_entity
            data:
              value: light.living_room_all_lights
          

      # Many press: kitchen_main_hue
      - conditions:
          - condition: template
            value_template: "{{ trigger.to_state.state == 'many' }}"
        sequence:
          - service: light.toggle
            target:
              entity_id: light.kitchen_main_huex2
          - service: input_text.set_value
            target:
              entity_id: input_text.minibutton_last_controlled_entity
            data:
              value: light.kitchen_main_huex2

      # Long press (hold): Dimming
      - conditions:
          - condition: template
            value_template: "{{ trigger.to_state.state == 'hold' }}"
        sequence:
          - choose:
              # Dim down if light is on and brightness > 50%
              - conditions:
                  - condition: template
                    value_template: >-
                      {{ states(states('input_text.minibutton_last_controlled_entity')) == 'on' and
                         (state_attr(states('input_text.minibutton_last_controlled_entity'), 'brightness') | int > 127) }}
                sequence:
                  - repeat:
                      while:
                        - condition: template
                          value_template: "{{ states('input_text.minibutton_last_state') == 'hold' }}"
                      sequence:
                        - service: light.turn_on
                          target:
                            entity_id: "{{ states('input_text.minibutton_last_controlled_entity') }}"
                          data:
                            brightness_step_pct: -15
                            transition: 0.15
                        - delay: 0.2

              # Dim up if light is off or brightness <= 50%
              - conditions:
                  - condition: template
                    value_template: >-
                      {{ states(states('input_text.minibutton_last_controlled_entity')) == 'off' or
                         (state_attr(states('input_text.minibutton_last_controlled_entity'), 'brightness') | int <= 127) }}
                sequence:
                  - repeat:
                      while:
                        - condition: template
                          value_template: "{{ states('input_text.minibutton_last_state') == 'hold' }}"
                      sequence:
                        - service: light.turn_on
                          target:
                            entity_id: "{{ states('input_text.minibutton_last_controlled_entity') }}"
                          data:
                            brightness_step_pct: 15
                            transition: 0.15
                        - delay: 0.2
1 Like