# How to read the state of ui-switch in node red

**URL:** <https://discourse.nodered.org/t/how-to-read-the-state-of-ui-switch-in-node-red/30538>\
**Category:** General\
**Created:** [22 July 2020 10:28 UTC](https://discourse.nodered.org/t/how-to-read-the-state-of-ui-switch-in-node-red/30538 "2020-07-22T10:28:36Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![shipra](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@shipra](https://discourse.nodered.org/u/shipra)\
**Post date:** [22 July 2020 10:28 UTC](https://discourse.nodered.org/t/how-to-read-the-state-of-ui-switch-in-node-red/30538/1 "2020-07-22T10:28:36Z")

</div>

how to read the state of ui-switch in node red .I want to store the message whenever someone toggle the switch and then i have to pass some messg to mqtt out node

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [22 July 2020 11:30 UTC](https://discourse.nodered.org/t/how-to-read-the-state-of-ui-switch-in-node-red/30538/2 "2020-07-22T11:30:41Z")

</div>

I edited your post to so it would display normally instead of looking like shouting)

What have you tried so far? Have you connected a `debug` node (set to display the Complete msg object) to the outpput of the `u-switch` to see what it is returning.

> [@shipra](#):
>
> I want to store the message whenever someone toggle the switch and then i have to pass some messg to mqtt out node

Where do you intend to store the output?

> [@shipra](#):
>
> i have to pass some messg to mqtt out node

what kind of message? if it is not in msg.payload, then you will need another node (maybe a `change` node) to create the message you want to pass,

---

<div class="post-metadata">

**Author:** ![shipra](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@shipra](https://discourse.nodered.org/u/shipra)\
**Post date:** [22 July 2020 11:32 UTC](https://discourse.nodered.org/t/how-to-read-the-state-of-ui-switch-in-node-red/30538/3 "2020-07-22T11:32:40Z")

</div>

> [@zenofmud](#):
>
> What have you tried so far? Have you connected a `debug` node (set to display the Complete msg object) to the outpput of the `u-switch` to see what it is returning.

Yes Sir I have deployed it

---

<div class="post-metadata">

**Author:** ![shipra](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@shipra](https://discourse.nodered.org/u/shipra)\
**Post date:** [22 July 2020 11:34 UTC](https://discourse.nodered.org/t/how-to-read-the-state-of-ui-switch-in-node-red/30538/4 "2020-07-22T11:34:09Z")

</div>

> [@zenofmud](#):
>
> Where do you intend to store the output?

This thing i dont know .Like I want to send my open message back to mqtt out when someone really has toggled that open switch

---

<div class="post-metadata">

**Author:** ![shipra](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@shipra](https://discourse.nodered.org/u/shipra)\
**Post date:** [22 July 2020 11:35 UTC](https://discourse.nodered.org/t/how-to-read-the-state-of-ui-switch-in-node-red/30538/5 "2020-07-22T11:35:09Z")

</div>

> [@zenofmud](#):
>
> what kind of message? if it is not in msg.payload, then you will need another node (maybe a `change` node) to create the message you want to pass,

Yes I have used the change node .

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [22 July 2020 11:36 UTC](https://discourse.nodered.org/t/how-to-read-the-state-of-ui-switch-in-node-red/30538/6 "2020-07-22T11:36:09Z")

</div>

> [@shipra](#):
>
> I want to send my open message back to mqtt out when someone really has toggled that open switch

So you will need to test the output of the `ui-switch` node. Which of the [core nodes](https://nodered.org/docs/user-guide/nodes) do you think you could use for that purpose?

---

<div class="post-metadata">

**Author:** ![shipra](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@shipra](https://discourse.nodered.org/u/shipra)\
**Post date:** [22 July 2020 11:38 UTC](https://discourse.nodered.org/t/how-to-read-the-state-of-ui-switch-in-node-red/30538/7 "2020-07-22T11:38:02Z")

</div>

Debug node for checking the output?

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [22 July 2020 11:41 UTC](https://discourse.nodered.org/t/how-to-read-the-state-of-ui-switch-in-node-red/30538/8 "2020-07-22T11:41:30Z")

</div>

is that your answer to my question of how you can test the output? If so, have you noticed that the debug node is a dead end node (i.e. it doesn't have an output)

Go back and look at the core nodes again (I provided you a link to them) and try again.

---

<div class="post-metadata">

**Author:** ![shipra](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@shipra](https://discourse.nodered.org/u/shipra)\
**Post date:** [22 July 2020 12:06 UTC](https://discourse.nodered.org/t/how-to-read-the-state-of-ui-switch-in-node-red/30538/9 "2020-07-22T12:06:00Z")

</div>

Switch node?

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [22 July 2020 12:33 UTC](https://discourse.nodered.org/t/how-to-read-the-state-of-ui-switch-in-node-red/30538/10 "2020-07-22T12:33:24Z")

</div>

You tell me. How would you use it?

---

<div class="post-metadata">

**Author:** ![shipra](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@shipra](https://discourse.nodered.org/u/shipra)\
**Post date:** [22 July 2020 12:35 UTC](https://discourse.nodered.org/t/how-to-read-the-state-of-ui-switch-in-node-red/30538/11 "2020-07-22T12:35:10Z")

</div>

if open switch has string on clicking =DR1\_ON then send messge to my mqtt out

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [22 July 2020 12:37 UTC](https://discourse.nodered.org/t/how-to-read-the-state-of-ui-switch-in-node-red/30538/12 "2020-07-22T12:37:29Z")

</div>

Does it work?

---

<div class="post-metadata">

**Author:** ![shipra](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@shipra](https://discourse.nodered.org/u/shipra)\
**Post date:** [22 July 2020 12:39 UTC](https://discourse.nodered.org/t/how-to-read-the-state-of-ui-switch-in-node-red/30538/13 "2020-07-22T12:39:25Z")

</div>

yes debug node i have deployed it is sending me DR1\_ON whenever i am clicking that

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [22 July 2020 12:49 UTC](https://discourse.nodered.org/t/how-to-read-the-state-of-ui-switch-in-node-red/30538/14 "2020-07-22T12:49:33Z")

</div>

Let me rephrase my query to you.

You have a msg coming from the `ui-switch` node. The msg contains information you need to test to see if it should be sent to the `mqtt-out` node so you have  
`ui-switch ------> ????? -------> mqtt-out`

What do you need to put in the middle (where the ?????? marks are) in order to text the contents of the msg and determine if you should send the msg on?

---

<div class="post-metadata">

**Author:** ![shipra](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@shipra](https://discourse.nodered.org/u/shipra)\
**Post date:** [22 July 2020 12:54 UTC](https://discourse.nodered.org/t/how-to-read-the-state-of-ui-switch-in-node-red/30538/15 "2020-07-22T12:54:00Z")

</div>

Sir,i know you want me to know ,but according to what i have done is  
UI-Switch-----\>Switch(checked if contains DR1\_ON) then trriger my own message --\> change node(for my own messge)--\> MQTT Out

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [22 July 2020 13:03 UTC](https://discourse.nodered.org/t/how-to-read-the-state-of-ui-switch-in-node-red/30538/16 "2020-07-22T13:03:11Z")

</div>

And does it work? If so, congratulations you have figured out how to solve your problem.

---

<div class="post-metadata">

**Author:** ![shipra](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@shipra](https://discourse.nodered.org/u/shipra)\
**Post date:** [22 July 2020 13:09 UTC](https://discourse.nodered.org/t/how-to-read-the-state-of-ui-switch-in-node-red/30538/17 "2020-07-22T13:09:25Z")

</div>

Sir ,The half issue is solved but like i will explain in steps:  
Mqtt code  
1: in this code i have switch case for user like case1: if that ui switch is in real triggered (means Open )then publish message (my own mesg) to mqtt out node  
2: similarly for Close ui switch

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [22 July 2020 13:17 UTC](https://discourse.nodered.org/t/how-to-read-the-state-of-ui-switch-in-node-red/30538/18 "2020-07-22T13:17:05Z")

</div>

I'm sorry but I do not understand what you just said.

1 - If you still have an issue export your flow and attach it to a reply.  
2 - Then, please explain in more detail what your current issue is

Note: I will be going out for about 2 hours and will respond when I get back.

---

<div class="post-metadata">

**Author:** ![shipra](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@shipra](https://discourse.nodered.org/u/shipra)\
**Post date:** [22 July 2020 13:21 UTC](https://discourse.nodered.org/t/how-to-read-the-state-of-ui-switch-in-node-red/30538/19 "2020-07-22T13:21:27Z")

</div>

Sure Sir,  
I have 2 ui switches (open and close) ,  
I have a mqtt code in which i am entering one valid rfid person he will have priveldges to use that ui switches  
Now I have to send one user defined message to one topic throught mqtt out  
and that i am doing by switch case in my mqtt code.(That cases should only work/publish on topic when in real/live that rfid person has pushes that Switches(either open or close)  
Case1:publish user defined mesg on one topic(for open)  
Case2: similarly for close

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [22 July 2020 13:25 UTC](https://discourse.nodered.org/t/how-to-read-the-state-of-ui-switch-in-node-red/30538/20 "2020-07-22T13:25:20Z")

</div>

where is the export of your flow? (the first thing I asked for)

[Next page](https://discourse.nodered.org/t/how-to-read-the-state-of-ui-switch-in-node-red/30538.md?page=2)
