# Buttons, pressing and when to send messages

**URL:** https://discourse.nodered.org/t/buttons-pressing-and-when-to-send-messages/58629
**Category:** General
**Created:** [18 February 2022 23:38 UTC](https://discourse.nodered.org/t/buttons-pressing-and-when-to-send-messages/58629 "2022-02-18T23:38:57Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [18 February 2022 23:38 UTC](https://discourse.nodered.org/t/buttons-pressing-and-when-to-send-messages/58629/1 "2022-02-18T23:38:57Z")

</div>

(I know: I'm making my own life difficult... but...)

I have a couple of projects - one of which I have already put up here - which are subflows to give you a _safety feature_ that you have to double click a button before it toggles.

So _Today's question_ is about how that should work.  
Reason: I am wanting to make a similar subflow that doesn't have the **TOGGLE** feature.  
But to get the button pressed, you still have to double press the button.

1 - I'm torn between making **another** subflow as opposed to adding to the existing one and adding the option so there is no _toggle_ feature.  
2 - Is this worth the effort? Though if you have _protection_ on toggle buttons, you will need/want it on single press buttons. So there isn't much love lost on having a slightly bigger subflow than having TWO that do slightly different things.

With things as they are - on the existing subflow:  
As you press the button, the output changes IN TIME with the buttons being pressed.  
~~Then it _re-asserts_ the final selection when you stop pressing the button.~~  
Ok, it doesn't do that. Sorry.

Is this good/bad? -- semi rhetorical, as I can see reasons for doing this and problems if I don't. Although that is only one side of it, I feel it is probably better doing it this way.

So, the _extra work_ needed to modify the existing code to make it _Double click to activate_ has it's own set of questions:

Base line:  
You **must** double click to get the output to change.

So what happens to the output if you quickly press the button THREE times?  
(discuss)

Should the output then STAY at that signal or should it send a _pulse_ message starting with .... `0`. Send a `1` if/when the button is DOUBLE clicked then go back to the `0`?  
(discuss)

Or - only to make it more complicated:  
Have both?  
(again: discuss)

I am going batty thinking about what is _the right way_

Thanks in advance.

---

<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: [19 February 2022 15:42 UTC](https://discourse.nodered.org/t/buttons-pressing-and-when-to-send-messages/58629/2 "2022-02-19T15:42:28Z")

</div>

Why don't you just add an Are you sure? Notification node for critical buttons?

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [19 February 2022 20:10 UTC](https://discourse.nodered.org/t/buttons-pressing-and-when-to-send-messages/58629/3 "2022-02-19T20:10:03Z")

</div>

I could. I just got _hung up_ from my real world experience with buttons and pop up's don't exist. So a _Double click_ option was the idea.

---

<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: [20 February 2022 07:22 UTC](https://discourse.nodered.org/t/buttons-pressing-and-when-to-send-messages/58629/4 "2022-02-20T07:22:39Z")

</div>

> [@Trying\_to\_learn](#):
>
> experience with buttons and pop up's don't exist.

I have no idea what you mean by pop-ups not existing.

> [@Trying\_to\_learn](#):
>
> _Double click_ option was the idea

Well if you try and do something the complicated way then you must expect problems.

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [20 February 2022 19:38 UTC](https://discourse.nodered.org/t/buttons-pressing-and-when-to-send-messages/58629/5 "2022-02-20T19:38:53Z")

</div>

In the real world Colin... Not on computer screens.

I do expect problems. I therefore ask for people's thoughts on how to do things - but within the limits I am prepared to do.

I don't think that is unreasonable.

---

<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: [20 February 2022 20:19 UTC](https://discourse.nodered.org/t/buttons-pressing-and-when-to-send-messages/58629/6 "2022-02-20T20:19:17Z")

</div>

Such safeguards in real life actually require additional action  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/9/893a10e8c7f0ac8ac13bb21cfb24c9924b2906e0.png)

Or precise handling and/or attention  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/e/8e0ad07b08db8cc6ed3525eaf42d4b4ad5558b0f.jpeg)

In other words - physically forced "I know what I'm doing" attitude.

If you targeting safety - you can't build it on top of something you can't really trust. If you can even say "but what if...", it is not safe anymore.

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [20 February 2022 20:22 UTC](https://discourse.nodered.org/t/buttons-pressing-and-when-to-send-messages/58629/7 "2022-02-20T20:22:21Z")

</div>

I agree in a lot of ways.

It is just I am _exploring_ that world.

Touch screens are problematic with on screen push buttons.  
So I am just seeing what is/would be a good way to make it a little less possible to get accidental presses.

---

<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: [20 February 2022 20:25 UTC](https://discourse.nodered.org/t/buttons-pressing-and-when-to-send-messages/58629/8 "2022-02-20T20:25:16Z")

</div>

By using two physical actions like switch to enable action and button to fire the action.

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [20 February 2022 20:27 UTC](https://discourse.nodered.org/t/buttons-pressing-and-when-to-send-messages/58629/9 "2022-02-20T20:27:37Z")

</div>

Ok....

But.. (Sorry - brain failure this end) I'm still not equating it easily.

The best I can get from it is to have TWO _buttons_ beside one another. One to enable the other.

---

<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: [20 February 2022 20:37 UTC](https://discourse.nodered.org/t/buttons-pressing-and-when-to-send-messages/58629/10 "2022-02-20T20:37:44Z")

</div>

Simple example with switch and button

```auto
[
    {
        "id": "4acb89a30b69f58e",
        "type": "ui_switch",
        "z": "2e6686c4918f199d",
        "name": "",
        "label": "safety lock",
        "tooltip": "",
        "group": "c7a27394.057878",
        "order": 14,
        "width": 4,
        "height": 1,
        "passthru": true,
        "decouple": "false",
        "topic": "topic",
        "topicType": "msg",
        "style": "",
        "onvalue": "true",
        "onvalueType": "bool",
        "onicon": "",
        "oncolor": "",
        "offvalue": "false",
        "offvalueType": "bool",
        "officon": "",
        "offcolor": "",
        "animate": false,
        "className": "",
        "x": 230,
        "y": 2850,
        "wires": [
            [
                "d0fb6010062ab6ed"
            ]
        ]
    },
    {
        "id": "eea3e707e440f91b",
        "type": "ui_button",
        "z": "2e6686c4918f199d",
        "name": "",
        "group": "c7a27394.057878",
        "order": 15,
        "width": 5,
        "height": 1,
        "passthru": false,
        "label": "Action",
        "tooltip": "",
        "color": "",
        "bgcolor": "",
        "className": "",
        "icon": "",
        "payload": "",
        "payloadType": "str",
        "topic": "topic",
        "topicType": "msg",
        "x": 570,
        "y": 2850,
        "wires": [
            [
                "7f2a4ffc73dbf79b",
                "086a722972596909"
            ]
        ]
    },
    {
        "id": "d0fb6010062ab6ed",
        "type": "change",
        "z": "2e6686c4918f199d",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "enabled",
                "pt": "msg",
                "to": "payload",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 410,
        "y": 2850,
        "wires": [
            [
                "eea3e707e440f91b"
            ]
        ]
    },
    {
        "id": "7f2a4ffc73dbf79b",
        "type": "change",
        "z": "2e6686c4918f199d",
        "name": "disable ",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "false",
                "tot": "bool"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 700,
        "y": 2800,
        "wires": [
            [
                "4acb89a30b69f58e"
            ]
        ]
    },
    {
        "id": "44496964eaa7257e",
        "type": "inject",
        "z": "2e6686c4918f199d",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": true,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "false",
        "payloadType": "bool",
        "x": 170,
        "y": 2910,
        "wires": [
            [
                "4acb89a30b69f58e"
            ]
        ]
    },
    {
        "id": "086a722972596909",
        "type": "function",
        "z": "2e6686c4918f199d",
        "name": "actual action goes on",
        "func": "\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 740,
        "y": 2880,
        "wires": [
            []
        ]
    },
    {
        "id": "c7a27394.057878",
        "type": "ui_group",
        "name": "CHART",
        "tab": "54e197d8.7f7fe8",
        "order": 2,
        "disp": false,
        "width": "9",
        "collapse": false
    },
    {
        "id": "54e197d8.7f7fe8",
        "type": "ui_tab",
        "name": "Home",
        "icon": "dashboard",
        "order": 1,
        "disabled": false,
        "hidden": false
    }
]

```

---

<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: [20 February 2022 20:54 UTC](https://discourse.nodered.org/t/buttons-pressing-and-when-to-send-messages/58629/11 "2022-02-20T20:54:46Z")

</div>

Or use a notification 'Are you sure' pop-up as I suggested.

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [20 February 2022 20:56 UTC](https://discourse.nodered.org/t/buttons-pressing-and-when-to-send-messages/58629/12 "2022-02-20T20:56:26Z")

</div>

Yes, Colin, but as I have said, I am from a REAL WORLD background.

In _the real world_ things don't just _pop up_ from no where. So that option is a bit out of scope at this time.

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [20 February 2022 21:00 UTC](https://discourse.nodered.org/t/buttons-pressing-and-when-to-send-messages/58629/13 "2022-02-20T21:00:03Z")

</div>

Nice.... The only.... _problem_ is there is no _time out_ if you accidentally press the `enable` button.

But that's easily fixed.

Thanks. Food for thought.

---

<div class="post-metadata">

### Author: ![Bobo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bobo/32/8401_2.png) [@Bobo](https://discourse.nodered.org/u/Bobo)
#### Post date: [21 February 2022 04:48 UTC](https://discourse.nodered.org/t/buttons-pressing-and-when-to-send-messages/58629/14 "2022-02-21T04:48:23Z")

</div>

> [@Trying\_to\_learn](#):
>
> Yes, Colin, but as I have said, I am from a REAL WORLD background.

Then perhaps you need to get a REAL WORLD (physical) isolation switch. And yes, you can get them cheap for Arduino/RPi.

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [21 February 2022 04:54 UTC](https://discourse.nodered.org/t/buttons-pressing-and-when-to-send-messages/58629/15 "2022-02-21T04:54:48Z")

</div>

Yes, but I am slowly migrating to touch screens and am looking at how to do that with them.

---

<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: [22 February 2022 08:35 UTC](https://discourse.nodered.org/t/buttons-pressing-and-when-to-send-messages/58629/16 "2022-02-22T08:35:13Z")

</div>

> [@Trying\_to\_learn](#):
>
> In _the real world_ things don't just _pop up_ from no where. So that option is a bit out of scope at this time.

Trying to make sure I understand here. If I understand correctly then you have a button, but you want to make sure it is not pressed accidentally, and am looking for the best strategy to use to prevent this.  
I suggested using a popup notification node to ask for confirmation but you said that you don't like this because it is too far removed from what you might expect for a physical button. Instead you are trying to use double click to prevent accidental pressing. As far as I can remember I have never seen a hardware button that you have to press twice to achieve an action. Hardware buttons are usually press once and for on and press again for off, or possibly press once for an action, and press again to repeat the action. So a double press seems as far from the 'real world' as a popup, in fact further from the real world because there one would usually expect a double click to switch it on and then off again.

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [22 February 2022 08:45 UTC](https://discourse.nodered.org/t/buttons-pressing-and-when-to-send-messages/58629/17 "2022-02-22T08:45:22Z")

</div>

You are correct. But I am messing around with touch screens.  
_Real estate_ is scarce. Although @hotNipi did suggest putting a `switch` node to act as the `enable` That is fair enough too.

I have taken that on for a couple of things. It is better in **some** ways.

If the _real life_ button is a press button, the hardware can do the double press detection.  
You press it and a pulse is sent. That _awakens_ the circuit downstream. Then the second press gets the job done.  
Yes, that entails a lot of extra stuff with lights/indicators showing what is going on.  
But as this is/can all be done with messages..... I thought it would be an interesting way to do it.

I have - since - got a nice subflow working that does both what I originally wanted to do and also does that to which I just eluded.

I'm kind of pleased with myself as I have very little understanding of what I am actually doing at a programatic level.  
I don't know/can't talk javascript.  
I don't know the commands.  
I just dig around until I get something doing what I want.

I am trying to make it _tidy_, as I write messy code. Just ask a few people with whom I have been getting help.

---

<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: [22 February 2022 10:12 UTC](https://discourse.nodered.org/t/buttons-pressing-and-when-to-send-messages/58629/18 "2022-02-22T10:12:47Z")

</div>

> [@Trying\_to\_learn](#):
>
> If the _real life_ button is a press button, the hardware can do the double press detection.  
> You press it and a pulse is sent. That _awakens_ the circuit downstream. Then the second press gets the job done.  
> Yes, that entails a lot of extra stuff with lights/indicators showing what is going on.

OK, so 'real life' means something that _can_ be done by hardware, even though it is never (or rarely) done in practice. It would not be that difficult to arrange that when a button is pressed it levers up a little notice that says "Press to Confirm" and when it is pushed back down it triggers the action. So a notification popup is just as much 'real life' as a double press, and much more intuitive for the user.

---

<div class="post-metadata">

### Author: ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)
#### Post date: [22 February 2022 10:59 UTC](https://discourse.nodered.org/t/buttons-pressing-and-when-to-send-messages/58629/19 "2022-02-22T10:59:31Z")

</div>

In real life, sometimes you find panels where critical functions are activated by simultaneously pressing two buttons which I find not too bad. Like the panel below, you have to press SOS on both sides (is a double button) at the same time when calling for help. But if it would be possible with a touch panel, I do not know

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/1/013d2eb9957d45ac67ec570cacb2da0d151cf0de.png)

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [22 February 2022 11:12 UTC](https://discourse.nodered.org/t/buttons-pressing-and-when-to-send-messages/58629/20 "2022-02-22T11:12:32Z")

</div>

I suggest you create one small button "Enable Controls". Touch that and the other buttons on the screen are active for 5 seconds.

Pretty easy to implement: the enable button opens a simple-logic-gate, a trigger node closes it again.

As for popups: I've lost count of the number of Windows PCs I've defenestrated due to infuriating "are you sure?" popups.

[Next page](https://discourse.nodered.org/t/buttons-pressing-and-when-to-send-messages/58629.md?page=2)
