# Switch node is not working

**URL:** <https://discourse.nodered.org/t/switch-node-is-not-working/35569>\
**Category:** General\
**Created:** [8 November 2020 21:14 UTC](https://discourse.nodered.org/t/switch-node-is-not-working/35569 "2020-11-08T21:14:11Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![dangoodhead](https://avatars.discourse-cdn.com/v4/letter/d/b5a626/32.png) [@dangoodhead](https://discourse.nodered.org/u/dangoodhead)\
**Post date:** [8 November 2020 21:14 UTC](https://discourse.nodered.org/t/switch-node-is-not-working/35569/1 "2020-11-08T21:14:11Z")

</div>

I trying to get a very simple flow to work. It has a virtual alexa device which is connected at all times to my amazon account. I then have this going to a switch node with String ON and one with string OFF.  
These then link to a call service node from home assistant. This node is linked to a smart plug.

If i link virtual device directly to the call service node it works fine. plug comes on. Thats fine but i need to add a switch so i can also turn it off. If i add a debug to the end of the call service node and ask alexa to turn on device, it shows in the debug window. If i also have a debug on the ON leg of the Switch node i get no output. Its almost like the switch node is broken, yet i have replaced it a few times.

---

<div class="post-metadata">

**Author:** ![JGKK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jgkk/32/18515_2.png) [@JGKK](https://discourse.nodered.org/u/JGKK)\
**Post date:** [8 November 2020 21:18 UTC](https://discourse.nodered.org/t/switch-node-is-not-working/35569/2 "2020-11-08T21:18:35Z")

</div>

Hello,  
Can you show us a screenshot of the output you see in the debug tab when a debug node is directly connected to the virtual device and another one of your switch node settings? This would be really helpful to be able to understand your problem and find possible solutions.

Johannes

---

<div class="post-metadata">

**Author:** ![dangoodhead](https://avatars.discourse-cdn.com/v4/letter/d/b5a626/32.png) [@dangoodhead](https://discourse.nodered.org/u/dangoodhead)\
**Post date:** [8 November 2020 21:28 UTC](https://discourse.nodered.org/t/switch-node-is-not-working/35569/3 "2020-11-08T21:28:48Z")

</div>

Thanks for the quick reply. I cant show you any debug info that comes out the switch legs. It doesn't create any. Attached is some screen shots.

 ![flow](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/9/49167b15f7c77cf5e14b42db3a143b67d31f2da0.png) ![switch settings](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/d/fd1642d920ca756d0e37f5d6e6efecc61f1cc702.png)

---

<div class="post-metadata">

**Author:** ![dangoodhead](https://avatars.discourse-cdn.com/v4/letter/d/b5a626/32.png) [@dangoodhead](https://discourse.nodered.org/u/dangoodhead)\
**Post date:** [8 November 2020 21:29 UTC](https://discourse.nodered.org/t/switch-node-is-not-working/35569/4 "2020-11-08T21:29:45Z")

</div>

![virtual device debug](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/1/61e4b97b83082a69649403c90b591b7fe4dc68b3.png) ![virtual device settings](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/7/c7f9e88f761f2056dc6cce270ebbbd476004b83b.png)

---

<div class="post-metadata">

**Author:** ![dangoodhead](https://avatars.discourse-cdn.com/v4/letter/d/b5a626/32.png) [@dangoodhead](https://discourse.nodered.org/u/dangoodhead)\
**Post date:** [8 November 2020 21:32 UTC](https://discourse.nodered.org/t/switch-node-is-not-working/35569/5 "2020-11-08T21:32:24Z")

</div>

![plug settings](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/e/4e35e591d21c278e1619505ecb70cc3248b7b960.png)

---

<div class="post-metadata">

**Author:** ![dangoodhead](https://avatars.discourse-cdn.com/v4/letter/d/b5a626/32.png) [@dangoodhead](https://discourse.nodered.org/u/dangoodhead)\
**Post date:** [8 November 2020 21:33 UTC](https://discourse.nodered.org/t/switch-node-is-not-working/35569/6 "2020-11-08T21:33:29Z")

</div>

I know the link has been removed from switch to the plug devices. That was just for testing and debugging.

---

<div class="post-metadata">

**Author:** ![JGKK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jgkk/32/18515_2.png) [@JGKK](https://discourse.nodered.org/u/JGKK)\
**Post date:** [8 November 2020 21:46 UTC](https://discourse.nodered.org/t/switch-node-is-not-working/35569/7 "2020-11-08T21:46:59Z")

</div>

Your switch node is set up to check `msg.payload` for _ON_ or _OFF_ but if you look at what you are getting in the `msg.payload` its not a string but an object. This object includes a **powerState** property which has this information. So you will have to change your switch node to check for the _ON_ and _OFF_ strings in `msg.payload.powerState` instead for the check to work.

---

<div class="post-metadata">

**Author:** ![dangoodhead](https://avatars.discourse-cdn.com/v4/letter/d/b5a626/32.png) [@dangoodhead](https://discourse.nodered.org/u/dangoodhead)\
**Post date:** [8 November 2020 21:53 UTC](https://discourse.nodered.org/t/switch-node-is-not-working/35569/8 "2020-11-08T21:53:45Z")

</div>

> [@JGKK](#):
>
> yload.powerState

Forgive me, i'm very new to this. So is that changing then the property to the msg.payload.powerstate in the switch node? I don't need a chnage node?

---

<div class="post-metadata">

**Author:** ![dangoodhead](https://avatars.discourse-cdn.com/v4/letter/d/b5a626/32.png) [@dangoodhead](https://discourse.nodered.org/u/dangoodhead)\
**Post date:** [8 November 2020 21:57 UTC](https://discourse.nodered.org/t/switch-node-is-not-working/35569/9 "2020-11-08T21:57:04Z")

</div>

> [@JGKK](#):
>
> msg.payload.powerState

I just tried it and its working. Such a small thing and it worked. I been messing for hours on trying to work this out. Thanks do much.

---

<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:** [8 November 2020 22:07 UTC](https://discourse.nodered.org/t/switch-node-is-not-working/35569/10 "2020-11-08T22:07:29Z")

</div>

Have a read of the docs page Working with Messages, that should prove very helpful. Also, if you have not done so already, then watch right through the Node-red Essentials videos linked to the the docs. You will soon get back the hour or so spent doing that.

---

<div class="post-metadata">

**Author:** ![dangoodhead](https://avatars.discourse-cdn.com/v4/letter/d/b5a626/32.png) [@dangoodhead](https://discourse.nodered.org/u/dangoodhead)\
**Post date:** [8 November 2020 22:11 UTC](https://discourse.nodered.org/t/switch-node-is-not-working/35569/11 "2020-11-08T22:11:49Z")

</div>

Thanks colin. I'll do that. It will probably inspire lots of cool ideas for automatons. Trouble is i don't have many plugs, switches etc at the moment. I'm hoping to move house in 2021 and really going to go for it.

---

<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:** [22 November 2020 22:11 UTC](https://discourse.nodered.org/t/switch-node-is-not-working/35569/12 "2020-11-22T22:11:53Z")

</div>

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