# Invert does not invert msg.payload from a switch

**URL:** <https://discourse.nodered.org/t/invert-does-not-invert-msg-payload-from-a-switch/3715>\
**Category:** General\
**Created:** [5 October 2018 14:48 UTC](https://discourse.nodered.org/t/invert-does-not-invert-msg-payload-from-a-switch/3715 "2018-10-05T14:48:23Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matthew](https://avatars.discourse-cdn.com/v4/letter/m/ed655f/32.png) [@Matthew](https://discourse.nodered.org/u/Matthew)\
**Post date:** [5 October 2018 14:48 UTC](https://discourse.nodered.org/t/invert-does-not-invert-msg-payload-from-a-switch/3715/1 "2018-10-05T14:48:23Z")

</div>

If I connect a dashboard switch to a boolean invert, no inversion takes place when I activate the switch. In fact the status of the invert remains as 'unknown' and there is no output in debug. If I use a boolean inject to the switch, msg.payload from teh inject passes through through the witch and the invert functions correctly.

Any ideas what is going on?

Thanks

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [5 October 2018 14:55 UTC](https://discourse.nodered.org/t/invert-does-not-invert-msg-payload-from-a-switch/3715/2 "2018-10-05T14:55:28Z")

</div>

what does debug direct on the switch report ?  
How do you have the switch configured ?

---

<div class="post-metadata">

**Author:** ![Matthew](https://avatars.discourse-cdn.com/v4/letter/m/ed655f/32.png) [@Matthew](https://discourse.nodered.org/u/Matthew)\
**Post date:** [5 October 2018 14:58 UTC](https://discourse.nodered.org/t/invert-does-not-invert-msg-payload-from-a-switch/3715/3 "2018-10-05T14:58:59Z")

</div>

Debug remains empty when I activate the switch and the status indicator which representes the output value of invert remains 'unknown'. The switch is configured to On payload: True, Off payload: 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:** [5 October 2018 15:03 UTC](https://discourse.nodered.org/t/invert-does-not-invert-msg-payload-from-a-switch/3715/4 "2018-10-05T15:03:47Z")

</div>

Are you sure that a debug on the output of the Switch (not the invert) remains empty when you click the switch?  
You say you have On payload True, but what type is that (string, boolean etc)?

---

<div class="post-metadata">

**Author:** ![Matthew](https://avatars.discourse-cdn.com/v4/letter/m/ed655f/32.png) [@Matthew](https://discourse.nodered.org/u/Matthew)\
**Post date:** [5 October 2018 15:05 UTC](https://discourse.nodered.org/t/invert-does-not-invert-msg-payload-from-a-switch/3715/5 "2018-10-05T15:05:34Z")

</div>

Apologies. On the switch, debug reports the correct values according to On (True) and Off (False).

---

<div class="post-metadata">

**Author:** ![Matthew](https://avatars.discourse-cdn.com/v4/letter/m/ed655f/32.png) [@Matthew](https://discourse.nodered.org/u/Matthew)\
**Post date:** [5 October 2018 15:06 UTC](https://discourse.nodered.org/t/invert-does-not-invert-msg-payload-from-a-switch/3715/6 "2018-10-05T15:06:32Z")

</div>

Switch paylaod type is 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:** [5 October 2018 15:17 UTC](https://discourse.nodered.org/t/invert-does-not-invert-msg-payload-from-a-switch/3715/7 "2018-10-05T15:17:42Z")

</div>

Export a flow consisting of the Switch, Invert and the Inject node that works and paste it here. Put a line containing three backtick characters before the flow and after it so it is correctly formatted here.

---

<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:** [5 October 2018 15:20 UTC](https://discourse.nodered.org/t/invert-does-not-invert-msg-payload-from-a-switch/3715/8 "2018-10-05T15:20:59Z")

</div>

Also tell us which invert node you are using. I guess you installed one of the node-red-contrib nodes or set of nodes, but which one?

---

<div class="post-metadata">

**Author:** ![Matthew](https://avatars.discourse-cdn.com/v4/letter/m/ed655f/32.png) [@Matthew](https://discourse.nodered.org/u/Matthew)\
**Post date:** [5 October 2018 15:36 UTC](https://discourse.nodered.org/t/invert-does-not-invert-msg-payload-from-a-switch/3715/9 "2018-10-05T15:36:46Z")

</div>

```auto
[{"id":"97f739d1.c6a63","type":"ui_switch","z":"3d366024.220ff8","name":"","label":"switch","group":"dfdb85a8.82471","order":0,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":480,"y":274,"wires":[["7a1eec6b.3dcedc"]]},{"id":"7a1eec6b.3dcedc","type":"Invert","z":"3d366024.220ff8","name":"Invert","x":680,"y":274,"wires":[["ea03ab2c.43401"]]},{"id":"ea03ab2c.43401","type":"debug","z":"3d366024.220ff8","name":"","active":true,"console":"false","complete":"false","x":898,"y":274,"wires":[]},{"id":"dfdb85a8.82471","type":"ui_group","z":"","name":"Default","tab":"5552dd2e.54054c","disp":true,"width":"6"},{"id":"5552dd2e.54054c","type":"ui_tab","z":"","name":"Home","icon":"dashboard"}]

```

Invert node is from node-red-contrib-boolean-logic 0.0.3

---

<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:** [5 October 2018 15:42 UTC](https://discourse.nodered.org/t/invert-does-not-invert-msg-payload-from-a-switch/3715/10 "2018-10-05T15:42:12Z")

</div>

You have not included the Inject node that does make the invert switch change

---

<div class="post-metadata">

**Author:** ![Matthew](https://avatars.discourse-cdn.com/v4/letter/m/ed655f/32.png) [@Matthew](https://discourse.nodered.org/u/Matthew)\
**Post date:** [5 October 2018 15:48 UTC](https://discourse.nodered.org/t/invert-does-not-invert-msg-payload-from-a-switch/3715/11 "2018-10-05T15:48:26Z")

</div>

Apologies again. With the inject nodes:\>

```auto
[{"id":"7edc9ef0.bebd18","type":"ui_switch","z":"ab3db175.f6be9","name":"","label":"switch","group":"dfdb85a8.82471","order":0,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":339,"y":362,"wires":[["1afca744.1c0421"]]},{"id":"1afca744.1c0421","type":"Invert","z":"ab3db175.f6be9","name":"Invert","x":539,"y":362,"wires":[["256867d7.873cf8"]]},{"id":"256867d7.873cf8","type":"debug","z":"ab3db175.f6be9","name":"","active":true,"console":"false","complete":"false","x":757,"y":362,"wires":[]},{"id":"5455b0e5.a9f35","type":"inject","z":"ab3db175.f6be9","name":"","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"x":148,"y":290,"wires":[["7edc9ef0.bebd18"]]},{"id":"b62c82e0.a0682","type":"inject","z":"ab3db175.f6be9","name":"","topic":"","payload":"false","payloadType":"bool","repeat":"","crontab":"","once":false,"x":84,"y":437,"wires":[["7edc9ef0.bebd18"]]},{"id":"dfdb85a8.82471","type":"ui_group","z":"","name":"Default","tab":"5552dd2e.54054c","disp":true,"width":"6"},{"id":"5552dd2e.54054c","type":"ui_tab","z":"","name":"Home","icon":"dashboard"}]

```

---

<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:** [5 October 2018 15:49 UTC](https://discourse.nodered.org/t/invert-does-not-invert-msg-payload-from-a-switch/3715/12 "2018-10-05T15:49:37Z")

</div>

I can see that it does not work. The issue seems to be that the invert node needs a topic specified in order to work. The Inject node defaults to an empty string but the Switch node defaults to no topic. Add a topic to the switch and it works. I think that is a bug in the Invert node.

---

<div class="post-metadata">

**Author:** ![Matthew](https://avatars.discourse-cdn.com/v4/letter/m/ed655f/32.png) [@Matthew](https://discourse.nodered.org/u/Matthew)\
**Post date:** [5 October 2018 15:53 UTC](https://discourse.nodered.org/t/invert-does-not-invert-msg-payload-from-a-switch/3715/13 "2018-10-05T15:53:38Z")

</div>

That's great. Thank you so much for your help (and patience).

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [5 October 2018 16:34 UTC](https://discourse.nodered.org/t/invert-does-not-invert-msg-payload-from-a-switch/3715/14 "2018-10-05T16:34:02Z")

</div>

please report the issue to the owner of that node. Thanks
