2020-10-03, 09:19 AM
Also, I find it really handy to have a node red dashboard so you can reboot or shutdown the Pi from a webpage on a tablet/phone/laptop.
Flow here with a countdown timer to turn off my music as well should anyone be interested >
Flow here with a countdown timer to turn off my music as well should anyone be interested >
Code:
[
{
"id": "26d6c7a0.d43558",
"type": "ui_slider",
"z": "346f9605.5900aa",
"name": "Auto Turn Off",
"label": "Minutes",
"tooltip": "",
"group": "d4a061b3.6ae9d",
"order": 2,
"width": 0,
"height": 0,
"passthru": true,
"outs": "end",
"topic": "",
"min": 0,
"max": "70",
"step": 1,
"x": 110,
"y": 460,
"wires": [
[
"e694c854.c75008"
]
]
},
{
"id": "ea149bfc.8f3d68",
"type": "exec",
"z": "346f9605.5900aa",
"command": "sudo killall clementine",
"addpay": false,
"append": "",
"useSpawn": "false",
"timer": "",
"oldrc": false,
"name": "",
"x": 780,
"y": 420,
"wires": [
[],
[],
[]
]
},
{
"id": "e694c854.c75008",
"type": "function",
"z": "346f9605.5900aa",
"name": "seconds to minutes",
"func": "if(msg.topic!=\"countdown\"){\n msg.timeout=msg.payload*60;\nreturn msg;}",
"outputs": 1,
"noerr": 0,
"x": 310,
"y": 420,
"wires": [
[
"845b73a0.3c363"
]
]
},
{
"id": "fddca3e2.bc0fc",
"type": "exec",
"z": "346f9605.5900aa",
"command": "mpc stop",
"addpay": false,
"append": "",
"useSpawn": "false",
"timer": "",
"oldrc": false,
"name": "",
"x": 740,
"y": 480,
"wires": [
[],
[],
[]
]
},
{
"id": "b667bd5a.a94f2",
"type": "inject",
"z": "346f9605.5900aa",
"name": "",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "25",
"payloadType": "num",
"x": 130,
"y": 420,
"wires": [
[
"26d6c7a0.d43558"
]
]
},
{
"id": "845b73a0.3c363",
"type": "mytimeout",
"z": "346f9605.5900aa",
"name": "",
"outtopic": "",
"outsafe": "",
"outwarning": "",
"outunsafe": "off",
"warning": "1",
"timer": "3",
"debug": false,
"ndebug": false,
"ignoreCase": false,
"repeat": false,
"again": false,
"x": 550,
"y": 420,
"wires": [
[
"fddca3e2.bc0fc",
"ea149bfc.8f3d68"
],
[
"9ea7b2c0.97ad6"
]
]
},
{
"id": "7ae79492.3b9f3c",
"type": "ui_text",
"z": "346f9605.5900aa",
"group": "d4a061b3.6ae9d",
"order": 1,
"width": 0,
"height": 0,
"name": "",
"label": "Time til turn off",
"format": "{{msg.payload}}",
"layout": "row-spread",
"x": 520,
"y": 500,
"wires": []
},
{
"id": "9ea7b2c0.97ad6",
"type": "function",
"z": "346f9605.5900aa",
"name": "minutesCountdown",
"func": "var temp = msg.payload;\nvar minutes = parseInt(temp/60);\nvar seconds = temp - minutes*60;\nmsg.payload = minutes.toString() + \":\" + seconds.toString();\nvar newMsg = { payload: minutes};\nnewMsg.topic = \"countdown\";\nreturn [msg, newMsg];",
"outputs": 2,
"noerr": 0,
"x": 310,
"y": 500,
"wires": [
[
"7ae79492.3b9f3c"
],
[
"26d6c7a0.d43558"
]
]
},
{
"id": "d1d09e6b.4fc3d",
"type": "comment",
"z": "346f9605.5900aa",
"name": "Dashboard off timer",
"info": "",
"x": 150,
"y": 380,
"wires": []
},
{
"id": "210a837e.f5231c",
"type": "ui_button",
"z": "346f9605.5900aa",
"name": "",
"group": "d4a061b3.6ae9d",
"order": 3,
"width": "2",
"height": "1",
"passthru": false,
"label": "Reboot",
"tooltip": "",
"color": "",
"bgcolor": "",
"icon": "",
"payload": "",
"payloadType": "str",
"topic": "",
"x": 130,
"y": 580,
"wires": [
[
"81aab8e9.0c53b8"
]
]
},
{
"id": "81aab8e9.0c53b8",
"type": "exec",
"z": "346f9605.5900aa",
"command": "sudo reboot",
"addpay": false,
"append": "",
"useSpawn": "false",
"timer": "",
"oldrc": false,
"name": "reboot",
"x": 330,
"y": 580,
"wires": [
[],
[],
[]
]
},
{
"id": "3ac279ec.11c376",
"type": "ui_button",
"z": "346f9605.5900aa",
"name": "",
"group": "d4a061b3.6ae9d",
"order": 3,
"width": "2",
"height": "1",
"passthru": false,
"label": "Shutdown",
"tooltip": "",
"color": "",
"bgcolor": "",
"icon": "",
"payload": "",
"payloadType": "str",
"topic": "",
"x": 120,
"y": 640,
"wires": [
[
"6725eec.382e01"
]
]
},
{
"id": "6725eec.382e01",
"type": "exec",
"z": "346f9605.5900aa",
"command": "sudo shutdown",
"addpay": false,
"append": "",
"useSpawn": "false",
"timer": "",
"oldrc": false,
"name": "shutdown",
"x": 330,
"y": 640,
"wires": [
[],
[],
[]
]
},
{
"id": "d4a061b3.6ae9d",
"type": "ui_group",
"z": "",
"name": "Auto Off",
"tab": "e93ef2b0.f7b94",
"disp": true,
"width": "6",
"collapse": false
},
{
"id": "e93ef2b0.f7b94",
"type": "ui_tab",
"z": "",
"name": "Web Radio",
"icon": "dashboard",
"order": 1,
"disabled": false,
"hidden": false
}
]