# Dashboard Switch for status and control

**URL:** <https://discourse.nodered.org/t/dashboard-switch-for-status-and-control/39703>\
**Category:** Dashboard\
**Created:** [25 January 2021 10:36 UTC](https://discourse.nodered.org/t/dashboard-switch-for-status-and-control/39703 "2021-01-25T10:36:29Z")\
**Posts on this page:** 18\
**Page:** 2

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [26 January 2021 18:04 UTC](https://discourse.nodered.org/t/dashboard-switch-for-status-and-control/39703/22 "2021-01-26T18:04:24Z")

</div>

> [@vikozo](#):
>
> how did you set the node for sending the information to the bulb itself?

You need to look up what the bulb requires. I have no experience of the bulb you mention.

---

<div class="post-metadata">

**Author:** ![molt](https://avatars.discourse-cdn.com/v4/letter/m/51bf81/32.png) [@molt](https://discourse.nodered.org/u/molt)\
**Post date:** [26 January 2021 21:52 UTC](https://discourse.nodered.org/t/dashboard-switch-for-status-and-control/39703/23 "2021-01-26T21:52:54Z")

</div>

Is there a way to solve that?  
I mean a switch should show the actual state of the light and the switch should also have the possibility to change the light on or off.  
I mean I'm not a programmer but it doesn't sounds like rocket science.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [26 January 2021 22:11 UTC](https://discourse.nodered.org/t/dashboard-switch-for-status-and-control/39703/24 "2021-01-26T22:11:39Z")

</div>

> [@molt](#):
>
> Is there a way to solve that?

Yes, configure the switch as I have advised. That should solve it. Why will you not show the debug information that I keep asking for? What is coming out of the switch and what is going back into it in the failing condition? I can't do any more till you post that information.

---

<div class="post-metadata">

**Author:** ![molt](https://avatars.discourse-cdn.com/v4/letter/m/51bf81/32.png) [@molt](https://discourse.nodered.org/u/molt)\
**Post date:** [27 January 2021 06:32 UTC](https://discourse.nodered.org/t/dashboard-switch-for-status-and-control/39703/25 "2021-01-27T06:32:21Z")

</div>

You mean I should replace the change-node with this one

> [@Colin](#):
>
> ```auto
> msg.payload = msg.payload.on ? "true" : "false"
> return msg;
> 
> ```

in a function-node?  
I will post the debug information as soon as possible.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [27 January 2021 10:04 UTC](https://discourse.nodered.org/t/dashboard-switch-for-status-and-control/39703/26 "2021-01-27T10:04:53Z")

</div>

> [@molt](#):
>
> You mean I should replace the change-node with this one

Read my post again. It won't make any difference to the way it works, it is just a more efficient way of doing what you are doing in a Change and a Function node. You can change it if you want to but it is nothing to do with the problem.

---

<div class="post-metadata">

**Author:** ![molt](https://avatars.discourse-cdn.com/v4/letter/m/51bf81/32.png) [@molt](https://discourse.nodered.org/u/molt)\
**Post date:** [27 January 2021 18:46 UTC](https://discourse.nodered.org/t/dashboard-switch-for-status-and-control/39703/27 "2021-01-27T18:46:27Z")

</div>

Now I have configured the switch like you said but its not working.

 ![Phoscon-App-und-3-weitere-Seiten-Persönlich-–-Microsoft_-Edge-2021-01-27-19-44-24](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/5/35f3035524955a726a9ac9ccd9262822d01092ea.gif)  
Thats from the switch debug\_out

```auto
msg : Object
object
payload: "false"
socketid: "03PCWf1zELrqw5UcAAAE"
_msgid: "aeaef91d.9a9448"

```

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [27 January 2021 19:27 UTC](https://discourse.nodered.org/t/dashboard-switch-for-status-and-control/39703/28 "2021-01-27T19:27:20Z")

</div>

What is not working? Videos are useless. Tell me what happens to the real light. Also I need to see what is coming back into the front of the switch as I have asked many times.

---

<div class="post-metadata">

**Author:** ![molt](https://avatars.discourse-cdn.com/v4/letter/m/51bf81/32.png) [@molt](https://discourse.nodered.org/u/molt)\
**Post date:** [27 January 2021 19:39 UTC](https://discourse.nodered.org/t/dashboard-switch-for-status-and-control/39703/29 "2021-01-27T19:39:17Z")

</div>

I cannot turn off the light by using the switch because the switch is, if the real light is on, always getting the input "true".

If the real light is on the switch input is

```auto
msg.payload : string[4]
"true"

```

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [27 January 2021 20:56 UTC](https://discourse.nodered.org/t/dashboard-switch-for-status-and-control/39703/31 "2021-01-27T20:56:32Z")

</div>

I don't fully understand. If you switch the light off via external means what comes in to the switch and what does the switch then show, and if you switch the light off by external means what comes in to the switch and what does the switch then show?

---

<div class="post-metadata">

**Author:** ![molt](https://avatars.discourse-cdn.com/v4/letter/m/51bf81/32.png) [@molt](https://discourse.nodered.org/u/molt)\
**Post date:** [27 January 2021 21:58 UTC](https://discourse.nodered.org/t/dashboard-switch-for-status-and-control/39703/32 "2021-01-27T21:58:34Z")

</div>

I don't fully understand you either 😉  
Let's start from the beginning again.  
I have a smart bulb where the power (electric) is always on (like hue lights).  
I'm able to control the light via deconz (Phoscon).  
For deconz there's the node I've added to combine node red and deconz.  
The deconz-input node is always sending the status of the selected light.  
There's the function which is sending status to the switch (if the input-node sends "true" , the switch is set to true, else, the switch sends a "false" ).  
The switch sends the true or false message to the deconz-out node. That's it.  
What comes from the deconz-input to the switch

```auto
27.1.2021, 22:52:51node: debugh_switch_input
msg.payload : string[4]
"true"

```

And that is what comes out from the switch if I try to move the switch slider to turn the light of.

```auto
27.1.2021, 22:52:58node: debug_switch_output
msg : Object
object
payload: "false"
socketid: "0cy1y2Yeb5H8cHn7AAAF"
_msgid: "afa730ed.9fbb8"

```

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [27 January 2021 22:08 UTC](https://discourse.nodered.org/t/dashboard-switch-for-status-and-control/39703/33 "2021-01-27T22:08:01Z")

</div>

Let's try and simplify it so I can understand.

1. Disconnect the wire going into the ui\_switch node.  
Set the ui\_switch to Pass Through messages.  
Now, if you click the ui\_switch off and on does the real light go off and on?

2. Assuming that works then (with the wire into the ui\_switch still disconnected) connect a debug node showing what is coming out of the function node to the left of the switch node. What does that show as you switch the ui\_switch off and on?

3. Post your current flow so I can check what you have now (leave off the Deconz nodes, I just have to keep deleting them and deleting the config node, which is annoying).

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [27 January 2021 22:15 UTC](https://discourse.nodered.org/t/dashboard-switch-for-status-and-control/39703/34 "2021-01-27T22:15:07Z")

</div>

It is late now, so I have to go. I will have a look at what you have posted in the morning.

---

<div class="post-metadata">

**Author:** ![molt](https://avatars.discourse-cdn.com/v4/letter/m/51bf81/32.png) [@molt](https://discourse.nodered.org/u/molt)\
**Post date:** [28 January 2021 14:55 UTC](https://discourse.nodered.org/t/dashboard-switch-for-status-and-control/39703/35 "2021-01-28T14:55:11Z")

</div>

Thank you for not giving up on me! 😄

> [@Colin](#):
>
> Disconnect the wire going into the ui\_switch node.  
> Set the ui\_switch to Pass Through messages.  
> Now, if you click the ui\_switch off and on does the real light go off and on?

1. 

**Scenario1** : Light is off, switch is off --\> Press the switch to turn the light on --\> Switch is on, light is on  
**Scenario2** : Light is on, switch is on --\> Press the switch to turn the light off --\> Switch goes off light stays on  
**Scenario3** : Light is off, switch is on --\> Press the switch to turn the light off --\> Switch goes off light goes on

1. Logs from the debug node which is comming out of the function node (wire is disconnected into the ui-switch)

**To Scenario1** :

```auto
28.1.2021, 15:50:15node: debug_function_out
msg.payload : string[4]
"true"

```

**To Scenario2** :  
Nothing

**To Scenario3** :

```auto
28.1.2021, 15:51:47node: debug_function_out
msg.payload : string[4]
"true"

```

1. 

```auto
[{"id":"29255051.dc251","type":"tab","label":"Dashboard UI","disabled":false,"info":""},{"id":"c4466cf7.5066f","type":"ui_switch","z":"29255051.dc251","name":"","label":"switch_light1","tooltip":"","group":"16ca559d.db74ea","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":240,"wires":[["2ac55486.b107fc"]]},{"id":"956b86bb.f530c8","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":240,"wires":[["fa3731e3.be23"]]},{"id":"fa3731e3.be23","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":240,"wires":[["54c34b8e.d6b474"]]},{"id":"2ac55486.b107fc","type":"debug","z":"29255051.dc251","name":"debug_switch_output","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1060,"y":300,"wires":[]},{"id":"54c34b8e.d6b474","type":"debug","z":"29255051.dc251","name":"debug_function_out","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":850,"y":460,"wires":[]},{"id":"16ca559d.db74ea","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}]

```

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [28 January 2021 15:20 UTC](https://discourse.nodered.org/t/dashboard-switch-for-status-and-control/39703/36 "2021-01-28T15:20:48Z")

</div>

> [@molt](#):
>
> **Scenario2** : Light is on, switch is on --\> Press the switch to turn the light off --\> Switch goes off light stays on

You said in post #7

> [@molt](#):
>
> The switch is working properly. I can turn the lights on and off with the switch.

But it appears that is no longer the case. What has changed with the switch -\> light control since then? You need to get that working again before doing anything else.

---

<div class="post-metadata">

**Author:** ![molt](https://avatars.discourse-cdn.com/v4/letter/m/51bf81/32.png) [@molt](https://discourse.nodered.org/u/molt)\
**Post date:** [28 January 2021 15:41 UTC](https://discourse.nodered.org/t/dashboard-switch-for-status-and-control/39703/37 "2021-01-28T15:41:13Z")

</div>

Ah i know what the problem was:  
If i set the payload from the switch to string --\> I can turn on the light but i cant turn it off.  
If i set the payload from the switch to boolean --\> Turn on and off works.  
The Scenarios i´ve postet the switch payload was set to string. Should i test again with boolean?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [28 January 2021 16:43 UTC](https://discourse.nodered.org/t/dashboard-switch-for-status-and-control/39703/38 "2021-01-28T16:43:42Z")

</div>

> [@molt](#):
>
> Should i test again with boolean

Yes, change the switch to output booleans, and take out the function node and change the Change node so it is configured like this  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/f/ff0b2c6c878f68cb77f363253c9e7a36c91500a7.png)  
It doesn't need to change the values, they should stay as boolean, so it is just necessary to Move msg.payload.on To msg.payload. Then retry the 1 and 2 from my earlier post. If they look OK then change the switch to NOT pass through and to Show State of Input. Then join the input wire up and see what happens.

---

<div class="post-metadata">

**Author:** ![molt](https://avatars.discourse-cdn.com/v4/letter/m/51bf81/32.png) [@molt](https://discourse.nodered.org/u/molt)\
**Post date:** [29 January 2021 08:00 UTC](https://discourse.nodered.org/t/dashboard-switch-for-status-and-control/39703/39 "2021-01-29T08:00:11Z")

</div>

IT WORKS! Thanks a lot for your help and pattience. Without the function-node plus the changes for the switch-node its finally working!

```auto
[{"id":"29255051.dc251","type":"tab","label":"Dashboard UI","disabled":false,"info":""},{"id":"c4466cf7.5066f","type":"ui_switch","z":"29255051.dc251","name":"","label":"switch_light1","tooltip":"","group":"16ca559d.db74ea","order":0,"width":0,"height":0,"passthru":false,"decouple":"true","topic":"","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":990,"y":180,"wires":[[]]},{"id":"956b86bb.f530c8","type":"change","z":"29255051.dc251","name":"","rules":[{"t":"move","p":"payload.on","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":180,"wires":[["c4466cf7.5066f"]]},{"id":"16ca559d.db74ea","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}]

```

---

<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:** [12 February 2021 08:00 UTC](https://discourse.nodered.org/t/dashboard-switch-for-status-and-control/39703/40 "2021-02-12T08:00:38Z")

</div>

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

[Previous page](https://discourse.nodered.org/t/dashboard-switch-for-status-and-control/39703.md?page=1)
