# Note-Red dont work like i want it to

**URL:** <https://discourse.nodered.org/t/note-red-dont-work-like-i-want-it-to/55489>\
**Category:** General\
**Created:** [20 December 2021 16:52 UTC](https://discourse.nodered.org/t/note-red-dont-work-like-i-want-it-to/55489 "2021-12-20T16:52:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bluescreentt](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bluescreentt/32/52541_2.png) [@bluescreentt](https://discourse.nodered.org/u/bluescreentt)\
**Post date:** [20 December 2021 16:52 UTC](https://discourse.nodered.org/t/note-red-dont-work-like-i-want-it-to/55489/1 "2021-12-20T16:52:17Z")

</div>

Hi

so after my last post

> [@Motion, timers and lights / getting started](https://discourse.nodered.org/t/motion-timers-and-lights-getting-started/55112/1):
>
> Hi I am using Node-Red on Home Assistant. I am new to Node-Red and Home Assistant lets take an example i have a Sonoff motion sensor when activated it triggers a Sonoff basic switch that turns on the lamp on the night stand. when the motionsensor resets the lamp turns of. easy!! but i am restricted to the 90 seconds that is the timeout for the sensor I have build the sequense so that it only works in a preset timerange. if i want to have the lights turn on by auto from 18:30 - 20:30 i …

I have tried many different approaches but i keedp getting stuck.

I am struggling with the Sonoff motion sensor and a light automation.

I have made this and it works. yes i know it might not be 100% but it works

```auto
[{"id":"3f3cec186c0b1595","type":"tab","label":"Kitchen","disabled":false,"info":"","env":[]},{"id":"540caf488341a7b4","type":"server-state-changed","z":"3f3cec186c0b1595","name":"Motion kitchen","server":"aa22a8c9.f573b8","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.so_ms_05_kit_ias_zone","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":110,"y":140,"wires":[["2bcf78ec6b574780"],["7c185bafc699cfef"]]},{"id":"2bcf78ec6b574780","type":"api-call-service","z":"3f3cec186c0b1595","name":"Turn Counter Lights on","server":"aa22a8c9.f573b8","version":3,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.gl_bel_01_kit_level_light_color_on_off, light.gl_bel_02_kit_level_light_color_on_off","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":500,"y":60,"wires":[[]]},{"id":"7c185bafc699cfef","type":"api-call-service","z":"3f3cec186c0b1595","name":"Turn counter lights off","server":"aa22a8c9.f573b8","version":3,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.gl_bel_01_kit_level_light_color_on_off, light.gl_bel_02_kit_level_light_color_on_off","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":440,"y":140,"wires":[[]]},{"id":"266a00af3af6d139","type":"time-range-switch","z":"3f3cec186c0b1595","name":"goldenHourEnd - sunriseEnd","lat":"","lon":"","startTime":"goldenHourEnd","endTime":"sunriseEnd","startOffset":0,"endOffset":0,"x":340,"y":400,"wires":[["b79954720591c332"],["405440a2151e00a0"]]},{"id":"b79954720591c332","type":"api-call-service","z":"3f3cec186c0b1595","name":"Turn Star on","server":"aa22a8c9.f573b8","version":3,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.star_kitch_01_on_off","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":590,"y":340,"wires":[[]]},{"id":"405440a2151e00a0","type":"api-call-service","z":"3f3cec186c0b1595","name":"Turn Star off","server":"aa22a8c9.f573b8","version":3,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.star_kitch_01_on_off","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":590,"y":400,"wires":[[]]},{"id":"04cab988dcb9dcf6","type":"bigtimer","z":"3f3cec186c0b1595","outtopic":"","outpayload1":"on","outpayload2":"off","name":"Big Timer","comment":"","lat":0,"lon":0,"starttime":"840","endtime":"1439","starttime2":0,"endtime2":0,"startoff":0,"endoff":0,"startoff2":0,"endoff2":0,"offs":0,"outtext1":"on","outtext2":"off","timeout":1440,"sun":true,"mon":true,"tue":true,"wed":true,"thu":true,"fri":true,"sat":true,"jan":true,"feb":true,"mar":true,"apr":true,"may":true,"jun":true,"jul":true,"aug":true,"sep":true,"oct":true,"nov":true,"dec":true,"day1":0,"month1":0,"day2":0,"month2":0,"day3":0,"month3":0,"day4":0,"month4":0,"day5":0,"month5":0,"day6":0,"month6":0,"day7":0,"month7":0,"day8":0,"month8":0,"day9":0,"month9":0,"day10":0,"month10":0,"day11":0,"month11":0,"day12":0,"month12":0,"d1":0,"w1":0,"d2":0,"w2":0,"d3":0,"w3":0,"d4":0,"w4":0,"d5":0,"w5":0,"d6":0,"w6":0,"xday1":0,"xmonth1":0,"xday2":0,"xmonth2":0,"xday3":0,"xmonth3":0,"xday4":0,"xmonth4":0,"xday5":0,"xmonth5":0,"xday6":0,"xmonth6":0,"xday7":0,"xmonth7":0,"xday8":0,"xmonth8":0,"xday9":0,"xmonth9":0,"xday10":0,"xmonth10":0,"xday11":0,"xmonth11":0,"xday12":0,"xmonth12":0,"xd1":0,"xw1":0,"xd2":0,"xw2":0,"xd3":0,"xw3":0,"xd4":0,"xw4":0,"xd5":0,"xw5":0,"xd6":0,"xw6":0,"suspend":false,"random":false,"randon1":false,"randoff1":false,"randon2":false,"randoff2":false,"repeat":true,"atstart":true,"odd":false,"even":false,"x":120,"y":420,"wires":[["266a00af3af6d139"],[],[]]},{"id":"aa22a8c9.f573b8","type":"server","name":"Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30}]

```

i am guessing it works because there is a timeout build in to the sensor of 90 sec. and this timeout is enough to not "disco light"

i have also done this one (based on the same idea)

```auto
[{"id":"c7338da316b5f946","type":"tab","label":"Ninja","disabled":false,"info":"","env":[]},{"id":"9f4352aa720e58a6","type":"time-range-switch","z":"c7338da316b5f946","name":"20:00 - 08:00","lat":"","lon":"","startTime":"20:00","endTime":"08:00","startOffset":"","endOffset":"","x":330,"y":80,"wires":[["ec1405aaacc61cf2"],[]]},{"id":"bf9063278512bbc8","type":"server-state-changed","z":"c7338da316b5f946","name":"Motion Ninja","server":"aa22a8c9.f573b8","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.so_ms_03_nin_ias_zone","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":110,"y":100,"wires":[["9f4352aa720e58a6","d98dccce3a7ccec1"],["8f64dcfa84cd285d"]]},{"id":"ec1405aaacc61cf2","type":"api-call-service","z":"c7338da316b5f946","name":"Turn Unicorn on","server":"aa22a8c9.f573b8","version":3,"debugenabled":false,"service_domain":"switch","service":"turn_on","entityId":"switch.ninjaunic","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":700,"y":80,"wires":[[]]},{"id":"1145a68514215cbf","type":"api-call-service","z":"c7338da316b5f946","name":"Turn Unicorn off","server":"aa22a8c9.f573b8","version":3,"debugenabled":false,"service_domain":"switch","service":"turn_off","entityId":"switch.ninjaunic","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":860,"y":180,"wires":[[]]},{"id":"8f64dcfa84cd285d","type":"time-range-switch","z":"c7338da316b5f946","name":"20:00 - 08:00","lat":"","lon":"","startTime":"20:00","endTime":"08:00","startOffset":"","endOffset":"","x":330,"y":140,"wires":[["d98dccce3a7ccec1"],[]]},{"id":"934b114d3c1d89df","type":"time-range-switch","z":"c7338da316b5f946","name":"18:30 - 19:59","lat":"","lon":"","startTime":"18:30","endTime":"19:59","startOffset":"","endOffset":"","x":290,"y":280,"wires":[["ec1405aaacc61cf2"],["d98dccce3a7ccec1"]]},{"id":"a6cc9ad74538e155","type":"bigtimer","z":"c7338da316b5f946","outtopic":"","outpayload1":"on","outpayload2":"off","name":"Unicorn on timer","comment":"","lat":"51.025","lon":"-1.4","starttime":"1080","endtime":"1200","starttime2":0,"endtime2":0,"startoff":0,"endoff":0,"startoff2":0,"endoff2":0,"offs":0,"outtext1":"on","outtext2":"off","timeout":1440,"sun":true,"mon":true,"tue":true,"wed":true,"thu":true,"fri":true,"sat":true,"jan":true,"feb":true,"mar":true,"apr":true,"may":true,"jun":true,"jul":true,"aug":true,"sep":true,"oct":true,"nov":true,"dec":true,"day1":0,"month1":0,"day2":0,"month2":0,"day3":0,"month3":0,"day4":0,"month4":0,"day5":0,"month5":0,"day6":0,"month6":0,"day7":0,"month7":0,"day8":0,"month8":0,"day9":0,"month9":0,"day10":0,"month10":0,"day11":0,"month11":0,"day12":0,"month12":0,"d1":0,"w1":0,"d2":0,"w2":0,"d3":0,"w3":0,"d4":0,"w4":0,"d5":0,"w5":0,"d6":0,"w6":0,"xday1":0,"xmonth1":0,"xday2":0,"xmonth2":0,"xday3":0,"xmonth3":0,"xday4":0,"xmonth4":0,"xday5":0,"xmonth5":0,"xday6":0,"xmonth6":0,"xday7":0,"xmonth7":0,"xday8":0,"xmonth8":0,"xday9":0,"xmonth9":0,"xday10":0,"xmonth10":0,"xday11":0,"xmonth11":0,"xday12":0,"xmonth12":0,"xd1":0,"xw1":0,"xd2":0,"xw2":0,"xd3":0,"xw3":0,"xd4":0,"xw4":0,"xd5":0,"xw5":0,"xd6":0,"xw6":0,"suspend":false,"random":false,"randon1":false,"randoff1":false,"randon2":false,"randoff2":false,"repeat":true,"atstart":true,"odd":false,"even":false,"x":100,"y":280,"wires":[["934b114d3c1d89df"],[],[]]},{"id":"d98dccce3a7ccec1","type":"delay","z":"c7338da316b5f946","name":"","pauseType":"delay","timeout":"30","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":590,"y":200,"wires":[["1145a68514215cbf"]]},{"id":"aa22a8c9.f573b8","type":"server","name":"Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30}]

```

so my thoughts here was that the sensor should activate a sonoff basic between a set time.

this works when seperate/alone

then i wanted to also add a scheduler to the same switch to turn on at a set time (outside the motion time)  
this also works when seperate/alone.

What is not working is when i combine them.  
when the motion sensor acctivates the switch, the timer turns it off again almost imediatly.  
i have tried to prevent this by adding a delay, but it just makes it worse ☹ because now the delay gives me a new problem. the motionsensor have to timeout before it will turn on again. everything gets unresponsive for the time that is left on the timeout.

I tried in the Kitchen flow to add a delay but the delays really screws it up for me.  
when i only have a motionsensor and a call service the lightsstays on for 90 sec and then turns off and back on again with the slightest movement.  
when adding a delay of 5 minutes the lights turn off and do not acctivate again until the motionsensor times out  
my thought was that as long as there is movement the sensor "should" reset the delay, but NO ☹

anyone have used the Sonoff Motion sensors and knows how to work with them ?

why cant i get the flow with schedule and motion to work ?  
what am i missing ?

Anyone ?

---

<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:** [18 February 2022 16:52 UTC](https://discourse.nodered.org/t/note-red-dont-work-like-i-want-it-to/55489/2 "2022-02-18T16:52:56Z")

</div>

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