Pi Shutdown Button with an OK/Cancel Notification

Hi. Here is my flow:

[{"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.

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?

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

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"

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

1 Like

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

[{"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}]

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