Lovelace switch that sends a "1" as long as you hold and goes back to "0" when released?

Hi
I’m looking for a way to have a switch which, as long as it is pushed (guess with the hold action) sends a “1” and as soon it’s released switches back to “0”.
Is this possible?

Thanks a lot in advance!
Nick

2 Likes

There is no core functionality to do this. There is a hold action for buttons and the like, but no release action. https://www.home-assistant.io/lovelace/actions/#hold-action

Are you looking for a physical switch or something in the frontend?

Thanks for your fast responses guys!

I thought so that there this is not something standard, therefor my question.
Somehow it should be a combination of hold and toggle.

@apop, a frontend switch.
The hardware is already in place: it’s a TV lift which has to be controlled this way.
The lift doesn’t have end switches and cannot have a permanent signal.

1 Like

In that case, @tom_l is right. Currently, there’s no way to do this in the frontend. However, keep an eye on this pull request, as it looks like the functionality is being worked on for the custom button card:

You could create a switch, which triggers an automation that starts a loops sending 1 until you turn the switch off.

Something like this: (untested)

automation:
  - trigger:
      - platform: state
        entity_id: switch.xy # <- your switch
        to: 'on'
    mode: single
    action:
      - alias: Send 1 UNTIL the switch is off
        repeat:
          sequence:
            # Put you action that sends "1" below
            - service: light.turn_oon
              entity_id: light.whatevber
            # Put your delay before sending the next "1"
            - delay:
                milliseconds: 200
          until:
            # stop loop when switch is turned off
            - condition: state
              entity_id: switch.xy
              state: 'off'

Maybe I am missing something but isn’t this describing a simple momentary pushbutton?

I am assuming that you are after a physical switch that will interface with HA? This can be built using ESPHome on an ESP8266 (even an ESP-01) with the addition of a single momentary push button…

It will be “ON” when pressed and “OFF” when released.

Edit: just saw you want in frontend, not physical. Oops :slight_smile:

Back again. I though I had looked at this before, the answer may be the Button card.

Except it doesn’t support a release action.

Yes that is what I said.

Yeah sorry Tom, shouldn’t try and WFH and do HA stuff at the same time - I am not good at multi-tasking… :thinking:

Hi Burningstone, I’m a little puzzled… :blush:
I have configured a switch in switch.yaml which already controls the TV lift.

So for the switch in the HA frontend I use the button card:

  • I use the hold action
  • with ‘call-service’ I trigger the automation

Where do my already functioning switch and the button card go in your example?

The other option is to automate turning it off. So you turn the switch on manually (tap action on the button) then this automation turns it off:

trigger:
  platform: state
  entity_id: switch.tv_lift
  to: 'on' 
  for: 
    seconds: 4 # or however many seconds it takes to lift
action:
  service: switch.turn_off
  entity_id: switch.tv_lift
1 Like

Now I’m confused. If you already have a switch that controls the TV lift, why not use tap_action to turn on the switch and hold_action to turn it off?

You’re all making this far too complicated.

Tap the button once to turn the switch on and thus start lifting, let the timed automation to stop it when lifted.

So does the same action that lifts the TV also lower the TV? Personally, it sounds like a garage door. In HA that would be a ‘cover’. I’d go with @tom_l’s route and a template cover. But you’ll need a sensor to determine if the TV is open or not. Then you have a nice little UI element that has an ‘open’ and ‘close’ and it will have the state ‘open’ and ‘closed’. Just my 2c.

1 Like

Thanks guys for thinking with me!

No @petro, 2 different actions.

The reason to have a push-button like effect is for security reasons: in case of a problem, something on top, … letting go the button would stop the lift from moving immediately.

Did you try my suggestion?

@Burningstone: yes, cannot get it to work. :blush:

Can you show your code please?