Hold to Dim

I have a sonoff nspanel with tasmota and I want to dim smart bulbs by holding (long press) the physical buttons. The buttons have been decoupled from the relays so they just send commands; but when using the following automation l, the lights end up in a continuous loop. Any ideas on how to fix the automation please?

alias: Living Room Brightness
description: ""
trigger:
  - platform: device
    domain: tasmota
    device_id: b2d655b71745cd9b93a92f4450abfba5
    type: button_long_press
    subtype: button_1
    discovery_id: 4417937B6CA4_button_1_HOLD
    id: LivingRoom-increase
  - platform: device
    domain: tasmota
    device_id: b2d655b71745cd9b93a92f4450abfba5
    type: button_long_press
    subtype: button_2
    discovery_id: 4417937B6CA4_button_2_HOLD
    id: LivingRoom-Decrease
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - LivingRoom-increase
        sequence:
          - repeat:
              sequence:
                - device_id: 97531ff873c0809634bacc693c604c8d
                  domain: light
                  entity_id: 91c71d49298c0e0e7bff430b777e43f3
                  type: brightness_increase
                - delay:
                    hours: 0
                    minutes: 0
                    seconds: 0
                    milliseconds: 500
              while:
                - condition: trigger
                  id:
                    - LivingRoom-increase
mode: restart

The trigger.id will always be the same. So your automation will always enter an endless loop because of your while statement. If your device has a ‘released the button’ trigger, then you’d want to use that for your while loop. Otherwise it will always be a guessing game.

Thank you. So without a button release command that my device doesn’t seem to support, i Cannot achieve what i want to?

You need two commands to make it work.

You appear to only have one command to signal the start of the dimming process. Without a second one to stop it, it will behave the way you have already observed (loops forever).

1 Like

no, because the system won’t know when to stop. I’d be willing to bet there is a way to detect it but only you will be able to find out how because you have the device. Events aren’t easy to work with. Does your device have an event entity?

I have no experience with nspanel running Tasmota but I found this documentation:

It contains a screenshot showing button events (linked below). What I don’t see in the screenshot is a button event indicating when a button is released.

I don’t know if it’s displaying all available button events but, for your application, you need an event to indicate when the button is no longer being pressed. Without that, I don’t see how it’s possible to achieve your goal practically.

I say “practically” because you could use a double-press to signal the end of a long-press but that would be an unusual way to control fading; the usual way is to simply release a button to stop fading, not double-click it.

Your application really needs a button-release event.

1 Like

I found another screenshot that lists button events and it also lacks a release event.

You can confirm it for yourself by creating an automation with a Device Trigger for your nspanel device. It will display a list of available button events. If it looks like either of the two screenshots I posted, then there’s no release event.

1 Like

Thank you for investigating, i really appreciate you taking the time.

Unfortunately, there doesn’t seem to be a button release option available in my automations :frowning:

I searched for examples of what you are trying to do (with the nspanel’s buttons) and couldn’t find any. At best, other people use them to initiate something (turn on a light, etc) because you only need one button event to do that.

Without knowing when a button is released, the alternative is to use some other button event. However, as explained above, it creates an unusual (unintuitive) way of controlling fading behavior (i.e. press once to start fading, press twice to stop it or long-press to start and short-press to stop … either way is non-standard).