# 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:** 2

<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:54 UTC](https://discourse.nodered.org/t/sonoff-t0-switch-and-nodered/22654/21 "2020-03-05T11:54:47Z")

</div>

Like this?

 ![debug](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/b/3bf71f2ee03b4e7c5492b03ebc48d83fa9df80e3.jpeg)

OKay it will switch with no motion the ledstrip to OFF, but with motion it is not going ON

---

<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 12:02 UTC](https://discourse.nodered.org/t/sonoff-t0-switch-and-nodered/22654/22 "2020-03-05T12:02:04Z")

</div>

This is the msg when it see movement, only ledstrip stays off

```auto
5-3-2020 13:01:18node: 9bd15be2.da99d8
zigbee2mqtt/0x680ae2fffe36ddc8 : msg : Object
{ topic: "zigbee2mqtt/0x680ae2fffe36ddc8", payload: object, qos: 0, retain: false, _msgid: "ff0ca4af.fd64c8" }
5-3-2020 13:01:18node: 9bd15be2.da99d8
zigbee2mqtt/0x680ae2fffe36ddc8 : msg : Object
{ topic: "zigbee2mqtt/0x680ae2fffe36ddc8", payload: "ON", qos: 0, retain: false, _msgid: "ff0ca4af.fd64c8" }

```

---

<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 12:08 UTC](https://discourse.nodered.org/t/sonoff-t0-switch-and-nodered/22654/23 "2020-03-05T12:08:23Z")

</div>

put a seperate debug on each node and name the debug nodes...makes it easier to see which node is sending what

see how in first `debug` the payload is aqn object? If you cliick the crows in the debug output, it will expand the oupput and show what is in payload.

---

<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 12:09 UTC](https://discourse.nodered.org/t/sonoff-t0-switch-and-nodered/22654/24 "2020-03-05T12:09:37Z")

</div>

i am a step futher now, when i remove the trigger 1 min. then the motion works and activate the lamp and without motion the lamp goes off. so the trigger part goes wrong.

Will name the debug nodes

---

<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 12:13 UTC](https://discourse.nodered.org/t/sonoff-t0-switch-and-nodered/22654/25 "2020-03-05T12:13:32Z")

</div>

![trigger](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/1/e1ae6674a8800833ef322dd9d18c9b554decb04b.jpeg)

there is no message coming from the trigger at all

---

<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 12:19 UTC](https://discourse.nodered.org/t/sonoff-t0-switch-and-nodered/22654/26 "2020-03-05T12:19:07Z")

</div>

Expand the object output as we cannot see it. you can copy the output and paste it between 3 tickmarks, like:

```  
output  
```

---

<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 12:19 UTC](https://discourse.nodered.org/t/sonoff-t0-switch-and-nodered/22654/27 "2020-03-05T12:19:49Z")

</div>

okay trigger output works after 1 min, then it decative the led lamp.

But when it sees motion when the light is off, then the led strips stays off  
 ![trigger](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/4/f4f998151c8617dd736a8ea5cdab48c5563f9f8d.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 12:23 UTC](https://discourse.nodered.org/t/sonoff-t0-switch-and-nodered/22654/28 "2020-03-05T12:23:26Z")

</div>

here is a video showing it

---

<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 12:27 UTC](https://discourse.nodered.org/t/sonoff-t0-switch-and-nodered/22654/29 "2020-03-05T12:27:27Z")

</div>

![Screen Shot 2020-03-05 at 7.26.05 AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/0/30083dcd9c6fac2aa26516d04327c4abf06cd5ad.png)

then click the triangle next to `payload` and provide a copy of the flow as it now is.

---

<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 12:29 UTC](https://discourse.nodered.org/t/sonoff-t0-switch-and-nodered/22654/30 "2020-03-05T12:29:59Z")

</div>

Post your flow.

---

<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 12:36 UTC](https://discourse.nodered.org/t/sonoff-t0-switch-and-nodered/22654/31 "2020-03-05T12:36:32Z")

</div>

```auto
[{"id":"eae0672e.14ad28","type":"tab","label":"Switches","disabled":false,"info":""},{"id":"9bd15be2.da99d8","type":"debug","z":"eae0672e.14ad28","name":"Motion output","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":160,"y":300,"wires":[]},{"id":"1fe1c1f.acc1c3e","type":"mqtt in","z":"eae0672e.14ad28","name":"motionHK","topic":"zigbee2mqtt/0x680ae2fffe36ddc8","qos":"0","datatype":"json","broker":"c1374cde.87a82","x":60,"y":200,"wires":[["e99b366b.adc088","9bd15be2.da99d8"]]},{"id":"5ee5229.75f54dc","type":"trigger","z":"eae0672e.14ad28","op1":"","op2":"OFF","op1type":"nul","op2type":"str","duration":"1","extend":false,"units":"min","reset":"ON","bytopic":"all","name":"","x":390,"y":200,"wires":[["d9bea7bb.841858","6e4d8204.bf361c"]]},{"id":"d9bea7bb.841858","type":"mqtt out","z":"eae0672e.14ad28","name":"Ledstrip Hobbykamer","topic":"wb_leds/cmnd/POWER","qos":"2","retain":"true","broker":"c1374cde.87a82","x":604,"y":200,"wires":[]},{"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":200,"wires":[["5ee5229.75f54dc","6bbe2d40.789b64"]]},{"id":"6bbe2d40.789b64","type":"debug","z":"eae0672e.14ad28","name":"occupancy output","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":390,"y":300,"wires":[]},{"id":"6e4d8204.bf361c","type":"debug","z":"eae0672e.14ad28","name":"trigger output","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":610,"y":300,"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:** ![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 12:38 UTC](https://discourse.nodered.org/t/sonoff-t0-switch-and-nodered/22654/32 "2020-03-05T12:38:39Z")

</div>

The trigger node receives a message, does nothing for 1 minute and then sends OFF.  
Reset is done when ON is received.

Nothing will happen.

---

<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 12:40 UTC](https://discourse.nodered.org/t/sonoff-t0-switch-and-nodered/22654/33 "2020-03-05T12:40:38Z")

</div>

yeah but i how can i get the light on when i move. what i told in the start post i am total NOOB atm

---

<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 12:44 UTC](https://discourse.nodered.org/t/sonoff-t0-switch-and-nodered/22654/34 "2020-03-05T12:44:11Z")

</div>

Before i post a flow:

You want the light to go on when there is motion detected and stay on for 1 minute correct ?  
The motion sensor only ouputs "true" when there is movement correct ? (there is no false)

---

<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 12:45 UTC](https://discourse.nodered.org/t/sonoff-t0-switch-and-nodered/22654/35 "2020-03-05T12:45:42Z")

</div>

correct, and that is not working.  
What i showed in the video  
Motion is detected and led stays off. what do i need to add to get the led strip on. and when there is no motion after 1 minut or what is set the strip goes off

---

<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 12:46 UTC](https://discourse.nodered.org/t/sonoff-t0-switch-and-nodered/22654/36 "2020-03-05T12:46:25Z")

</div>

Ok then it is much simpler:

```auto
[{"id":"387379cb.b4d1f6","type":"mqtt in","z":"e0655590.95e07","name":"motionHK","topic":"zigbee2mqtt/0x680ae2fffe36ddc8","qos":"0","datatype":"json","broker":"48a8cabf.0c8d34","x":84,"y":144,"wires":[["118e3215.bb2206","8aea0148.ebb3a8"]]},{"id":"8aea0148.ebb3a8","type":"trigger","z":"e0655590.95e07","op1":"ON","op2":"OFF","op1type":"str","op2type":"str","duration":"2","extend":true,"units":"min","reset":"","bytopic":"all","name":"","x":262,"y":144,"wires":[["12c82796.71798","cf56003d.2d9298"]]},{"id":"12c82796.71798","type":"mqtt out","z":"e0655590.95e07","name":"Ledstrip Hobbykamer","topic":"wb_leds/cmnd/POWER","qos":"2","retain":"true","broker":"48a8cabf.0c8d34","x":484,"y":144,"wires":[]},{"id":"48a8cabf.0c8d34","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 13:18 UTC](https://discourse.nodered.org/t/sonoff-t0-switch-and-nodered/22654/37 "2020-03-05T13:18:53Z")

</div>

> [@bakman2](#):
>
> [{"id":"387379cb.b4d1f6","type":"mqtt in","z":"e0655590.95e07","name":"motionHK","topic":"zigbee2mqtt/0x680ae2fffe36ddc8","qos":"0","datatype":"json","broker":"48a8cabf.0c8d34","x":84,"y":144,"wires":[["118e3215.bb2206","8aea0148.ebb3a8"]]},{"id":"8aea0148.ebb3a8","type":"trigger","z":"e0655590.95e07","op1":"ON","op2":"OFF","op1type":"str","op2type":"str","duration":"2","extend":true,"units":"min","reset":"","bytopic":"all","name":"","x":262,"y":144,"wires":[["12c82796.71798","cf56003d.2d9298"]]},{"id":"12c82796.71798","type":"mqtt out","z":"e0655590.95e07","name":"Ledstrip Hobbykamer","topic":"wb\_leds/cmnd/POWER","qos":"2","retain":"true","broker":"48a8cabf.0c8d34","x":484,"y":144,"wires":},{"id":"48a8cabf.0c8d34","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":""}]

thanks that works

---

<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 13:22 UTC](https://discourse.nodered.org/t/sonoff-t0-switch-and-nodered/22654/38 "2020-03-05T13:22:20Z")

</div>

My main quastion is then still unanswerd.  
but i think that is not possible.

But is this idear possible

When i push the T0 switch from main light, and it is between 6-7am then only the led strip goes on, and after and bedore 6-7am also the main light goes on. but when there is no movement then all lights go off.

---

<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 13:28 UTC](https://discourse.nodered.org/t/sonoff-t0-switch-and-nodered/22654/39 "2020-03-05T13:28:11Z")

</div>

> My main quastion is then still unanswerd.

What is your "main" question ?

> When i push the T0 switch from main light, and it is between 6-7am then only the led strip goes on, and after and bedore 6-7am also the main light goes on. but when there is no movement then all lights go off.

Yes that is simple, go to the hamburger menu (right top) -\> manage palette -\> install tab, search "node-red-contrib-time-range-switch", install. Now you can route messages based on the time.

---

<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 13:49 UTC](https://discourse.nodered.org/t/sonoff-t0-switch-and-nodered/22654/40 "2020-03-05T13:49:25Z")

</div>

> [@bakman2](#):
>
> node-red-contrib-time-range-switch

i usee mqtt in but when i push on the T0 sonoff switch in my room, it goes on always.  
That T0 works also without connecton  
[https://www.itead.cc/sonoff-tx-series-wifi-smart-wall-switches.html](https://www.itead.cc/sonoff-tx-series-wifi-smart-wall-switches.html)

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

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