Navigating confusing documentation about momentary switches

I have a silly series of questions about creating momentary switches that I haven’t found answered elsewhere … my goal is to follow a very helpful (but not perfectly complete) set of instructions shared with me by another forum user that involve creating momentary switches.

My first question is: is using this custom component (hass-momentary by twrecked) still the ideal way to create a momentary switch? The person whose instructions I’m trying to follow shared code examples with “platform: momentary”; am I right to assume that they meant to install that component? Or is that now a delivered platform in HA? (I don’t see documentation to suggest that it is, but I wanted to check.)

Second question: assuming that that component is the way to go, how does one install and use it? I installed it using HACS, and I now have a momentary folder in my custom_components folder, but I don’t have any momentary.yaml as referenced by the component’s readme.

Elsewhere, I’ve seen reference to putting “momentary:” (by itself?) in my configuration.yaml … should I do that?

Once I figure out the above and get the component properly installed, how do I create custom momentary switches with it? Do I put the code in configuration.yaml? Or elsewhere?

Thanks in advance for any help you can offer for my dumb questions!

There is no need for an external integration to create momentary “switches” (buttons) as it is already built into HA:

Buttons == momentary switches. They perform one action and are stateless.

1 Like

What specific features do you need? As Bill mentioned above, HA has its own momentary switch-like entities. Those that are supplied by another integration are button entities, and those that are user-defined are input_button entities which can be set up either in the YAML configuration or through the Helper tab of Settings > Devices & services.

The custom integration you linked has additional features like duration and cancel-ability which do not exist in the core integrations.

2 Likes

Thank you both very much for explaining and offering help.

So, the suggestion I was trying to follow was someone’s workaround for “integrating” a smart lock without HA integration into HA. Part of the workaround was a momentary switch set up as a delay to account for how it takes time for the lock to lock itself, report that to HomeKit, have the HA HK integration report that to HA, etc. The delay insured that while all that was happening, a “please wait” notification could be displayed, and people wouldn’t hammer the toggle, thereby relocating the lock while waiting for it to unlock, etc.

If buttons are the “right” way to do this, I suppose I’ll get to work adapting the code I was given to use buttons instead of momentary switches via the custom component; it’ll make it harder, but I’ll probably learn more (I say reluctantly but optimistically).

If I can impose upon your kindness a little more, can I ask, how do people usually use button (and input_button) as momentary switches? Trigger the button and then look at the last time it was “pressed” to see if your desired delay has elapsed yet, basically?

Thanks again!

1 Like

Can you post what you were given (or a link to it, if it’s already shared somewhere) so we can see how the pieces work together?

2 Likes

Heh, of course, thanks; I was trying to save you from having to do my homework, but it’s probably easier if I just show you. No pressure (of course) to do anything with this.

What I was attempting to replicate was the workaround detailed in this comment … as you can see, that user’s first suggested steps were to create momentary switches for the reasons he describes and I paraphrased in my earlier post. Any thoughts?

1 Like

someone will likely smack me for this but I use a script for something similar.

You can associate a script to a dashboard UI button. It behaves like a momentary button, but actually has self resetting state (on while it is running, off when it’s not)

In single mode(the default) it will reject repeated presses. It will show as busy/on while it’s on.

Just put a delay in it for however long you want it to be unavailable.

k… ducking now from the abuse of a script :duck:

2 Likes

Hahaha actually, imho, that’s pretty damn clever! Approved! :blush:

Interesting! I’ll look into this route if that seems to be the best way to do it (though I’ll admit it seems rather more ‘advanced’ than buttons or even that custom component). Thanks so much for replying.

1 Like

it’s not more advance… I think it’s actually simpler to implement… but I can’t claim cleverness… more ignorance about both the button and the hacs custom one.

There’s no rule you can’t do both. :blush:

Personally, I learned doing things in HA natively simply because I wanted to know everything it could do. But, if it’s faster to use a custom component or integration, that works too.