Help converting from HA automation to Node Red

Good morning everyone. The HA automation is working just fine, no issues at all i am just moving everything to Node Red.

I am trying to convert the below HA automation to Node Red. The part that i am not able to make work is the condition that the light switch MUST have been off for 1 second before it can run again. I can not for the life of me figure out how to add that condition in a Node Red flow. Any suggestions/help would be greatly appreciated! If i didnt provide enough information i apologize and i can provide anything you might need just let me know.

- id: '1590600465824'
  alias: Kitchen Light ON With Motion
  description: ''
  - entity_id: binary_sensor.presence_9
    platform: state
    to: 'on'
  - condition: device
    device_id: ac4944e272d746ca9dfe3fbab818241f
    domain: switch
    entity_id: switch.kitchen_light
      hours: 0
      minutes: 0
      seconds: 1
    type: is_off
  - after: 06:00
    before: '20:00'
    condition: time
  - data: {}
    entity_id: switch.kitchen_light
    service: switch.turn_on

There’s a node RED section of the forum FYI, this probably belongs there since its not about HA configuration but Node RED.

Also although this type of condition can be done in Node RED, it’s definitely simpler to do in HA. Just something to think about. I love Node RED but there are some things its better at then HA and some things HA is better at then Node RED.

Anyway for the solution I did a write up that explains exactly how to write that condition here. In your case the constraint would be on last_changed and the condition would be <= $fromMillis($millis() - 1000)). This would ensure that the condition was only true if the entity’s state had changed to the state you want it in at least one second ago.

I am so sorry about posting in the wrong section. I will move this right away.

Secondly, thank so much for the guidance. I agree that some things are better to do in HA over Node Red. It has now become a challenge lol. I spend hours trying to make it work and just couldn’t do it. Now i just want to make it work to make myself feel better.

Yes, this type of condition is not as straightforward in NodeRed. However, in your example I dont see the benefit of this condition. Can you please explain?
Whats the benefit of checking if the light has been off for 1sec?
Why not just check if the light is off?
What exactly are you trying to achieve as your endgoal?

I need the pause from on->off-> On because our kitchen lighting system has a night light feature. The feature activates by toggling the switch on/of/on within 2 seconds. The problem is when I build the flow in node red there are certain situations where the lights will turn off and at that perfect time someone walks back in the kitchen and the lights turn on resulting in the night lights turning on instead of the regular lights. It doesn’t happen all the time (the timing has to be just right) but it does happen at least once a day. This is really annoying.

Understood. I like this problem. It gets you thinking. There are probably again several different ways to do this. As Mike mentioned, you can simply check for the last_called attribute.

You can also try it with the one I made below:

[{"id":"220817d0.2dbbe8","type":"server-state-changed","z":"dc7bdb4e.f7fc88","name":"Motion","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.presence_9","entityidfiltertype":"substring","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"x":50,"y":520,"wires":[["8ee5f546.7043d8"]]},{"id":"96adb102.e4aa7","type":"time-range-switch","z":"dc7bdb4e.f7fc88","name":"","startTime":"06:00","endTime":"20:00","startOffset":"","endOffset":"","x":810,"y":440,"wires":[["c864ac28.5559b"],[]]},{"id":"d9619db7.95dd5","type":"switch","z":"dc7bdb4e.f7fc88","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":470,"y":520,"wires":[["4918c64d.a000d8"],["73c0af93.51203"]]},{"id":"c864ac28.5559b","type":"api-call-service","z":"dc7bdb4e.f7fc88","name":"Turn On","version":1,"debugenabled":false,"service_domain":"switch","service":"turn_on","entityId":"switch.kitchen_light","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":980,"y":440,"wires":[[]]},{"id":"e0e9712e.87612","type":"template","z":"dc7bdb4e.f7fc88","name":"cancel","field":"payload","fieldType":"msg","format":"handlebars","syntax":"plain","template":"cancel","output":"str","x":790,"y":520,"wires":[["5a4bf388.d0da4c"]],"inputLabels":["on"],"outputLabels":["stop"]},{"id":"5a4bf388.d0da4c","type":"mytimeout","z":"dc7bdb4e.f7fc88","name":"30sec","outtopic":"","outsafe":" ","outwarning":"","outunsafe":"off","warning":"","timer":"30","debug":false,"ndebug":false,"ignoreCase":false,"repeat":false,"again":false,"x":910,"y":600,"wires":[["13b633ee.52643c"],[]]},{"id":"4918c64d.a000d8","type":"api-current-state","z":"dc7bdb4e.f7fc88","name":"Light On?","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":true,"entity_id":"switch.kitchen_light","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":640,"y":440,"wires":[["e0e9712e.87612"],["96adb102.e4aa7"]]},{"id":"687a5a68.d1a824","type":"comment","z":"dc7bdb4e.f7fc88","name":"Delay for turn off","info":"","x":940,"y":560,"wires":[]},{"id":"73c0af93.51203","type":"api-current-state","z":"dc7bdb4e.f7fc88","name":"Light On?","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":true,"entity_id":"switch.kitchen_light","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":640,"y":600,"wires":[["5a4bf388.d0da4c"],[]]},{"id":"13b633ee.52643c","type":"switch","z":"dc7bdb4e.f7fc88","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":1090,"y":600,"wires":[["4c15254b.8e449c"]]},{"id":"4c15254b.8e449c","type":"api-call-service","z":"dc7bdb4e.f7fc88","name":"Turn Off","version":1,"debugenabled":false,"service_domain":"switch","service":"turn_off","entityId":"switch.kitchen_light","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1260,"y":600,"wires":[["8ee5f546.7043d8"]]},{"id":"781c6dd9.c442b4","type":"comment","z":"dc7bdb4e.f7fc88","name":"Cancel if Motion is detected during turn off delay","info":"","x":920,"y":480,"wires":[]},{"id":"8ee5f546.7043d8","type":"delay","z":"dc7bdb4e.f7fc88","name":"","pauseType":"rate","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":270,"y":520,"wires":[["d9619db7.95dd5"]]}]

This one is untested, but it should work. The idea is to have a rate limiter in there that is triggered at the same time as the light turns off. Therefore you will have an automatic 1sec delay in case there is motion discovered in this “perfect timing case”.

Furthermore, my assumption is that you also want to turn off the light if no motion was discovered for some time (30sec) in my flow.
NOTE: I’m using a custom node called “mytimeout” but you can also replace it with the stoptimer. I just prefer using the mytimeout node.

Anyway… its probably easier to help you after you post your current flow that you are unhappy with.

I agree, this has become more of a challenge than anything. Like i said, it is working just fine with HA Automations but i want to make this work in NR now. I really appreciate you taking the time to help with this. I will go through your flow and see how it works today. I will update you on what it does and how it works out… Again, i really appreciate the help!