How to keep a service from running during a certain time period

I have a lamp that during the day I trigger to turn on by a motion sensor and light level and then turn off after 10 minutes of no motion. I also trigger the lamp to turn on at sunset and turn off at 1am, but I don’t want to lamp to turn off during that time. So my question is how do I keep the lamp from turning off. TIA

Here is my flow, I’m wanting to stop the Stoptimer during the time period of the Bigtimer.

Any ideas?

Just use a time range switch node between the motion detection and timer node to allow it to function outside the time range of the daily routines. Time range switch node will already be present in nodered or just take a look @ https://flows.nodered.org/node/node-red-contrib-time-range-switch .

1 Like

Thanks for your help, that is what I was looking for and it works great. I was trying different nodes and configurations but just didn’t see this node. I’m retired and trying to learn node-red. Node-Red seems easier to me than yaml.

node red is pretty much straight forward and if you find anything you need help with you always have both this and the node red community.

sheminasalam, do have any idea as to why the light level node isn’t working? It works one time and then wont work again even if the light level is below the setpoint.

It would be best if you can share the flow to analyze it. If exporting code is not familiar to you just follow these step. To share the flow, you should select the entire flow and then press CTL+E. Then the export node window will appear, the code in that window is the that of the flow. Click copy to clipboard tab at the bottom and share it. If there are any passwords in the flow please make sure you remove it from the code before sharing.

[{"id":"40023292.3ec94c","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"38bba1ec.290e0e","type":"api-call-service","z":"40023292.3ec94c","name":"Turn On Jeff Light","server":"4a63ddf5.8fd424","version":1,"debugenabled":true,"service_domain":"switch","service":"turn_on","entityId":"switch.jeff_light","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":990,"y":260,"wires":[[]]},{"id":"d1aad3c8.4f472","type":"bigtimer","z":"40023292.3ec94c","outtopic":"","outpayload1":"ON","outpayload2":"OFF","name":"Trigger Jeff & Turtle Light","comment":"","lat":"039.325159","lon":"-88.127590","starttime":"5004","endtime":"90","starttime2":0,"endtime2":0,"startoff":"-50","endoff":0,"startoff2":0,"endoff2":0,"offs":0,"outtext1":"","outtext2":"","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,"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":false,"atstart":false,"odd":false,"even":false,"x":130,"y":400,"wires":[["e385ab43.7629e8"],[],[]]},{"id":"e385ab43.7629e8","type":"switch","z":"40023292.3ec94c","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"ON","vt":"str"},{"t":"eq","v":"OFF","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":430,"y":400,"wires":[["62d37c09.668a14","38bba1ec.290e0e"],["dc99f138.5e14f","44b4db6.a677324"]]},{"id":"62d37c09.668a14","type":"api-call-service","z":"40023292.3ec94c","name":"Turn On Turtle Light","server":"4a63ddf5.8fd424","version":1,"debugenabled":true,"service_domain":"light","service":"turn_on","entityId":"light.turtle","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1000,"y":320,"wires":[[]]},{"id":"dc99f138.5e14f","type":"api-call-service","z":"40023292.3ec94c","name":"Turn Off Turtle Light","server":"4a63ddf5.8fd424","version":1,"debugenabled":true,"service_domain":"light","service":"turn_off","entityId":"light.turtle","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1000,"y":520,"wires":[[]]},{"id":"44b4db6.a677324","type":"api-call-service","z":"40023292.3ec94c","name":"Turn Off Jeff Light","server":"456659de.370498","version":1,"debugenabled":true,"service_domain":"switch","service":"turn_off","entityId":"switch.jeff_light","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":990,"y":460,"wires":[[]]},{"id":"e540e0dc.62ae9","type":"server-state-changed","z":"40023292.3ec94c","name":"Livingroom Motion Detection","server":"4a63ddf5.8fd424","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.livingroom_4_in_1_sensor_7","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,"x":140,"y":120,"wires":[["b9171d40.e80e8"],["2544066e.4aee1a"]]},{"id":"2544066e.4aee1a","type":"time-range-switch","z":"40023292.3ec94c","name":"","lat":"39.325159","lon":"-88.127590","startTime":"sunset","endTime":"01:30","startOffset":"-60","endOffset":0,"x":140,"y":260,"wires":[[],["47e328c6.cf43d8"]]},{"id":"47e328c6.cf43d8","type":"stoptimer","z":"40023292.3ec94c","duration":"10","units":"Minute","payloadtype":"num","payloadval":"0","name":"","x":400,"y":260,"wires":[[],["692d4181.ccc77"]]},{"id":"b9171d40.e80e8","type":"api-current-state","z":"40023292.3ec94c","name":"","server":"4a63ddf5.8fd424","version":1,"outputs":2,"halt_if":"22","halt_if_type":"num","halt_if_compare":"lte","override_topic":false,"entity_id":"sensor.livingroom_light_sen_9","state_type":"num","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":490,"y":120,"wires":[["9950dfd7.de94e"],[]]},{"id":"9950dfd7.de94e","type":"api-current-state","z":"40023292.3ec94c","name":"Is Jeff Light On","server":"4a63ddf5.8fd424","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"switch.jeff_light","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":580,"y":180,"wires":[[],["38bba1ec.290e0e"]]},{"id":"692d4181.ccc77","type":"api-current-state","z":"40023292.3ec94c","name":"Is Jeff Light Off","server":"4a63ddf5.8fd424","version":1,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"switch.jeff_light","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":400,"y":320,"wires":[[],["44b4db6.a677324"]]},{"id":"4a63ddf5.8fd424","type":"server","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true},{"id":"456659de.370498","type":"server","name":"Home Assistant","addon":true}]

The light level was at 18.5 which was less than the setpoint.

Instead of using a trigger-state node to check the light level, try using a current state node. It will be simpler. You can try this edit

[{"id":"e540e0dc.62ae9","type":"server-state-changed","z":"51045e07.bbf87","name":"Livingroom Motion Detection","server":"4a63ddf5.8fd424","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.livingroom_4_in_1_sensor_7","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,"x":240,"y":2880,"wires":[["74d211c0.2be67","6ff1de72.4784a"],["2544066e.4aee1a"]]},{"id":"2544066e.4aee1a","type":"time-range-switch","z":"51045e07.bbf87","name":"","lat":"39.325159","lon":"-88.127590","startTime":"sunset","endTime":"01:30","startOffset":"-50","endOffset":0,"x":480,"y":2920,"wires":[[],["47e328c6.cf43d8"]]},{"id":"74d211c0.2be67","type":"debug","z":"51045e07.bbf87","name":"Motion Detected","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":480,"y":2840,"wires":[]},{"id":"38bba1ec.290e0e","type":"api-call-service","z":"51045e07.bbf87","name":"Turn On Jeff Light","server":"4a63ddf5.8fd424","version":1,"debugenabled":true,"service_domain":"switch","service":"turn_on","entityId":"switch.jeff_light","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":950,"y":2880,"wires":[[]]},{"id":"1027dd9b.2aefa2","type":"debug","z":"51045e07.bbf87","name":"Motion Passed Thru","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":720,"y":2840,"wires":[]},{"id":"47e328c6.cf43d8","type":"stoptimer","z":"51045e07.bbf87","duration":"10","units":"Minute","payloadtype":"num","payloadval":"0","name":"","x":680,"y":2920,"wires":[["44b4db6.a677324"],[]]},{"id":"e385ab43.7629e8","type":"switch","z":"51045e07.bbf87","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"ON","vt":"str"},{"t":"eq","v":"OFF","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":710,"y":2980,"wires":[["62d37c09.668a14","38bba1ec.290e0e"],["dc99f138.5e14f","44b4db6.a677324"]]},{"id":"44b4db6.a677324","type":"api-call-service","z":"51045e07.bbf87","name":"Turn Off Jeff Light","server":"456659de.370498","version":1,"debugenabled":true,"service_domain":"switch","service":"turn_off","entityId":"switch.jeff_light","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":950,"y":2980,"wires":[[]]},{"id":"d1aad3c8.4f472","type":"bigtimer","z":"51045e07.bbf87","outtopic":"","outpayload1":"ON","outpayload2":"OFF","name":"Trigger Jeff & Turtle Light","comment":"","lat":"039.325159","lon":"-88.127590","starttime":"5004","endtime":"90","starttime2":0,"endtime2":0,"startoff":"-50","endoff":0,"startoff2":0,"endoff2":0,"offs":0,"outtext1":"","outtext2":"","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,"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":false,"atstart":false,"odd":false,"even":false,"x":250,"y":3000,"wires":[["e385ab43.7629e8"],[],[]]},{"id":"62d37c09.668a14","type":"api-call-service","z":"51045e07.bbf87","name":"Turn On Turtle Light","server":"4a63ddf5.8fd424","version":1,"debugenabled":true,"service_domain":"light","service":"turn_on","entityId":"light.turtle","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":960,"y":2920,"wires":[[]]},{"id":"dc99f138.5e14f","type":"api-call-service","z":"51045e07.bbf87","name":"Turn Off Turtle Light","server":"4a63ddf5.8fd424","version":1,"debugenabled":true,"service_domain":"light","service":"turn_off","entityId":"light.turtle","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":960,"y":3040,"wires":[[]]},{"id":"6ff1de72.4784a","type":"api-current-state","z":"51045e07.bbf87","name":"Living Room Light","server":"d177950.2a5aa68","version":1,"outputs":2,"halt_if":"22","halt_if_type":"num","halt_if_compare":"lte","override_topic":false,"entity_id":"sensor.livingroom_light_sen_9","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":490,"y":2880,"wires":[["1027dd9b.2aefa2","38bba1ec.290e0e"],[]]},{"id":"4a63ddf5.8fd424","type":"server","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true},{"id":"456659de.370498","type":"server","name":"Home Assistant","addon":true},{"id":"d177950.2a5aa68","type":"server","name":"Home Assistant","legacy":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}] 

Giving it a try right now. Thanks

Looks like that took care of it. Does the trigger-state only work if the value changes? That’s what it’s looking like to me.

I don’t have too much experience with trigger-state node. Mostly the other nodes are sufficient to get the job done.

The logic works great thanks for your help. Now I have another question. Lets say if someone turns the livingroom light on by voice command, is there a way to disable the call-service to turn it off if the motion sensor gets triggered?

What is the device you are using for voice commands-alexa/google home? Is this device integrated with HA? Also what kind of switches are you using?

google home and the switches are tuya

Is the google home integrated to HA or nodered? I believe that the tuya switches are running with the stock firmware and not tasmota… If you have integrated google home to HA or have the nora service running in node red we might have a work around for this.

my google home devices are showing up in the intergrations

yes. but are these showing up in the Google Cast integration? If this is the case we can only control the google home devices as media player i,e to play audio, tts etc and cannot control switches or devices in google home. We need other integrations such as, in your case you might be using the tuya integration in HA to connect HA to tuya devices…are you?

Yes, I’m using tuya integrations for HA and the google devices are showing up in Google Cast