I want to turn off and turn on my display via node red

Hello everybody!
I want to turn off and turn on my display via node red.
On the Raspberry this works great with xrandr --output DSI-1 --off and xrandr --output DSI-1 --auto
However, this command cannot be executed from node red with exec.
Then I get the message: Can't open display.
I thought then I would just create a script (on.sh and off.sh) the scripts work directly on the Raspberry, as soon as I run the script again via node red, I get the same error message.
Can anyone tell me how to get this to work or does anyone have another solution?
PS: I use the 7" touch display directly via foil cable.
Thank you!

When you run an exec node, because Node-RED is almost certainly started from systemd at startup, it does not have an display reference to work with.

I think you should be able to prefix the command to run with a display variable like this:

DISPLAY=:0 ./my_app

To find the right setting for DISPLAY, I think you should be able to do echo $DISPLAY from a standard command line.

1 Like

Super thank you!
I couldn't run the script quickly, but the command itself works!

For everyone who also wants to switch off their 7" display via node red, here are the nodes.
For those who want to switch off HDMI, replace DSI-1 with HDMI-x x=HDMI channel
You can find out with the command xrandr in the command line.

image

[
    {
        "id": "673c3af6dab828b5",
        "type": "tab",
        "label": "Flow 2",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "b65f82a8b8e8d84c",
        "type": "exec",
        "z": "673c3af6dab828b5",
        "command": "DISPLAY=:0 xrandr --output DSI-1 ",
        "addpay": "payload",
        "append": "",
        "useSpawn": "false",
        "timer": "10",
        "winHide": false,
        "oldrc": false,
        "name": "",
        "x": 580,
        "y": 300,
        "wires": [
            [
                "ab48be502509d061"
            ],
            [
                "91bed3b5ad656226"
            ],
            [
                "498c965228c7e7f5"
            ]
        ]
    },
    {
        "id": "3eee9a9065c11492",
        "type": "change",
        "z": "673c3af6dab828b5",
        "name": "translate",
        "rules": [
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "true",
                "fromt": "bool",
                "to": "--auto",
                "tot": "str"
            },
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "false",
                "fromt": "bool",
                "to": "--off",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 320,
        "y": 300,
        "wires": [
            [
                "b65f82a8b8e8d84c"
            ]
        ]
    },
    {
        "id": "4e39c5b56de4373d",
        "type": "inject",
        "z": "673c3af6dab828b5",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "false",
        "payloadType": "bool",
        "x": 150,
        "y": 300,
        "wires": [
            [
                "3eee9a9065c11492"
            ]
        ]
    },
    {
        "id": "ab48be502509d061",
        "type": "debug",
        "z": "673c3af6dab828b5",
        "name": "debug 75",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": true,
        "complete": "true",
        "targetType": "full",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 960,
        "y": 260,
        "wires": []
    },
    {
        "id": "498c965228c7e7f5",
        "type": "debug",
        "z": "673c3af6dab828b5",
        "name": "debug 76",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": true,
        "complete": "true",
        "targetType": "full",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 960,
        "y": 380,
        "wires": []
    },
    {
        "id": "91bed3b5ad656226",
        "type": "debug",
        "z": "673c3af6dab828b5",
        "name": "debug 77",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": true,
        "complete": "true",
        "targetType": "full",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 960,
        "y": 320,
        "wires": []
    },
    {
        "id": "d7ee6c518a5dc15a",
        "type": "inject",
        "z": "673c3af6dab828b5",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "true",
        "payloadType": "bool",
        "x": 150,
        "y": 340,
        "wires": [
            [
                "3eee9a9065c11492"
            ]
        ]
    }
]
2 Likes

I would also like to show you my finished TAB.
After two hours without use, the display and the reader (QR, PIN, NFC) switch off
Since the touch function of the display remains active, I placed a button in a tab over the entire display to "wake it up" again.
The timer also changes tabs so that you normally don't see the button.

[
    {
        "id": "0d4cbb2d996aa349",
        "type": "tab",
        "label": "monitor an/aus",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "6d5a2a80ddd37dc1",
        "type": "rpi-gpio out",
        "z": "0d4cbb2d996aa349",
        "name": "",
        "pin": "21",
        "set": "",
        "level": "0",
        "freq": "",
        "out": "out",
        "bcm": true,
        "x": 920,
        "y": 260,
        "wires": []
    },
    {
        "id": "4557cab44fd70210",
        "type": "comment",
        "z": "0d4cbb2d996aa349",
        "name": "Sleepmode Keypad and Display",
        "info": "",
        "x": 250,
        "y": 80,
        "wires": []
    },
    {
        "id": "32f8fd89a5b7bd43",
        "type": "ui_ui_control",
        "z": "0d4cbb2d996aa349",
        "name": "",
        "events": "all",
        "x": 100,
        "y": 160,
        "wires": [
            [
                "4f02361bbe2edcd3"
            ]
        ]
    },
    {
        "id": "a1c6fcbfd33487ca",
        "type": "trigger",
        "z": "0d4cbb2d996aa349",
        "name": "",
        "op1": "0",
        "op2": "1",
        "op1type": "num",
        "op2type": "num",
        "duration": "2",
        "extend": true,
        "overrideDelay": false,
        "units": "hr",
        "reset": "",
        "bytopic": "all",
        "topic": "topic",
        "outputs": 1,
        "x": 690,
        "y": 160,
        "wires": [
            [
                "6d5a2a80ddd37dc1",
                "402cb8e798baf1c2",
                "9f42e8a44f0eef48",
                "976f7349fe0d8e8a"
            ]
        ]
    },
    {
        "id": "0c71f918d21654b6",
        "type": "change",
        "z": "0d4cbb2d996aa349",
        "name": "Tab sleepmode",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "{\"tab\":\"sleepmode\"}",
                "tot": "json"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1120,
        "y": 160,
        "wires": [
            [
                "32f8fd89a5b7bd43"
            ]
        ]
    },
    {
        "id": "402cb8e798baf1c2",
        "type": "switch",
        "z": "0d4cbb2d996aa349",
        "name": "",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "1",
                "vt": "num"
            },
            {
                "t": "eq",
                "v": "0",
                "vt": "num"
            },
            {
                "t": "else"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 3,
        "x": 910,
        "y": 160,
        "wires": [
            [
                "0c71f918d21654b6"
            ],
            [],
            []
        ]
    },
    {
        "id": "f010b987a3f0de6b",
        "type": "ui_button",
        "z": "0d4cbb2d996aa349",
        "name": "",
        "group": "d84cd9992f69b4e8",
        "order": 1,
        "width": 14,
        "height": 8,
        "passthru": false,
        "label": " <font size = 50>  wake up ",
        "tooltip": "",
        "color": "",
        "bgcolor": "green",
        "className": "",
        "icon": "",
        "payload": "",
        "payloadType": "str",
        "topic": "topic",
        "topicType": "msg",
        "x": 150,
        "y": 440,
        "wires": [
            [
                "18b30027012195ed"
            ]
        ]
    },
    {
        "id": "18b30027012195ed",
        "type": "change",
        "z": "0d4cbb2d996aa349",
        "name": "Tab startscreen",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "{\"tab\":\"startscreen\"}",
                "tot": "json"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 380,
        "y": 440,
        "wires": [
            [
                "9581c5f328816ca8"
            ]
        ]
    },
    {
        "id": "9581c5f328816ca8",
        "type": "ui_ui_control",
        "z": "0d4cbb2d996aa349",
        "name": "",
        "events": "all",
        "x": 600,
        "y": 440,
        "wires": [
            []
        ]
    },
    {
        "id": "a90218148929fbe7",
        "type": "switch",
        "z": "0d4cbb2d996aa349",
        "name": "",
        "property": "sleepmode",
        "propertyType": "flow",
        "rules": [
            {
                "t": "true"
            },
            {
                "t": "else"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 490,
        "y": 160,
        "wires": [
            [],
            [
                "a1c6fcbfd33487ca"
            ]
        ]
    },
    {
        "id": "ce09e4bbe4afae18",
        "type": "change",
        "z": "0d4cbb2d996aa349",
        "name": "flow true",
        "rules": [
            {
                "t": "set",
                "p": "sleepmode",
                "pt": "flow",
                "to": "true",
                "tot": "bool"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1100,
        "y": 60,
        "wires": [
            []
        ]
    },
    {
        "id": "49d00688f7bad8f3",
        "type": "change",
        "z": "0d4cbb2d996aa349",
        "name": "flow false",
        "rules": [
            {
                "t": "set",
                "p": "sleepmode",
                "pt": "flow",
                "to": "false",
                "tot": "bool"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1100,
        "y": 100,
        "wires": [
            []
        ]
    },
    {
        "id": "4f02361bbe2edcd3",
        "type": "delay",
        "z": "0d4cbb2d996aa349",
        "name": "",
        "pauseType": "delay",
        "timeout": "500",
        "timeoutUnits": "milliseconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "allowrate": false,
        "outputs": 1,
        "x": 300,
        "y": 160,
        "wires": [
            [
                "a90218148929fbe7"
            ]
        ]
    },
    {
        "id": "9f42e8a44f0eef48",
        "type": "trigger",
        "z": "0d4cbb2d996aa349",
        "name": "",
        "op1": "true",
        "op2": "true",
        "op1type": "bool",
        "op2type": "bool",
        "duration": "1",
        "extend": true,
        "overrideDelay": false,
        "units": "s",
        "reset": "",
        "bytopic": "all",
        "topic": "topic",
        "outputs": 2,
        "x": 860,
        "y": 60,
        "wires": [
            [
                "ce09e4bbe4afae18"
            ],
            [
                "49d00688f7bad8f3"
            ]
        ]
    },
    {
        "id": "f4450d1f35d1e6f2",
        "type": "exec",
        "z": "0d4cbb2d996aa349",
        "command": "DISPLAY=:0 xrandr --output DSI-1 ",
        "addpay": "payload",
        "append": "",
        "useSpawn": "false",
        "timer": "10",
        "winHide": false,
        "oldrc": false,
        "name": "",
        "x": 1160,
        "y": 220,
        "wires": [
            [],
            [],
            []
        ]
    },
    {
        "id": "976f7349fe0d8e8a",
        "type": "change",
        "z": "0d4cbb2d996aa349",
        "name": "translate",
        "rules": [
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "0",
                "fromt": "num",
                "to": "--auto",
                "tot": "str"
            },
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "1",
                "fromt": "num",
                "to": "--off",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 920,
        "y": 220,
        "wires": [
            [
                "f4450d1f35d1e6f2"
            ]
        ]
    },
    {
        "id": "b78863376e9a1269",
        "type": "inject",
        "z": "0d4cbb2d996aa349",
        "name": "ON",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "0",
        "payloadType": "num",
        "x": 630,
        "y": 320,
        "wires": [
            [
                "976f7349fe0d8e8a",
                "6d5a2a80ddd37dc1"
            ]
        ]
    },
    {
        "id": "2d5a80ab21e3269a",
        "type": "inject",
        "z": "0d4cbb2d996aa349",
        "name": "OFF",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "1",
        "payloadType": "num",
        "x": 630,
        "y": 360,
        "wires": [
            [
                "976f7349fe0d8e8a",
                "6d5a2a80ddd37dc1"
            ]
        ]
    },
    {
        "id": "d84cd9992f69b4e8",
        "type": "ui_group",
        "name": "sleepmode",
        "tab": "d92570b02ac79961",
        "order": 1,
        "disp": false,
        "width": 14,
        "collapse": false,
        "className": ""
    },
    {
        "id": "d92570b02ac79961",
        "type": "ui_tab",
        "name": "sleepmode",
        "icon": "dashboard",
        "order": 14,
        "disabled": false,
        "hidden": false
    }
]
3 Likes

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