Momentary Switch on Lovelace

How can I create a momentary switch on lovelace for my garage door switch? it supposed to send 1 when pressed and send 0 when released. as of moment I do have an automation to do it but it only works with 1 second delay and I’m really hoping to find a way to drop the delay down to 200ms.
Could anyone help me with this?

thanks for the quick response.
how can I make the momentary stay on for milliseconds? it only says seconds in the readme
or I shouldn’t include that part to make it instant?
and how can I link it to existing switch?

You can’t specify less than one second for this custom integration. If you require that you will have to use a delay in an automation or script. However while delay: supports milliseconds, sub one second delays are highly processor load dependant.

You use the event generated by the momentary button to trigger automations. In the automation you can use services to control other switches.

Are you actually experiencing problems when using a 1 second delay? Or is there some other reason you want to reduce the time?

My garage door automation works perfectly fine with a 1 second off delay.

When I try to slightly open the door then the door opens too wide and that’s my only issue but it works perfectly for completely open or close the door

If you’re using Tasmota on the device controlling your garage door, you can set Pulsetime (in milliseconds)
With this, the switch in HA UI behaves like a Momentary Switch.

Read more on this topic here.

2 Likes

How do one uses hass-momentary?
I can see the definition, but how do I attach action to it? Like I want to invoke for example command_line command_on when the button is pressed?

1 Like

I ended up creating an automation that turns off the switch after 150 milliseconds when the state changes to on. So you can do the same and have HA run your script in that automation.

What exactly you’re trying to achieve?

I am trying to add a momentary switch on lovelace to open/close a garage door.

I’ve added https://github.com/twrecked/hass-momentary to HA.

I’m not sure how to go about adding the switch to lovelace?

Perfect! thx!!!

The idea of this momentary add-on is to do the same in a built in integration like fanction. The only issue here is that it has no connection to a physical switch like KNX, Sonoff or so. The question what is this add-on really switching?
I have a Modbus switch which needs to be used as a momentary physical switch. This add-on has no connection to such switch.

Anyone can explain my question.

This integration works with switches in home assistant. It will turn them off after turning them on. It does not link directly to any hardware. Only home assistant entities.

I’m not sure that’s true.

From the docs it looks like that integration will only create a toggle switch entity in HA that doesn’t link to or interact with any other entities.

Once created then you will have to actually make it do something real - like in an automation you could link the momnentary entity to another switch entity and cause the other entity to do something when the momentary entity is toggled.

Very similar to an input_boolean except that it turns itself off/on automatically when actuated.

Unless I misunderstood something.

See if this works for you. The value_template turns off the soft switch in HA but never triggers the turn_off action. Whatever after turn_off is dummy to complete the syntax.

The “momentary” implementation is fully enclosed within turn_on accomplished by a delay of however many ms you want.

switch:
 - platform: template
   switches:
     test_momentary:
       value_template: >
         {% if is_state('switch.test_momentary','on') %}
           false
         {% endif %}
       turn_on:
        - service: switch.turn_on
          target:
            entity_id: switch.test_lamp
        - delay:
            milliseconds: 100
        - service: switch.turn_off
          target:
            entity_id: switch.test_lamp
       turn_off:
        - service: switch.turn_off
          target:
            entity_id: switch.test_lamp
1 Like