Dimming light with a single step doesn't work

Hi folks, I’ve been struggling for hours without any progress, any help in the right direction would be greatly appreciated. The issue:

I’d like to have a horizontal stack card on my dashboard with 3 items: a ‘+’ button, a ‘-’ button and an indicator showing a value from 0 to 255. Each horizontal stack card is related to a single dimmable light. I’m trying to achieve a single dim-step up or down on a button press.
I’m using a horizontal stack card with a mushroom-template-card for each item in the stack card. The order of the items is shown in the screenshot.

The display is working perfectly. The buttons don’t work as expected.

The issues I’m having:

  • the first section of the code below simply gets the current brightness and subtracts 1 from that value. It then makes sure the value is never lower than zero and returns the new value. That doesn’t work though. I get and error “Failed to perform the action light/turn_on. Expected int for dictionary value @ data[‘brightness’]”
  • when trying a simpler approach, as shown in the third section, the light only responds when using a value higher than 1. And even then, the step is not exactly as it should be. For example: when using ‘brightness_step: 2’, the light increases 2 or 3 steps and usually stops responding after a few times of pressing the + button.

Your help would be greatly appreciated!
The code:

type: horizontal-stack
cards:
  - type: custom:mushroom-template-card
    icon: mdi:minus
    layout: vertical
    tap_action:
      action: perform-action
      target:
        entity_id: light.keuken_tafel
      perform_action: light.turn_on
      data:
        brightness: >
          {% set current_value = state_attr('light.keuken_tafel', 'brightness') %}
          {% set new_value = current_value - 1 %}
          {% if new_value >= 0 %}
            {% set new_value = 0 %}
          {% endif %}
          {{ new_value|int }}
    hold_action:
      action: none
    double_tap_action:
      action: none
    icon_color: ""
    multiline_secondary: false
    fill_container: false
  - type: custom:mushroom-template-card
    secondary: "{{ state_attr(\"light.keuken_tafel\", \"brightness\")}}"
    entity: light.keuken_tafel
    badge_icon: ""
    layout: vertical
    hold_action:
      action: none
    double_tap_action:
      action: none
    tap_action:
      action: none
    icon_color: ""
    icon: ""
    primary: Keukentafel
  - type: custom:mushroom-template-card
    icon: mdi:plus
    layout: vertical
    tap_action:
      action: perform-action
      target:
        entity_id: light.keuken_tafel
      perform_action: light.turn_on
      data:
        brightness_step: 1
    hold_action:
      action: none
    double_tap_action:
      action: none
    icon_color: ""
    multiline_secondary: false
    fill_container: false

you should use brightness_step_pct or brightness_step instead of brightness.

take a look at it here:

I believe the root issue here is that the card you’re using doesn’t accept jinja templates. but in this case, you’re only trying to adjust it by a constant amount. so if you use brightness_step_pct: 10 it will adjust the brightness by 10% and do all the checking for you.

Thank you for you instant reply!

As shown in the 3rd part of the code (for the plus button), I’ve tried increase (or decrease) the brightness with a single step as you’ve suggested. It doens’t work as expected: increasing with a single step does not do anything. Increasing with 2 steps does increases with 2 or 3 steps. Increasing, for example, 10 steps yields a more trustworthy result but still not as expected.
What to do?

edit: just to let you know, using a single (or more) steps in percentages does work as it should. I’m aiming for smaller steps though. Hence my search for a single step solution.

This is my code now:

type: horizontal-stack
cards:
  - type: custom:mushroom-template-card
    icon: mdi:minus
    layout: vertical
    tap_action:
      action: perform-action
      target:
        entity_id: light.keuken_tafel
      perform_action: light.turn_on
      data:
        brightness_step: -2
    hold_action:
      action: none
    double_tap_action:
      action: none
    icon_color: ""
    multiline_secondary: false
    fill_container: false
  - type: custom:mushroom-template-card
    secondary: '{{ state_attr("light.keuken_tafel", "brightness") }}'
    entity: light.keuken_tafel
    badge_icon: ""
    layout: vertical
    hold_action:
      action: none
    double_tap_action:
      action: none
    tap_action:
      action: none
    icon_color: ""
    icon: ""
    primary: Keukentafel
  - type: custom:mushroom-template-card
    icon: mdi:plus
    layout: vertical
    tap_action:
      action: perform-action
      target:
        entity_id: light.keuken_tafel
      perform_action: light.turn_on
      data:
        brightness_step: 10
    hold_action:
      action: none
    double_tap_action:
      action: none
    icon_color: ""
    multiline_secondary: false
    fill_container: false

hi …

if you do it by brightness_step, I think that’s about as fine grained control as you can get. There are 256 total steps. Your hardware may or may not actually support that many steps so if it actually has 100, it may round your steps and therefore each 1 step call may not always change the brightness… Does that make sense? Not sure if I explained that super well

btw, when hitting replies in the forum, use the reply beside the post… Not the blue button on the bottom. If you reply to my post, I’ll get a notification… I only just happened to run across your reply by luck which is why it’s two days later …

given what you described I might try using brightness_step_pct and play around with the value that works best for you there