# Pi Shutdown Button with an OK/Cancel Notification

**URL:** <https://discourse.nodered.org/t/pi-shutdown-button-with-an-ok-cancel-notification/30459>\
**Category:** General\
**Created:** [21 July 2020 10:09 UTC](https://discourse.nodered.org/t/pi-shutdown-button-with-an-ok-cancel-notification/30459 "2020-07-21T10:09:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![oncdastan](https://avatars.discourse-cdn.com/v4/letter/o/34f0e0/32.png) [@oncdastan](https://discourse.nodered.org/u/oncdastan)\
**Post date:** [21 July 2020 10:09 UTC](https://discourse.nodered.org/t/pi-shutdown-button-with-an-ok-cancel-notification/30459/1 "2020-07-21T10:09:14Z")

</div>

Hi. Here is my flow:

```auto
[{"id":"b699b242.275aa","type":"ui_button","z":"4cdd06f6.faf528","name":"","group":"843bc78a.c5b078","order":5,"width":0,"height":0,"passthru":false,"label":"Shutdown","tooltip":"","color":"","bgcolor":"","icon":"","payload":" ","payloadType":"str","topic":"Shutdown?","x":650,"y":520,"wires":[["4d82c2f5.fd5f2c"]]},{"id":"4d82c2f5.fd5f2c","type":"ui_toast","z":"4cdd06f6.faf528","position":"dialog","displayTime":"3","highlight":"","sendall":true,"outputs":1,"ok":"Yes","cancel":"No","raw":false,"topic":"","name":"","x":810,"y":520,"wires":[["1415437.5d64bbd"]]},{"id":"1415437.5d64bbd","type":"exec","z":"4cdd06f6.faf528","command":"sudo shutdown -h now","addpay":true,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"","x":1040,"y":520,"wires":[[],[],[]]},{"id":"843bc78a.c5b078","type":"ui_group","z":"","name":"logo","tab":"43cae785.290cd8","order":2,"disp":false,"width":"6","collapse":false},{"id":"43cae785.290cd8","type":"ui_tab","z":"","name":"Home","icon":"dashboard","order":3,"disabled":false,"hidden":false}]

```

Both options are shutting down the Pi. I don't know how to fix this. Also, when the payload was empty, I got a weird line in the notification box. So, I put one space in the payload, instead of leaving it empty. This fixed the visual part, but it is not functioning properly, like I mentioned.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [21 July 2020 10:18 UTC](https://discourse.nodered.org/t/pi-shutdown-button-with-an-ok-cancel-notification/30459/2 "2020-07-21T10:18:05Z")

</div>

disconnect the `exec` node for the moment, now add a `debug` node to the output of the 'Show Dialog' node. Deploy adn run

what do you see in the debug?  
what happens if that msg is sent to the `exec` node?

---

<div class="post-metadata">

**Author:** ![oncdastan](https://avatars.discourse-cdn.com/v4/letter/o/34f0e0/32.png) [@oncdastan](https://discourse.nodered.org/u/oncdastan)\
**Post date:** [21 July 2020 10:38 UTC](https://discourse.nodered.org/t/pi-shutdown-button-with-an-ok-cancel-notification/30459/3 "2020-07-21T10:38:07Z")

</div>

First, I clicked on "Yes". Then, "No". This is the result:

```auto
7/21/2020, 1:37:04 PMnode: 3b223cea.433854
Shutdown? : msg.payload : string[3]
"Yes"
7/21/2020, 1:37:13 PMnode: 3b223cea.433854
Shutdown? : msg.payload : string[2]
"No"

```

---

<div class="post-metadata">

**Author:** ![oncdastan](https://avatars.discourse-cdn.com/v4/letter/o/34f0e0/32.png) [@oncdastan](https://discourse.nodered.org/u/oncdastan)\
**Post date:** [21 July 2020 10:51 UTC](https://discourse.nodered.org/t/pi-shutdown-button-with-an-ok-cancel-notification/30459/4 "2020-07-21T10:51:49Z")

</div>

Maybe I can just put a switch, compare the input with String "Yes", and connect the output to the exec. This should work.

---

<div class="post-metadata">

**Author:** ![oncdastan](https://avatars.discourse-cdn.com/v4/letter/o/34f0e0/32.png) [@oncdastan](https://discourse.nodered.org/u/oncdastan)\
**Post date:** [21 July 2020 11:04 UTC](https://discourse.nodered.org/t/pi-shutdown-button-with-an-ok-cancel-notification/30459/5 "2020-07-21T11:04:35Z")

</div>

It worked! Here is the flow, if anyone needs it:

```auto
[{"id":"b699b242.275aa","type":"ui_button","z":"4cdd06f6.faf528","name":"","group":"843bc78a.c5b078","order":5,"width":0,"height":0,"passthru":false,"label":"Shutdown","tooltip":"","color":"","bgcolor":"","icon":"","payload":" ","payloadType":"str","topic":"Shutdown?","x":650,"y":520,"wires":[["4d82c2f5.fd5f2c"]]},{"id":"4d82c2f5.fd5f2c","type":"ui_toast","z":"4cdd06f6.faf528","position":"dialog","displayTime":"3","highlight":"","sendall":true,"outputs":1,"ok":"Yes","cancel":"No","raw":false,"topic":"","name":"","x":810,"y":520,"wires":[["61d35078.247aa"]]},{"id":"1415437.5d64bbd","type":"exec","z":"4cdd06f6.faf528","command":"sudo shutdown -h now","addpay":true,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"","x":1160,"y":520,"wires":[[],[],[]]},{"id":"61d35078.247aa","type":"switch","z":"4cdd06f6.faf528","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"Yes","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":970,"y":520,"wires":[["1415437.5d64bbd"]]},{"id":"843bc78a.c5b078","type":"ui_group","z":"","name":"logo","tab":"43cae785.290cd8","order":2,"disp":false,"width":"6","collapse":false},{"id":"43cae785.290cd8","type":"ui_tab","z":"","name":"Home","icon":"dashboard","order":3,"disabled":false,"hidden":false}]

```

---

<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:** [4 August 2020 11:04 UTC](https://discourse.nodered.org/t/pi-shutdown-button-with-an-ok-cancel-notification/30459/6 "2020-08-04T11:04:38Z")

</div>

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