# Momentary switch or button (normally open)

**URL:** <https://discourse.nodered.org/t/momentary-switch-or-button-normally-open/36768>\
**Category:** FAQs\
**Created:** [30 November 2020 18:47 UTC](https://discourse.nodered.org/t/momentary-switch-or-button-normally-open/36768 "2020-11-30T18:47:37Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![bobs409](https://avatars.discourse-cdn.com/v4/letter/b/ee59a6/32.png) [@bobs409](https://discourse.nodered.org/u/bobs409)\
**Post date:** [30 November 2020 18:47 UTC](https://discourse.nodered.org/t/momentary-switch-or-button-normally-open/36768/1 "2020-11-30T18:47:37Z")

</div>

Hi, first time poster and newbie. 🤪

I've been searching all over for a way to put a **momentary** button on my node red dashboard. Something that goes high while pressed and back to low when left go. I didn't find anything like that in the library here.

Anyone know of such a thing?

Thanks in advance,

Bob

---

<div class="post-metadata">

**Author:** ![hotNipi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hotnipi/32/383_2.png) [@hotNipi](https://discourse.nodered.org/u/hotNipi)\
**Post date:** [30 November 2020 19:46 UTC](https://discourse.nodered.org/t/momentary-switch-or-button-normally-open/36768/2 "2020-11-30T19:46:40Z")

</div>

There is no such node to install that would give you the momentary button functionality. But it can be done by using the `ui_template` node.  
Have you searched here in forum? There is many threads talking about the momentary button. Many examples given and discussed.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [30 November 2020 20:39 UTC](https://discourse.nodered.org/t/momentary-switch-or-button-normally-open/36768/3 "2020-11-30T20:39:41Z")

</div>

Do you need the 'let go'message to happen when the button is released or would it be ok for it to happen a defined time after the pressed message? If the latter then you can use a ui\_button followed by a Trigger node to send the On then Off messages.

---

<div class="post-metadata">

**Author:** ![bobs409](https://avatars.discourse-cdn.com/v4/letter/b/ee59a6/32.png) [@bobs409](https://discourse.nodered.org/u/bobs409)\
**Post date:** [30 November 2020 21:54 UTC](https://discourse.nodered.org/t/momentary-switch-or-button-normally-open/36768/4 "2020-11-30T21:54:32Z")

</div>

I need something to turn on only when the button is pressed/held down and turn off when the button is left go of.

Was hoping for an easy solution as I don't have a lot of experience yet on writing code. I have been going thru the forum, maybe I'll find something here yet that I can work with.

Thanks,

Bob

---

<div class="post-metadata">

**Author:** ![hotNipi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hotnipi/32/383_2.png) [@hotNipi](https://discourse.nodered.org/u/hotNipi)\
**Post date:** [30 November 2020 22:00 UTC](https://discourse.nodered.org/t/momentary-switch-or-button-normally-open/36768/5 "2020-11-30T22:00:16Z")

</div>

OK. Play with this.

```auto
[{"id":"eac5d9eb.958798","type":"ui_template","z":"6d08d5ab.a8aa3c","group":"61e6d4c4.e7619c","name":"momentary button","order":7,"width":"1","height":"1","format":"<div id=\"momentary\">\n <md-button style=\"min-width:36px;\n width: 100%; \n height: 100%; \n margin:0; \n padding: 0px; \n border-radius: 50%; \n background-color:green\">\n \n <i class=\"fa fa-hand-pointer-o\"></i>\n </md-button>\n</div>\n<script>\n(function($scope) {\n \n$('#momentary').on('touchstart mousedown', function(e) {\n e.preventDefault(); //prevent default behavior\n $scope.send({\"topic\":\"momentary\",\"payload\": true});\n});\n\n$('#momentary').on('touchend mouseup', function(e) {\n e.preventDefault(); //prevent default behavior\n $scope.send({\"topic\":\"momentary\",\"payload\": false});\n});\n \n})(scope);\n</script>","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":true,"templateScope":"local","x":360,"y":140,"wires":[["534f375d.fce978"]]},{"id":"534f375d.fce978","type":"debug","z":"6d08d5ab.a8aa3c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":530,"y":140,"wires":[]},{"id":"61e6d4c4.e7619c","type":"ui_group","name":"TEST","tab":"d680797a.2f8b88","order":1,"disp":true,"width":"5","collapse":false},{"id":"d680797a.2f8b88","type":"ui_tab","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

```

---

<div class="post-metadata">

**Author:** ![bobs409](https://avatars.discourse-cdn.com/v4/letter/b/ee59a6/32.png) [@bobs409](https://discourse.nodered.org/u/bobs409)\
**Post date:** [30 November 2020 22:06 UTC](https://discourse.nodered.org/t/momentary-switch-or-button-normally-open/36768/6 "2020-11-30T22:06:19Z")

</div>

Thank you!! That's something I can work with. 👍 Seems to operate just like I need.

Bob

---

<div class="post-metadata">

**Author:** ![hotNipi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hotnipi/32/383_2.png) [@hotNipi](https://discourse.nodered.org/u/hotNipi)\
**Post date:** [30 November 2020 22:07 UTC](https://discourse.nodered.org/t/momentary-switch-or-button-normally-open/36768/7 "2020-11-30T22:07:52Z")

</div>

Of course it does 🙂 But you just missed the learning part.

---

<div class="post-metadata">

**Author:** ![bobs409](https://avatars.discourse-cdn.com/v4/letter/b/ee59a6/32.png) [@bobs409](https://discourse.nodered.org/u/bobs409)\
**Post date:** [30 November 2020 22:27 UTC](https://discourse.nodered.org/t/momentary-switch-or-button-normally-open/36768/8 "2020-11-30T22:27:23Z")

</div>

Well I still have to make it work for my needs so some learning yet. 😉 It has to control gpio pins on an esp8266 that is mqtt'd to a raspberry pi broker. I'm getting there little by little...

Bob

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [14 December 2020 22:27 UTC](https://discourse.nodered.org/t/momentary-switch-or-button-normally-open/36768/9 "2020-12-14T22:27:23Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
