Double Button Down/Up Light Dimmer

This is a blueprint to help dim lights using generic button down/up events.

Summary

Features

  • Lets the user add the triggers to down/up events from two buttons. Holding down one button dims up. Holding down the other dims down.
  • The trigger config is a little tedious, if anyone has an idea how I can add the trigger IDs into the blueprint, please let me know.
  • Lets the user select one or multiple lights to dim (they need the brightness attribute!)
  • Lets the user select a % step to dim by and a time out per step.

Behaviors

  • The starting set point brightness when multiple lights are selected is the average brightness of these lights.
  • The _stop triggers do nothing in the actions, they just cause the automation to stop and restart using mode: restart. That’s crucial to make it work.

My setup

I use it with a Shelly I4 but any device that supports a button down/up trigger should work here.

The target light being a hue light strip which works well.

The Blueprint

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

blueprint:
  name: Double Button Up Down Dimmer (v1.1.0)
  description: Use two buttons with up and down events to dim a light entity
  domain: automation
  input:
    dim_triggers:
      name: "Select the **four** button up and down triggers (usually Device -> x Button up / down)"
      description: |
        **IMPORTANT**: you MUST add the following IDs (via `... -> Edit ID`) as follows per trigger: 
        - `Dim Up Button Down   -> dim_up_start`
        - `Dim Up Button Up     -> dim_up_stop`
        - `Dim Down Button Down -> dim_down_start`
        - `Dim Down Button Up   -> dim_down_stop`

        Tip: Select the device and then duplicate the trigger and adjust. Save time in searching.
      selector:
        trigger:
    target_light_entities:
      name: Lights to dim.
      description: Lights needs to have the brightness attribute to work.
      selector:
        entity:
          filter:
            domain: light
          multiple: true
    step_pct:
      name: Percent step to change target light entities brightness per step.
      selector:
        number:
          min: 1
          max: 100
          mode: box
          unit_of_measurement: "%"
      default: 5
    step_timeout_ms:
      name: Space out of steps in milliseconds
      description: The brightness will be turned up/down in this time intervals by the step size.
      selector:
        number:
          min: 10
          max: 1000
          mode: box
          unit_of_measurement: "ms"
      default: 200
triggers: !input dim_triggers
conditions: []
actions:
  - variables:
      step_pct: !input step_pct
      timeout_ms: !input step_timeout_ms
      target_light_entities: !input target_light_entities
  - variables:
      step_255: >-
        {{ (255 / 100 * step_pct) | int }}
      direction: >-
        {% if trigger.id == 'dim_up_start' %} {{ 1 }} {% else %} {{ -1 }} {%
        endif %}
      current_brightness: >-
        {% set brightness_list =  target_light_entities | map('state_attr','brightness') | select | list %}
        {{ 0 if brightness_list | count == 0 else (brightness_list | sum / brightness_list | count) | int }}
  - if:
      - condition: trigger
        id:
          - dim_up_start
          - dim_down_start
    then:
      - repeat:
          sequence:
            - variables:
                current_brightness: >-
                  {{ max(0, min(current_brightness + direction * step_255, 255))
                  }}
            - repeat:
                sequence:
                  - action: light.turn_on
                    metadata: {}
                    data:
                      brightness: "{{ current_brightness }}"
                    target:
                      entity_id:
                        - "{{ repeat.item }}"
                for_each: "{{ target_light_entities }}"
            - delay:
                hours: 0
                minutes: 0
                seconds: 0
                milliseconds: "{{ timeout_ms }}"
          while:
            - condition: template
              value_template: >-
                {{ 0 < current_brightness if direction | int  < 0 else current_brightness < 255 }}
mode: restart


Changelog

v1 - initial version

v1.1

  • Added sensible defaults for step_pct = 5 and step_timeout_ms = 200.
  • Fixed two bugs that would prohibit the automation from running when the brightness is 0% or 100%.
  • Moved to internally use the 0-255 brightness scale instead of percent for more robustness.