# Noob with NR, converting HA Automation to NR

**URL:** <https://discourse.nodered.org/t/noob-with-nr-converting-ha-automation-to-nr/12249>\
**Category:** Dashboard\
**Created:** [15 June 2019 00:00 UTC](https://discourse.nodered.org/t/noob-with-nr-converting-ha-automation-to-nr/12249 "2019-06-15T00:00:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![monsieurlatte](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/monsieurlatte/32/9465_2.png) [@monsieurlatte](https://discourse.nodered.org/u/monsieurlatte)\
**Post date:** [15 June 2019 00:00 UTC](https://discourse.nodered.org/t/noob-with-nr-converting-ha-automation-to-nr/12249/1 "2019-06-15T00:00:04Z")

</div>

So I have a HA automation that turns on a couple of lights when I arrive home after dark, works great, except for when my wife is already asleep I dont want the bedroom light to come on. So I switched to NR however for some reason when my phone is home it keeps triggering like every minute or so. Anyone know why? I appreciate the help.

Figured it out. Here's working code

```auto
[{"id":"ba2d4342.44933","type":"tab","label":"JR-Arriving/Leaving Home","disabled":false,"info":""},{"id":"94a9dbcc.ae3948","type":"trigger-state","z":"ba2d4342.44933","name":"JR-Phone","server":"8f3bff2.2affc","entityid":"device_tracker.jr","entityidfiltertype":"exact","debugenabled":true,"constraints":[{"id":"8rovcvfy66t","targetType":"this_entity","targetValue":"","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"home"},{"id":"7umfemunnen","targetType":"this_entity","targetValue":"","propertyType":"previous_state","propertyValue":"old_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"not_home"}],"constraintsmustmatch":"all","outputs":2,"customoutputs":[],"outputinitially":true,"state_type":"str","x":72.00000762939453,"y":200.0000057220459,"wires":[["26aa2388.f5403c"],[]]},{"id":"1b585776.fe6199","type":"api-current-state","z":"ba2d4342.44933","name":"Kitchen Light Status Check","server":"8f3bff2.2affc","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"light.kitchen_lights","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":511.00000762939453,"y":154.0000114440918,"wires":[[],["1e1662aa.f70bdd"]]},{"id":"1e1662aa.f70bdd","type":"api-call-service","z":"ba2d4342.44933","name":"Turn On","server":"8f3bff2.2affc","service_domain":"light","service":"turn_on","data":"{\"entity_id\":\"light.kitchen_lights\",\"brightness_pct\":10}","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":517.0000190734863,"y":87.0000171661377,"wires":[[]]},{"id":"326f6a43.feeb06","type":"api-current-state","z":"ba2d4342.44933","name":"JR's Room Status Check (Noise Machine)","server":"8f3bff2.2affc","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"switch.jrs_noise_machine","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":513.9999771118164,"y":262.99999618530273,"wires":[[],["5a51a9d3.78d668"]]},{"id":"5a51a9d3.78d668","type":"api-call-service","z":"ba2d4342.44933","name":"Turn On Bedroom Light","server":"8f3bff2.2affc","service_domain":"light","service":"turn_on","data":"{\"entity_id\":\"light.jr_s_bedroom_light\",\"brightness_pct\":10}","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":522.0000457763672,"y":351.00000190734863,"wires":[[]]},{"id":"26aa2388.f5403c","type":"time-range-switch","z":"ba2d4342.44933","name":"","lat":"47.72252","lon":"-122.17864","startTime":"sunset","endTime":"sunrise","startOffset":"+20","endOffset":0,"x":247.51392364501953,"y":193.79863739013672,"wires":[["1b585776.fe6199","326f6a43.feeb06"],[]]},{"id":"d524a65b.ab92c8","type":"trigger-state","z":"ba2d4342.44933","name":"JR-Phone","server":"8f3bff2.2affc","entityid":"device_tracker.jr","entityidfiltertype":"exact","debugenabled":false,"constraints":[{"id":"ef3bfbngswh","targetType":"this_entity","targetValue":"","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"not_home"},{"id":"yc6gh9lydwc","targetType":"this_entity","targetValue":"","propertyType":"previous_state","propertyValue":"old_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"home"}],"constraintsmustmatch":"all","outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"str","x":91.52082824707031,"y":511.45140838623047,"wires":[["4fe763bb.317f6c","3b33af49.994bd"],[]]},{"id":"4fe763bb.317f6c","type":"api-call-service","z":"ba2d4342.44933","name":"Bedroom TV Turn Off","server":"8f3bff2.2affc","service_domain":"remote","service":"turn_off","data":"{\"entity_id\":\"remote.jr\"}","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":348.5173797607422,"y":463.37850189208984,"wires":[[]]},{"id":"3b33af49.994bd","type":"api-call-service","z":"ba2d4342.44933","name":"Bedroom Light Turn Off","server":"8f3bff2.2affc","service_domain":"light","service":"turn_off","data":"{\"entity_id\":\"light.jr_s_bedroom_light\"}","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":365.51390075683594,"y":522.3889083862305,"wires":[[]]},{"id":"8f3bff2.2affc","type":"server","z":"","name":"Home Assistant"}]

```

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [15 June 2019 10:04 UTC](https://discourse.nodered.org/t/noob-with-nr-converting-ha-automation-to-nr/12249/2 "2019-06-15T10:04:26Z")

</div>

Please wrap code in back-ticks or use the `</>` button in the editor to paste code otherwise it cannot be used.

---

<div class="post-metadata">

**Author:** ![SouthernLonghauler](https://avatars.discourse-cdn.com/v4/letter/s/d6d6ee/32.png) [@SouthernLonghauler](https://discourse.nodered.org/u/SouthernLonghauler)\
**Post date:** [29 January 2020 10:08 UTC](https://discourse.nodered.org/t/noob-with-nr-converting-ha-automation-to-nr/12249/3 "2020-01-29T10:08:52Z")

</div>

You might try the following, as it will only trigger the first time your phone state has changed and ONLY if the sun is down.

Remove the Sunrise-Sunset check and instead add a constraint to JR-Phone as follows:  
Entity ID: sun.sun  
Current State  
Is: (a/z) below\_horizon
