Add minimum brightness threshold when creating automation from a blueprint

I am using the following code from a blueprint to turn and dim a light.

Right now, I am using a very clumsy if condition to turn the light back on to 10% if you dim too far that the light turns off. I am trying to introduce a variable that can be checked instead so that the light does not turn off and then back on but am learning yaml as I go an unsure how to add it to the automation.

How do i extend the code in the Down_HoldPress section to stop the lamp turning off and always be on at 10%?

alias: Hue Remote Hall
description: ""
use_blueprint:
  path: dustins/zha-philips-hue-v2-smart-dimmer-switch-and-remote-rwl022.yaml
  input:
    zha_device: d1ce1ba91433814d7118ce0c247aef9d
    Power_Press:
      - service: light.toggle
        data: {}
        target:
          entity_id: light.hall_small_lamp
    Up_HoldPress:
      - service: light.turn_on
        data:
          brightness_step_pct: 10
        target:
          entity_id: light.hall_small_lamp
    Down_HoldPress:
      - if:
          - condition: device
            type: is_off
            device_id: c5627b7674446a1bcf33ba826931699f
            entity_id: light.hall_small_lamp
            domain: light
        then:
          - type: turn_on
            device_id: c5627b7674446a1bcf33ba826931699f
            entity_id: light.hall_small_lamp
            domain: light
            brightness_pct: 10
        else:
          - service: light.turn_on
            data:
              brightness_step_pct: -10
            target:
              entity_id: light.hall_small_lamp

Try something like this:

        else:
          - service: light.turn_on
            data:
              brightness_pct: >-
                {% set curr_brightness = state_attr('light.hall_small_lamp', 'brightness_pct') | float(0) %}
                {{ max(10, curr_brightness - 10) }}
            target:
              entity_id: light.hall_small_lamp

Or even simpler:

        else:
          - service: light.turn_on
            data:
              brightness_pct: "{{ max(10, state_attr('light.hall_small_lamp', 'brightness_pct') | float(0))}}"
            target:
              entity_id: light.hall_small_lamp

I’ve typed this on my tablet and couldn’t test it, so my apologies if I missed some space or something else.

Thanks for a fast answer!

This sort of works as it stops the lamp turning off but it doesn’t allow me to set the dimness of the lamp as it just sets the minimum threshold when I press the dim down button. I’d like to be able to dim the lamp still if it’s at maximum brightness and just avoid the lamp turning off by overshooting.

To the minimum you mean, right?

So, why don’t you save your time by testing the light manually in order to find its minimum brightness and then hard-code it?

You probably can still do it programmatically, but that will provide some bad experience to the user as the light will go off before the system can detecte it happening and be able to turn on back, reduce the step and try again with a smaller step, in a kind of a loop until it finds the minimum every time (or at least the first time and then stores the minimum in a helper, which will be even more work for you).

I am very new to all this so bear with me.

I see what my problem is now and why setting “brightness value” wasn’t working for me before. I have to set a min value of at least 25 as this is 10% of 255. It’s a bit confusing because the device brightness slider is between 0 and 100, so presumably this is it’s percentage value and not it’s step value.

Thanks again for helping me!

Yeah, brightness and brightness_pct have similar results, but in different scales:

A bit confusing…