Dashboard Switch for status and control

Hi,

this is my first try to implement sth. with node-red.
I´ve installed node-red-contrib-deconz and node-red-dashboard - they´re both up and running.

The switch should show me the actual state of the light (on or off) and i want also to be able to change the status of the switch (which controls the light).
But the switch sends the value direct to the light so i can not manual change the light from the switch on the Dashboard-UI.

I hope someone knows what ive tried to explain in my bad english lol

Welcome to the forum @molt

Do you mean that the output from the switch is not the correct output to drive the light node? If so then you can use a Change or Function node to set it to the right value.
Make sure that you have not selected message pass through in the switch or you will get an infinite loop.

Edit: or change the configuration of the Switch node to send the correct output, then adjust the function on in the input of the switch to also use those values

1 Like

Hey @Colin,
thanks for your fast reply!

Let me try to explain what ive done so far.

  1. The "light-node" gives me a true or false (boolean) for the object "on"
  2. The "change-node" search the boolean "true" and replaces it with a string "true"
  3. The function is:
    if (msg.payload.on == "true"){
    msg.payload = "true";
    }
    else {
    msg.payload = "false";
    }
  4. the "switch_light" is now true or false and gives the parameter to the last node to turn the light on or off

Now my challange: If i switch the light by using the switch in the ui it will be overwritten by the intput from the "light-node"

Please export your flow (select the nodes and select Export in the menus) and paste it here. When pasting use the </> button at the top of the forum entry window.
Also tell us what values you have to send to the light to control it.

1 Like

To control the light i have to send the value from object "on"

msg.payload : Object
object
alert: "none"
bri: 254
colormode: "ct"
ct: 370
on: true
reachable: true
[
    {
        "id": "29255051.dc251",
        "type": "tab",
        "label": "Dashboard UI",
        "disabled": false,
        "info": ""
    },
    {
        "id": "66bf7b9a.ab07b4",
        "type": "ui_switch",
        "z": "29255051.dc251",
        "name": "",
        "label": "switch_light",
        "tooltip": "",
        "group": "b45673d4.b5364",
        "order": 0,
        "width": 0,
        "height": 0,
        "passthru": true,
        "decouple": "false",
        "topic": "",
        "style": "",
        "onvalue": "true",
        "onvalueType": "str",
        "onicon": "",
        "oncolor": "",
        "offvalue": "false",
        "offvalueType": "str",
        "officon": "",
        "offcolor": "",
        "x": 870,
        "y": 160,
        "wires": [
            [
                "edb65647.889838"
            ]
        ]
    },
    {
        "id": "ab8fa445.09ab18",
        "type": "function",
        "z": "29255051.dc251",
        "name": "",
        "func": "if (msg.payload.on == \"true\"){\nmsg.payload = \"true\";\n}\nelse {\nmsg.payload = \"false\";\n}\nreturn msg;\n",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "x": 700,
        "y": 160,
        "wires": [
            [
                "66bf7b9a.ab07b4"
            ]
        ]
    },
    {
        "id": "5a309341.18881c",
        "type": "change",
        "z": "29255051.dc251",
        "name": "",
        "rules": [
            {
                "t": "change",
                "p": "payload.on",
                "pt": "msg",
                "from": "true",
                "fromt": "bool",
                "to": "true",
                "tot": "str"
            },
            {
                "t": "change",
                "p": "payload.false",
                "pt": "msg",
                "from": "false",
                "fromt": "bool",
                "to": "false",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 500,
        "y": 160,
        "wires": [
            [
                "ab8fa445.09ab18"
            ]
        ]
    },
    {
        "id": "d56e2d4b.d5343",
        "type": "deconz-input",
        "z": "29255051.dc251",
        "name": "",
        "server": "c4ace8e0.769aa8",
        "device": "7c:b0:3e:aa:00:ad:86:ee-03",
        "device_name": "Badezimmer-Decke : Color temperature light",
        "topic": "",
        "state": "0",
        "output": "always",
        "outputAtStartup": true,
        "x": 190,
        "y": 160,
        "wires": [
            [
                "5a309341.18881c"
            ],
            []
        ]
    },
    {
        "id": "edb65647.889838",
        "type": "deconz-output",
        "z": "29255051.dc251",
        "name": "",
        "server": "c4ace8e0.769aa8",
        "device": "7c:b0:3e:aa:00:ad:86:ee-03",
        "device_name": "Badezimmer-Decke : Color temperature light",
        "command": "on",
        "commandType": "deconz_cmd",
        "payload": "payload",
        "payloadType": "msg",
        "transitionTime": "",
        "x": 1170,
        "y": 160,
        "wires": []
    },
    {
        "id": "b45673d4.b5364",
        "type": "ui_group",
        "name": "Standard",
        "tab": "7874e5cb.93b9ec",
        "order": 1,
        "disp": true,
        "width": "6",
        "collapse": false
    },
    {
        "id": "c4ace8e0.769aa8",
        "type": "deconz-server",
        "name": "deconz",
        "ip": "192.168.1.75",
        "port": "80",
        "apikey": "1A32BAACC0",
        "ws_port": "443",
        "secure": false,
        "polling": "15"
    },
    {
        "id": "7874e5cb.93b9ec",
        "type": "ui_tab",
        "name": "Home",
        "icon": "dashboard",
        "disabled": false,
        "hidden": false
    }
]

Do you mean you have to send that whole structure? If so then see if this controls the light (note, I have changed the switch config so use this one not the one you currently have). Don't connect anything to the input yet.

[edit] Forgot the flow, here it is, hopefully

[{"id":"66bf7b9a.ab07b4","type":"ui_switch","z":"29255051.dc251","name":"","label":"switch_light","tooltip":"","group":"b45673d4.b5364","order":0,"width":0,"height":0,"passthru":false,"decouple":"false","topic":"","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":870,"y":160,"wires":[["bde16114.37d62"]]},{"id":"bde16114.37d62","type":"function","z":"29255051.dc251","name":"","func":"msg.payload = {\n    alert: \"none\",\n    bri: 254,\n    colormode: \"ct\",\n    ct: 370,\n    on: msg.payload,\n    reachable: true,\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1050,"y":160,"wires":[["953eb27a.de8a98"]]},{"id":"953eb27a.de8a98","type":"debug","z":"29255051.dc251","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1230,"y":120,"wires":[]},{"id":"b45673d4.b5364","type":"ui_group","name":"Standard","tab":"7874e5cb.93b9ec","order":1,"disp":true,"width":"6","collapse":false},{"id":"7874e5cb.93b9ec","type":"ui_tab","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]
1 Like

Maybe you missunderstood me or im too stupid to explain it with english skills.

The switch is working properly. I can turn the lights on and off with the switch.
What i want is that the switch is showing the status of the light and additionally that i am able to turn the lights on and off with the switch.
But currently thats not possible because the switch is getting the message from the first light-node and is automatically using this value to control the light.

Well I asked what you have to send to the light to control it and you showed me a data structure with on: true in it which appeared to mean that you need to send that to control it. If the existing flow does control the light then it seems you have to send just strings "true" or "false".
If so then your original flow should work if you do what I originally suggested, which is to set the switch to Not pass messages through and to Show state of the input. Then when you click the switch it should send the required state to control the light. The switch will not visually change, however, until the input comes in with the new state.
If that doesn't work add a debug node showing what is coming out of the switch and what is going into it. Give the debug nodes names so it is clear which is which. Also post the new flow.

1 Like

Thanks for your patience @Colin !
I´ve uploaded a video to demonstrate you what ive tried to explain.
Everything is working except the "turn off light" by the switch command.

[
    {
        "id": "29255051.dc251",
        "type": "tab",
        "label": "Dashboard UI",
        "disabled": false,
        "info": ""
    },
    {
        "id": "66bf7b9a.ab07b4",
        "type": "ui_switch",
        "z": "29255051.dc251",
        "name": "",
        "label": "switch_light",
        "tooltip": "",
        "group": "b45673d4.b5364",
        "order": 0,
        "width": 0,
        "height": 0,
        "passthru": false,
        "decouple": "true",
        "topic": "",
        "style": "",
        "onvalue": "true",
        "onvalueType": "str",
        "onicon": "",
        "oncolor": "",
        "offvalue": "false",
        "offvalueType": "str",
        "officon": "",
        "offcolor": "",
        "x": 890,
        "y": 160,
        "wires": [
            [
                "168163dc.c083dc",
                "edb65647.889838"
            ]
        ]
    },
    {
        "id": "5a309341.18881c",
        "type": "change",
        "z": "29255051.dc251",
        "name": "",
        "rules": [
            {
                "t": "change",
                "p": "payload.on",
                "pt": "msg",
                "from": "true",
                "fromt": "bool",
                "to": "true",
                "tot": "str"
            },
            {
                "t": "change",
                "p": "payload.on",
                "pt": "msg",
                "from": "false",
                "fromt": "bool",
                "to": "false",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 500,
        "y": 160,
        "wires": [
            [
                "6ff2a14d.f12a5"
            ]
        ]
    },
    {
        "id": "d56e2d4b.d5343",
        "type": "deconz-input",
        "z": "29255051.dc251",
        "name": "",
        "server": "c4ace8e0.769aa8",
        "device": "7c:b0:3e:aa:00:ad:86:ee-03",
        "device_name": "Badezimmer-Decke : Color temperature light",
        "topic": "",
        "state": "0",
        "output": "always",
        "outputAtStartup": true,
        "x": 190,
        "y": 160,
        "wires": [
            [
                "5a309341.18881c"
            ],
            []
        ]
    },
    {
        "id": "edb65647.889838",
        "type": "deconz-output",
        "z": "29255051.dc251",
        "name": "",
        "server": "c4ace8e0.769aa8",
        "device": "7c:b0:3e:aa:00:ad:86:ee-03",
        "device_name": "Badezimmer-Decke : Color temperature light",
        "command": "on",
        "commandType": "deconz_cmd",
        "payload": "payload",
        "payloadType": "str",
        "transitionTime": "",
        "x": 1230,
        "y": 160,
        "wires": []
    },
    {
        "id": "168163dc.c083dc",
        "type": "function",
        "z": "29255051.dc251",
        "name": "",
        "func": "if (msg.payload == \"false\"){\nmsg.payload = \"false\";\n}\nelse {\nmsg.payload = \"true\";\n}\nreturn msg;\n",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "x": 900,
        "y": 340,
        "wires": [
            [
                "66bf7b9a.ab07b4"
            ]
        ]
    },
    {
        "id": "6ff2a14d.f12a5",
        "type": "function",
        "z": "29255051.dc251",
        "name": "",
        "func": "if (msg.payload.on == \"true\"){\nmsg.payload = \"true\";\n}\nelse {\nmsg.payload = \"false\";\n}\nreturn msg;\n",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "x": 700,
        "y": 160,
        "wires": [
            [
                "66bf7b9a.ab07b4"
            ]
        ]
    },
    {
        "id": "b45673d4.b5364",
        "type": "ui_group",
        "name": "Standard",
        "tab": "7874e5cb.93b9ec",
        "order": 1,
        "disp": true,
        "width": "6",
        "collapse": false
    },
    {
        "id": "c4ace8e0.769aa8",
        "type": "deconz-server",
        "name": "deconz",
        "ip": "192.168.1.75",
        "port": "80",
        "apikey": "1A32BAACC0",
        "ws_port": "443",
        "secure": false,
        "polling": "15"
    },
    {
        "id": "7874e5cb.93b9ec",
        "type": "ui_tab",
        "name": "Home",
        "icon": "dashboard",
        "disabled": false,
        "hidden": false
    }
]

Are you looking for this?

[{"id":"29255051.dc251","type":"tab","label":"Dashboard UI","disabled":false,"info":""},{"id":"66bf7b9a.ab07b4","type":"ui_switch","z":"29255051.dc251","name":"","label":"switch_light1","tooltip":"","group":"b45673d4.b5364","order":0,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"","style":"","onvalue":"true","onvalueType":"str","onicon":"","oncolor":"","offvalue":"false","offvalueType":"str","officon":"","offcolor":"","x":850,"y":160,"wires":[["376e3c15.2661c4"]]},{"id":"5a309341.18881c","type":"change","z":"29255051.dc251","name":"","rules":[{"t":"change","p":"payload.on","pt":"msg","from":"true","fromt":"bool","to":"true","tot":"str"},{"t":"change","p":"payload.on","pt":"msg","from":"false","fromt":"bool","to":"false","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":160,"wires":[["6ff2a14d.f12a5"]]},{"id":"6ff2a14d.f12a5","type":"function","z":"29255051.dc251","name":"","func":"if (msg.payload.on == \"true\"){\nmsg.payload = \"true\";\n}\nelse {\nmsg.payload = \"false\";\n}\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":680,"y":160,"wires":[["66bf7b9a.ab07b4"]]},{"id":"77f90995.eb3488","type":"inject","z":"29255051.dc251","name":"msg.payload.on boolean true","props":[{"p":"payload.on","v":"true","vt":"bool"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":220,"y":140,"wires":[["5a309341.18881c"]]},{"id":"376e3c15.2661c4","type":"debug","z":"29255051.dc251","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1010,"y":160,"wires":[]},{"id":"4750783.2e79888","type":"inject","z":"29255051.dc251","name":"msg.payload.on boolean false","props":[{"p":"payload.on","v":"false","vt":"bool"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":220,"y":180,"wires":[["5a309341.18881c"]]},{"id":"b45673d4.b5364","type":"ui_group","name":"Standard","tab":"7874e5cb.93b9ec","order":1,"disp":true,"width":"6","collapse":false},{"id":"7874e5cb.93b9ec","type":"ui_tab","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

Without 2nd function and ticked checkbox in switch( Pass through msg if payload matches new state)

1 Like

I think there may be some confusion. What does the input coming from the deconz input node indicate? I assumed that it was showing you the actual state of the light - the actual real light. Is that correct?
If it is not correct is it possible to have an input node showing the actual state of the light?

1 Like

@markost If i replace the inject with the deconz input and the debug with the deconz-out i am not able to switch the light off by using the ui-switch, like before.

@Colin The "deconz-input" listens for messages send from deconz.
Theres also a "deconz-get" which gets the current state of a device a group.
Yep, deconz-input is showing the actual state of the light...the real light.

In that case show us the debug output that I asked for. What is being sent by the switch and what is going into the switch as a result of that. Also what the light does in that situation.

I dont have "deconz", so inject/debug are used for simulation...
What about: Without 2nd function and ticked checkbox in switch( Pass through msg if payload matches new state)?

Are you posting under two different names? It is confusing. Which flow are you testing now and what is not working?
Do not tick pass through. Do not have feedback round the switch.

The flow you posted in post #10 works perfectly for me after I remove the pass through selection and select Show State of Input.

[{"id":"17833bc8.a56494","type":"ui_switch","z":"219f852.e8be6fa","name":"","label":"switch_light1","tooltip":"","group":"3f589707.4f5da","order":0,"width":0,"height":0,"passthru":false,"decouple":"true","topic":"","style":"","onvalue":"true","onvalueType":"str","onicon":"","oncolor":"","offvalue":"false","offvalueType":"str","officon":"","offcolor":"","x":850,"y":160,"wires":[["5346050f.c5ff94"]]},{"id":"5f6eceac.457318","type":"change","z":"219f852.e8be6fa","name":"","rules":[{"t":"change","p":"payload.on","pt":"msg","from":"true","fromt":"bool","to":"true","tot":"str"},{"t":"change","p":"payload.on","pt":"msg","from":"false","fromt":"bool","to":"false","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":160,"wires":[["1c5c7a56.3f864e"]]},{"id":"1c5c7a56.3f864e","type":"function","z":"219f852.e8be6fa","name":"","func":"if (msg.payload.on == \"true\"){\nmsg.payload = \"true\";\n}\nelse {\nmsg.payload = \"false\";\n}\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":680,"y":160,"wires":[["17833bc8.a56494"]]},{"id":"2488c8c3.b7bff","type":"inject","z":"219f852.e8be6fa","name":"msg.payload.on boolean true","props":[{"p":"payload.on","v":"true","vt":"bool"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":220,"y":140,"wires":[["5f6eceac.457318"]]},{"id":"5346050f.c5ff94","type":"debug","z":"219f852.e8be6fa","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1010,"y":160,"wires":[]},{"id":"4e6b042e.bc1e34","type":"inject","z":"219f852.e8be6fa","name":"msg.payload.on boolean false","props":[{"p":"payload.on","v":"false","vt":"bool"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":220,"y":180,"wires":[["5f6eceac.457318"]]},{"id":"3f589707.4f5da","type":"ui_group","name":"Standard","tab":"7874e5cb.93b9ec","order":1,"disp":true,"width":"6","collapse":false},{"id":"7874e5cb.93b9ec","type":"ui_tab","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

On a side note you can replace the Change and Function node with a Function node containing

msg.payload = msg.payload.on  ?  "true"  :  "false"
return msg;

Hello @Colin
how did you set the node for sending the information to the bulb itself?
The Nodes like you have it, show the correct information but the Bulb is not changing :wink:
i have the lidl bulb with (Color temperature light)

have a nice day
vinc

For me it is working as I posted (Pass through select) :thinking:

I am unclear who all the various people posting here are. Are you all separate people or are one or more of you using multiple names?

1 Like

It will until you close the loop so that a message sent by the switch controls the light and triggers an input where the Inject nodes are, then you will get an infinite loop.

2 Likes