# Simple question from a beginner

**URL:** https://discourse.nodered.org/t/simple-question-from-a-beginner/76785
**Category:** General
**Created:** [21 March 2023 16:02 UTC](https://discourse.nodered.org/t/simple-question-from-a-beginner/76785 "2023-03-21T16:02:33Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![sohnvonoff](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sohnvonoff/32/77783_2.png) [@sohnvonoff](https://discourse.nodered.org/u/sohnvonoff)
#### Post date: [21 March 2023 16:02 UTC](https://discourse.nodered.org/t/simple-question-from-a-beginner/76785/1 "2023-03-21T16:02:33Z")

</div>

I'm a node red beginner. I'm trying to solve what I think is a simple problem.  
An illumination sensor (MQTT) supplies the brightness as a value between 0 and 15000.  
The goal is a NODE with an output (true/false) which outputs true from a certain brightness value. switches back to false when the brightness value falls below.  
my attempt is:

```auto
[{"id":"e0c6a123.6cfe58","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"710896e58f65c071","type":"mqtt in","z":"e0c6a123.6cfe58","name":"bre_snsbx170_lux","topic":"/BRE-SnsBx170/STAT/Lux","qos":"1","datatype":"auto-detect","broker":"e314300a.e8a55","nl":false,"rap":true,"rh":0,"inputs":0,"x":130,"y":100,"wires":[["aafe50798cd70349"]]},{"id":"18e506ec766aa592","type":"debug","z":"e0c6a123.6cfe58","name":"IstHell","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":930,"y":100,"wires":[]},{"id":"435b8e162aa6632e","type":"inject","z":"e0c6a123.6cfe58","name":"Daylight-1k","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1000","payloadType":"num","x":160,"y":200,"wires":[["aafe50798cd70349"]]},{"id":"ae85673a31a3fa68","type":"debug","z":"e0c6a123.6cfe58","name":"debug 18","active":false,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":680,"y":220,"wires":[]},{"id":"0dd661bc63f89f66","type":"inject","z":"e0c6a123.6cfe58","name":"Daylight-2k","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"2000","payloadType":"num","x":131.48333740234375,"y":158.48333740234375,"wires":[["aafe50798cd70349"]]},{"id":"aafe50798cd70349","type":"switch","z":"e0c6a123.6cfe58","name":"","property":"payload","propertyType":"msg","rules":[{"t":"gt","v":"1500","vt":"str"},{"t":"lte","v":"1500","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":430,"y":120,"wires":[["7b0d2d7dc631bb54","ae85673a31a3fa68"],["7878c77ba3104cf6","ae85673a31a3fa68"]]},{"id":"7b0d2d7dc631bb54","type":"change","z":"e0c6a123.6cfe58","name":"Gr1500","rules":[{"t":"set","p":"payload","pt":"msg","to":"true","tot":"bool"},{"t":"set","p":"topic","pt":"msg","to":"Gr1500","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":640,"y":100,"wires":[["18e506ec766aa592"]]},{"id":"7878c77ba3104cf6","type":"change","z":"e0c6a123.6cfe58","name":"Kl1500","rules":[{"t":"set","p":"payload","pt":"msg","to":"true","tot":"bool"},{"t":"set","p":"topic","pt":"msg","to":"Kl1500","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":640,"y":140,"wires":[["a7164ec93382d121"]]},{"id":"a7164ec93382d121","type":"debug","z":"e0c6a123.6cfe58","name":"IstDunkel","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1000,"y":140,"wires":[]},{"id":"e314300a.e8a55","type":"mqtt-broker","name":"Server-Mqtt","broker":"192.168.10.136","port":"1883","clientid":"","autoConnect":true,"usetls":false,"protocolVersion":"3","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"userProps":"","sessionExpiry":""}]

```

ni node red it looks like this:

 ![NR](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/e/2ea48e0f5422be58e76a8790dc2f39fe0bb225da.jpeg)

the problem is the Change-Node never go to false. the true at the output is only ever updated.  
what am I doing wrong?

---

<div class="post-metadata">

### Author: ![Buckskin](https://avatars.discourse-cdn.com/v4/letter/b/b9e5f3/32.png) [@Buckskin](https://discourse.nodered.org/u/Buckskin)
#### Post date: [21 March 2023 16:07 UTC](https://discourse.nodered.org/t/simple-question-from-a-beginner/76785/2 "2023-03-21T16:07:40Z")

</div>

In the switch node change the selection options to numbers (0-9) rather than text (a-z)

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/9/d9125f4d5c4aa96b5ea14b5fbded380f66fe59b1.png)

---

<div class="post-metadata">

### Author: ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)
#### Post date: [21 March 2023 16:41 UTC](https://discourse.nodered.org/t/simple-question-from-a-beginner/76785/3 "2023-03-21T16:41:26Z")

</div>

Depending on what you are doing with the output, you may need some hysteresis.

Otherwise when the light level is very close to the threshold value it may keep switching between the light and dark outputs. So if you are driving a light for example you may find it keeps switching on and off rapidly.

An easy way to do that is to leave a "dead band" between the two values where no action is taken.

payload \> 1500 light  
payload \<= 1400 dark

Then anywhere in between does nothing.

---

<div class="post-metadata">

### Author: ![sohnvonoff](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sohnvonoff/32/77783_2.png) [@sohnvonoff](https://discourse.nodered.org/u/sohnvonoff)
#### Post date: [21 March 2023 17:11 UTC](https://discourse.nodered.org/t/simple-question-from-a-beginner/76785/4 "2023-03-21T17:11:34Z")

</div>

hallo Buckskin,  
Thanks very much,  
I adjusted it, this doesn't change the problem with the two change nodes, they both remain on true.

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [21 March 2023 17:23 UTC](https://discourse.nodered.org/t/simple-question-from-a-beginner/76785/5 "2023-03-21T17:23:04Z")

</div>

Neither of your change nodes sets msg.payload to false.

---

<div class="post-metadata">

### Author: ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)
#### Post date: [21 March 2023 17:58 UTC](https://discourse.nodered.org/t/simple-question-from-a-beginner/76785/6 "2023-03-21T17:58:43Z")

</div>

Give this a try

```auto
[{"id":"710896e58f65c071","type":"mqtt in","z":"e0c6a123.6cfe58","name":"bre_snsbx170_lux","topic":"/BRE-SnsBx170/STAT/Lux","qos":"1","datatype":"auto-detect","broker":"e314300a.e8a55","nl":false,"rap":true,"rh":0,"inputs":0,"x":105,"y":105,"wires":[["aafe50798cd70349"]]},{"id":"18e506ec766aa592","type":"debug","z":"e0c6a123.6cfe58","name":"IstHell","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":910,"y":135,"wires":[]},{"id":"435b8e162aa6632e","type":"inject","z":"e0c6a123.6cfe58","name":"Daylight-1400","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1400","payloadType":"num","x":145,"y":210,"wires":[["aafe50798cd70349"]]},{"id":"ae85673a31a3fa68","type":"debug","z":"e0c6a123.6cfe58","name":"debug 18","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":680,"y":220,"wires":[]},{"id":"0dd661bc63f89f66","type":"inject","z":"e0c6a123.6cfe58","name":"Daylight-1500","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1500","payloadType":"num","x":141.48333740234375,"y":158.48333740234375,"wires":[["aafe50798cd70349"]]},{"id":"aafe50798cd70349","type":"switch","z":"e0c6a123.6cfe58","name":"","property":"payload","propertyType":"msg","rules":[{"t":"gte","v":"1500","vt":"str"},{"t":"lte","v":"1400","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":430,"y":120,"wires":[["7b0d2d7dc631bb54","ae85673a31a3fa68"],["7878c77ba3104cf6","ae85673a31a3fa68"]]},{"id":"7b0d2d7dc631bb54","type":"change","z":"e0c6a123.6cfe58","name":"Gr1500","rules":[{"t":"set","p":"payload","pt":"msg","to":"true","tot":"bool"},{"t":"set","p":"topic","pt":"msg","to":"Gr1500","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":675,"y":105,"wires":[["18e506ec766aa592"]]},{"id":"7878c77ba3104cf6","type":"change","z":"e0c6a123.6cfe58","name":"Kl1500","rules":[{"t":"set","p":"payload","pt":"msg","to":"false","tot":"bool"},{"t":"set","p":"topic","pt":"msg","to":"Kl1400","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":675,"y":150,"wires":[["18e506ec766aa592"]]},{"id":"e314300a.e8a55","type":"mqtt-broker","name":"Server-Mqtt","broker":"192.168.10.136","port":"1883","clientid":"","autoConnect":true,"usetls":false,"protocolVersion":"3","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"userProps":"","sessionExpiry":""}]

```

---

<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: [20 May 2023 17:58 UTC](https://discourse.nodered.org/t/simple-question-from-a-beginner/76785/7 "2023-05-20T17:58:45Z")

</div>

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