# Sonoff T0 switch and nodered

**URL:** <https://discourse.nodered.org/t/sonoff-t0-switch-and-nodered/22654>\
**Category:** General\
**Created:** [5 March 2020 09:30 UTC](https://discourse.nodered.org/t/sonoff-t0-switch-and-nodered/22654 "2020-03-05T09:30:30Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![sniperxnl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sniperxnl/32/18250_2.png) [@sniperxnl](https://discourse.nodered.org/u/sniperxnl)\
**Post date:** [5 March 2020 09:30 UTC](https://discourse.nodered.org/t/sonoff-t0-switch-and-nodered/22654/1 "2020-03-05T09:30:30Z")

</div>

Guys,

my situation is, have sonoff T0 switch that activate/diactivate my main light, but i have also a led strip that is placed and activated by a sonoff switch, all flashed with tasmota and visible with mqtt

What i want, i normally only use my led strip above my bench, but when i go away i want to push the t0 switch to deactivate the sonoff ledstrips, but when i push and my main light is alreadt off it goes on, is there somthing possible?

---

<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:** [5 March 2020 10:00 UTC](https://discourse.nodered.org/t/sonoff-t0-switch-and-nodered/22654/2 "2020-03-05T10:00:39Z")

</div>

You need to provide more information.

What does your flow do?  
How are you seperating the msgs from the two switches?  
How are you keeping track of the status of each light?

It would be helpful - if your flow is not too large - to supply a copy of the flow ([read this first](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506))

---

<div class="post-metadata">

**Author:** ![sniperxnl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sniperxnl/32/18250_2.png) [@sniperxnl](https://discourse.nodered.org/u/sniperxnl)\
**Post date:** [5 March 2020 10:01 UTC](https://discourse.nodered.org/t/sonoff-t0-switch-and-nodered/22654/3 "2020-03-05T10:01:49Z")

</div>

```auto
[{"id":"eae0672e.14ad28","type":"tab","label":"Switches","disabled":false,"info":""},{"id":"7d1b3eaa.2492a","type":"switch","z":"eae0672e.14ad28","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"OFF","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":470,"y":120,"wires":[["832d9499.e8b088"]]},{"id":"fb213706.abe6b8","type":"mqtt in","z":"eae0672e.14ad28","name":"Main light","topic":"switch-1/stat/POWER","qos":"1","datatype":"auto","broker":"c1374cde.87a82","x":60,"y":120,"wires":[["7d1b3eaa.2492a"]]},{"id":"c694836a.36333","type":"mqtt in","z":"eae0672e.14ad28","name":"motionHK","topic":"zigbee2mqtt/0x680ae2fffe36ddc8","qos":"0","datatype":"json","broker":"c1374cde.87a82","x":60,"y":180,"wires":[["552dbd0e.09aba4"]]},{"id":"552dbd0e.09aba4","type":"change","z":"eae0672e.14ad28","name":"","rules":[{"t":"move","p":"payload.occupancy","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":270,"y":180,"wires":[["89522436.4d5508","9bd15be2.da99d8"]]},{"id":"89522436.4d5508","type":"switch","z":"eae0672e.14ad28","name":"","property":"payload","propertyType":"msg","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":470,"y":180,"wires":[["3ced05c1.e8f8ba"],["4b66b3fe.682afc"]]},{"id":"3ced05c1.e8f8ba","type":"change","z":"eae0672e.14ad28","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"ON","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":620,"y":160,"wires":[["832d9499.e8b088"]]},{"id":"4b66b3fe.682afc","type":"change","z":"eae0672e.14ad28","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"OFF","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":620,"y":200,"wires":[["d253db4b.de5968"]]},{"id":"d253db4b.de5968","type":"trigger","z":"eae0672e.14ad28","op1":"","op2":"OFF","op1type":"nul","op2type":"str","duration":"2","extend":false,"units":"min","reset":"ON","bytopic":"all","name":"","x":850,"y":220,"wires":[["1dcbc70a.dffa59","832d9499.e8b088","9bd15be2.da99d8"]]},{"id":"1dcbc70a.dffa59","type":"mqtt out","z":"eae0672e.14ad28","name":"","topic":"switch-1/cmnd/POWER","qos":"","retain":"","broker":"c1374cde.87a82","x":930,"y":160,"wires":[]},{"id":"832d9499.e8b088","type":"mqtt out","z":"eae0672e.14ad28","name":"Ledstrip Hobbykamer","topic":"switch_1/cmnd/POWER","qos":"2","retain":"true","broker":"c1374cde.87a82","x":920,"y":300,"wires":[]},{"id":"9bd15be2.da99d8","type":"debug","z":"eae0672e.14ad28","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":610,"y":280,"wires":[]},{"id":"c1374cde.87a82","type":"mqtt-broker","z":"","name":"Hassio","broker":"192.168.2.23","port":"1883","clientid":"Admin","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

```

---

<div class="post-metadata">

**Author:** ![sniperxnl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sniperxnl/32/18250_2.png) [@sniperxnl](https://discourse.nodered.org/u/sniperxnl)\
**Post date:** [5 March 2020 10:02 UTC](https://discourse.nodered.org/t/sonoff-t0-switch-and-nodered/22654/4 "2020-03-05T10:02:43Z")

</div>

Is this enough info, i am really new on Node red, so all is a learning curve

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [5 March 2020 10:06 UTC](https://discourse.nodered.org/t/sonoff-t0-switch-and-nodered/22654/5 "2020-03-05T10:06:20Z")

</div>

Your topic is not entirely clear to me, but if i understand correctly:

- 2 lights, 1 main light, 1 ledstrip
- when you leave, the led strip turns off but the the main light is toggled instead of OFF ?

---

<div class="post-metadata">

**Author:** ![sniperxnl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sniperxnl/32/18250_2.png) [@sniperxnl](https://discourse.nodered.org/u/sniperxnl)\
**Post date:** [5 March 2020 10:13 UTC](https://discourse.nodered.org/t/sonoff-t0-switch-and-nodered/22654/6 "2020-03-05T10:13:11Z")

</div>

Made a video showing what i mean  
[https://youtu.be/A8Kxj1DB6Oc](https://youtu.be/A8Kxj1DB6Oc)

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [5 March 2020 10:40 UTC](https://discourse.nodered.org/t/sonoff-t0-switch-and-nodered/22654/7 "2020-03-05T10:40:23Z")

</div>

I understand where you want to go, but looking at your flow:

![Screenshot 2020-03-05 at 11.37.06](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/b/1b0d1b7a8a6d5ae934b9afd676ee665c0913cf39.jpeg)

These mqtt nodes are both going to the same topic.  
What is the debug output of the Main Light when you press the button and when it is switched automatically.

For the occupancy part, you can reduce the flow by using this:

```auto
[{"id":"6e260d04.00bb5c","type":"mqtt in","z":"788a0bf5.383e84","name":"motionHK","topic":"zigbee2mqtt/0x680ae2fffe36ddc8","qos":"0","datatype":"json","broker":"37a13171.cc203e","x":84,"y":192,"wires":[["9efc0527.d0588"]]},{"id":"6b3610c9.564d","type":"trigger","z":"788a0bf5.383e84","op1":"","op2":"OFF","op1type":"nul","op2type":"str","duration":"2","extend":false,"units":"min","reset":"ON","bytopic":"all","name":"","x":406,"y":192,"wires":[["28eecb4f.35ebfc","e3758948.00fdf"]]},{"id":"28eecb4f.35ebfc","type":"mqtt out","z":"788a0bf5.383e84","name":"Ledstrip Hobbykamer","topic":"switch_1/cmnd/POWER","qos":"2","retain":"true","broker":"37a13171.cc203e","x":628,"y":192,"wires":[]},{"id":"9efc0527.d0588","type":"change","z":"788a0bf5.383e84","name":"occupancy","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.occupancy ? \"ON\" : \"OFF\"","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":238,"y":192,"wires":[["6b3610c9.564d"]]},{"id":"37a13171.cc203e","type":"mqtt-broker","z":"","name":"Hassio","broker":"192.168.2.23","port":"1883","clientid":"Admin","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

```

---

<div class="post-metadata">

**Author:** ![sniperxnl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sniperxnl/32/18250_2.png) [@sniperxnl](https://discourse.nodered.org/u/sniperxnl)\
**Post date:** [5 March 2020 10:44 UTC](https://discourse.nodered.org/t/sonoff-t0-switch-and-nodered/22654/8 "2020-03-05T10:44:43Z")

</div>

These node one is Switch\_1 and the other switch-1 🙂

---

<div class="post-metadata">

**Author:** ![sniperxnl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sniperxnl/32/18250_2.png) [@sniperxnl](https://discourse.nodered.org/u/sniperxnl)\
**Post date:** [5 March 2020 10:49 UTC](https://discourse.nodered.org/t/sonoff-t0-switch-and-nodered/22654/9 "2020-03-05T10:49:10Z")

</div>

when i manual push the switch on or off

```auto
5-3-2020 11:47:36node: 9bd15be2.da99d8
switch-1/stat/POWER : msg.payload : string[2]
"ON"

```

```auto
5-3-2020 11:47:40node: 9bd15be2.da99d8
switch-1/stat/POWER : msg.payload : string[3]
"OFF"

```

the main light is only going off by send a message dure no motion

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [5 March 2020 10:50 UTC](https://discourse.nodered.org/t/sonoff-t0-switch-and-nodered/22654/10 "2020-03-05T10:50:17Z")

</div>

Really clear.....what is switch 1 and what is switch 1 ?

---

<div class="post-metadata">

**Author:** ![sniperxnl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sniperxnl/32/18250_2.png) [@sniperxnl](https://discourse.nodered.org/u/sniperxnl)\
**Post date:** [5 March 2020 10:52 UTC](https://discourse.nodered.org/t/sonoff-t0-switch-and-nodered/22654/11 "2020-03-05T10:52:02Z")

</div>

switch-1/cmnd/POWER is mainlight  
switch\_1/cmnd/POWER is ledstrip

Btw your flow is awesome, that makes it so clean, many thanks

---

<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:** [5 March 2020 10:54 UTC](https://discourse.nodered.org/t/sonoff-t0-switch-and-nodered/22654/12 "2020-03-05T10:54:22Z")

</div>

So you have two switches that use the topics:  
switch-1/stat/POWER (main light switch)  
switch-1/cmnd/POWER (led switch)

What is the secong MQTT-in (motionHK) is that a motion detector?

You might want to change (if you can) the main topics of the two devices to 'main\_light' and 'wb\_leds' (wb = workbench) so instead of `switch-1/stat/POWER` you would get `main_light/stat/POWER` and instead of `switch-1/cmnd/POWER` you would use 'wb\_leds/cmnd/POWER'

---

<div class="post-metadata">

**Author:** ![sniperxnl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sniperxnl/32/18250_2.png) [@sniperxnl](https://discourse.nodered.org/u/sniperxnl)\
**Post date:** [5 March 2020 11:01 UTC](https://discourse.nodered.org/t/sonoff-t0-switch-and-nodered/22654/13 "2020-03-05T11:01:49Z")

</div>

> [@zenofmud](#):
>
> main\_light

thanks doing that now, i understand to start now to make it easy before upgrading my complete house

---

<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:** [5 March 2020 11:11 UTC](https://discourse.nodered.org/t/sonoff-t0-switch-and-nodered/22654/14 "2020-03-05T11:11:45Z")

</div>

> [@zenofmud](#):
>
> What is the secong MQTT-in (motionHK) is that a motion detector?

Helps to answer all questions...

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [5 March 2020 11:11 UTC](https://discourse.nodered.org/t/sonoff-t0-switch-and-nodered/22654/15 "2020-03-05T11:11:47Z")

</div>

So the switch-node that filters for "OFF" you don't really need.

I would recommend to give it descriptive names:

`hobby-kamer/main-switch/` (it is not the light itself, it controls lights)  
`hobby-kamer/led-strip-switch/`

etc.

side-note, you can actually send these commands from [tasmota directly with rules](https://tasmota.github.io/docs/#/Rules).

---

<div class="post-metadata">

**Author:** ![sniperxnl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sniperxnl/32/18250_2.png) [@sniperxnl](https://discourse.nodered.org/u/sniperxnl)\
**Post date:** [5 March 2020 11:14 UTC](https://discourse.nodered.org/t/sonoff-t0-switch-and-nodered/22654/16 "2020-03-05T11:14:52Z")

</div>

the motion sensor is a ikea one connected to zigbee2mqtt

---

<div class="post-metadata">

**Author:** ![sniperxnl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sniperxnl/32/18250_2.png) [@sniperxnl](https://discourse.nodered.org/u/sniperxnl)\
**Post date:** [5 March 2020 11:17 UTC](https://discourse.nodered.org/t/sonoff-t0-switch-and-nodered/22654/17 "2020-03-05T11:17:35Z")

</div>

Motion sensor sends this, true or false, and my mqtt only reacts on (ON or OFF) now the led strip is not reacting

```auto
zigbee2mqtt/0x680ae2fffe36ddc8 : msg.payload : Object
{ occupancy: true, linkquality: 120, update_available: false, requested_brightness_level: 76, requested_brightness_percent: 30 … }

```

---

<div class="post-metadata">

**Author:** ![sniperxnl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sniperxnl/32/18250_2.png) [@sniperxnl](https://discourse.nodered.org/u/sniperxnl)\
**Post date:** [5 March 2020 11:33 UTC](https://discourse.nodered.org/t/sonoff-t0-switch-and-nodered/22654/18 "2020-03-05T11:33:24Z")

</div>

So weird, changed the names in tasmota and also in the nodes, but now the led strip is not reacting in this flow, my google assist command flow activate the led strip

```auto
[{"id":"e99b366b.adc088","type":"change","z":"eae0672e.14ad28","name":"occupancy","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.occupancy ? \"ON\" : \"OFF\"","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":210,"y":220,"wires":[["5ee5229.75f54dc","9bd15be2.da99d8"]]}]

```

![tasmota](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/7/c7495157cfb61413a54cc6aec4100a69d18d8f64.jpeg)

---

<div class="post-metadata">

**Author:** ![sniperxnl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sniperxnl/32/18250_2.png) [@sniperxnl](https://discourse.nodered.org/u/sniperxnl)\
**Post date:** [5 March 2020 11:35 UTC](https://discourse.nodered.org/t/sonoff-t0-switch-and-nodered/22654/19 "2020-03-05T11:35:45Z")

</div>

When i do a test command works then Light goes on

 ![MQTT](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/6/a65a5e969be005a3095598cf2a9d02cd72444049.jpeg)

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [5 March 2020 11:39 UTC](https://discourse.nodered.org/t/sonoff-t0-switch-and-nodered/22654/20 "2020-03-05T11:39:30Z")

</div>

You need to start with connecting debug nodes (output: complete msg object) everywhere.

[Next page](https://discourse.nodered.org/t/sonoff-t0-switch-and-nodered/22654.md?page=2)
