# Function node light questions

**URL:** <https://discourse.nodered.org/t/function-node-light-questions/30816>\
**Category:** General\
**Created:** [28 July 2020 08:13 UTC](https://discourse.nodered.org/t/function-node-light-questions/30816 "2020-07-28T08:13:49Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Higgis](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/higgis/32/26469_2.png) [@Higgis](https://discourse.nodered.org/u/Higgis)\
**Post date:** [28 July 2020 08:13 UTC](https://discourse.nodered.org/t/function-node-light-questions/30816/1 "2020-07-28T08:13:50Z")

</div>

Would need some help. I have a lamp I try to be able to change color and brightness.

If I write {"brightness": 150} in the data field, it changes brightness, but how do you write such in function node has tried to read me to this but does not get wiser.

Also tried chanche node but even there I did not get it to work.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [28 July 2020 08:30 UTC](https://discourse.nodered.org/t/function-node-light-questions/30816/2 "2020-07-28T08:30:06Z")

</div>

Hi,

It is good to see you are playing with Node-Red.

Have a read of some of the threads on how to share nodes:

[How to share](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506/2)

> If I write {"brightness": 150} in the data filed

I'm guessing that is the node for the bulb?

Could you maybe say what this node is called?

How confident are you to do basic things in Node-Red?

eg:

Drag an `inject` node into the _EDIT_ area.  
Also a `change` node.

Connect the two together and connect the output of the `change` node to the input of the node that controls the bulb.

Open the `change` node and set it like this:

 ![Screenshot from 2020-07-28 18-25-08](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/1/d18e8ac17e898d23c2a67e9d93782afdd42a88b7.png)

Now, duplicate the `inject` and `change` node and connect the `change` node's output to the bulb's input (this will be two connections going in).

Edit the second `change` node with a different value.  
Make it very different to the first one. It won't be very good to have values like: 150, 151.  
Try 50 and 200.

Deploy the flow.

Press one of the `inject` node _button_ (the little tab on the left of the node.)

See if the bulb changes brightness.

If it doesn't don't panic.

Repeat it with the other `inject` node.

This is because the bulb may be already at that value.

So pressing the second `inject` node will (should) change the bulb's brightness.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [28 July 2020 08:39 UTC](https://discourse.nodered.org/t/function-node-light-questions/30816/3 "2020-07-28T08:39:23Z")

</div>

> [@Higgis](#):
>
> If I write {"brightness": 150} in the data field

Tell us the full name of that node please (probably node-red-contrib-something). Without that we cannot know exactly what you have to do.

---

<div class="post-metadata">

**Author:** ![Higgis](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/higgis/32/26469_2.png) [@Higgis](https://discourse.nodered.org/u/Higgis)\
**Post date:** [29 July 2020 19:55 UTC](https://discourse.nodered.org/t/function-node-light-questions/30816/4 "2020-07-29T19:55:39Z")

</div>

Have tested a few different chanche node but get none to work. If I check debug, it seems to send my value on britness like something else.

```auto
[{"id":"e5f36ec.bf4639","type":"tab","label":"Flow 17","disabled":false,"info":""},{"id":"4ada4ecd.9704f","type":"api-call-service","z":"e5f36ec.bf4639","name":"","server":"b2b8610a.26012","version":1,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.ikea_of_sweden_tradfri_bulb_e14_cws_opal_600lm_6c97befe_level_light_color_on_off","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":630,"y":440,"wires":[[]]},{"id":"fab8737c.7f99a","type":"inject","z":"e5f36ec.bf4639","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":440,"wires":[["4ada4ecd.9704f"]]},{"id":"ec6d42b8.31e0c","type":"debug","z":"e5f36ec.bf4639","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":830,"y":160,"wires":[]},{"id":"cdcf79b6.66b6c8","type":"debug","z":"e5f36ec.bf4639","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":850,"y":420,"wires":[]},{"id":"d71cdbed.a6c328","type":"api-call-service","z":"e5f36ec.bf4639","name":"","server":"b2b8610a.26012","version":1,"debugenabled":true,"service_domain":"light","service":"turn_on","entityId":"light.ikea_of_sweden_tradfri_bulb_e14_cws_opal_600lm_6c97befe_level_light_color_on_off","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":650,"y":240,"wires":[[]]},{"id":"5de1068f.077208","type":"inject","z":"e5f36ec.bf4639","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":240,"wires":[["fce6da4.33bf228"]]},{"id":"76d5a3f8.d9a23c","type":"api-call-service","z":"e5f36ec.bf4639","name":"","server":"b2b8610a.26012","version":1,"debugenabled":true,"service_domain":"light","service":"turn_on","entityId":"light.ikea_of_sweden_tradfri_bulb_e14_cws_opal_600lm_6c97befe_level_light_color_on_off","data":"{\"brightness\":10}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":590,"y":160,"wires":[["ec6d42b8.31e0c"]]},{"id":"6abb2a83.b479b4","type":"inject","z":"e5f36ec.bf4639","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":160,"wires":[["76d5a3f8.d9a23c"]]},{"id":"b57d62f.674b1a","type":"comment","z":"e5f36ec.bf4639","name":"working britness","info":"","x":320,"y":160,"wires":[]},{"id":"9126ebe2.032888","type":"function","z":"e5f36ec.bf4639","name":"","func":"msg.payload={\n \n\"data.brightness\":250,\n\n};\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":380,"y":360,"wires":[["cdcf79b6.66b6c8","d71cdbed.a6c328"]]},{"id":"4f492fab.2175c","type":"change","z":"e5f36ec.bf4639","name":"","rules":[{"t":"set","p":"data.brightness","pt":"msg","to":"255","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":330,"y":300,"wires":[["d71cdbed.a6c328","ff90fe85.8877d"]]},{"id":"fce6da4.33bf228","type":"change","z":"e5f36ec.bf4639","name":"","rules":[{"t":"set","p":"brightness","pt":"msg","to":"200","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":370,"y":240,"wires":[["d71cdbed.a6c328","b4d95759.304a58"]]},{"id":"f0e6c8d3.b089a8","type":"inject","z":"e5f36ec.bf4639","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":300,"wires":[["4f492fab.2175c"]]},{"id":"a422dc83.3e7d4","type":"inject","z":"e5f36ec.bf4639","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":360,"wires":[["9126ebe2.032888"]]},{"id":"ff90fe85.8877d","type":"debug","z":"e5f36ec.bf4639","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":830,"y":360,"wires":[]},{"id":"b4d95759.304a58","type":"debug","z":"e5f36ec.bf4639","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":830,"y":300,"wires":[]},{"id":"b2b8610a.26012","type":"server","z":"","name":"Home Assistant BOR","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

```

[edited to format correctly with ``` on a seperate line before and ``` on a line after the paste]

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [29 July 2020 20:01 UTC](https://discourse.nodered.org/t/function-node-light-questions/30816/5 "2020-07-29T20:01:22Z")

</div>

Please see [this post](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506) for how to share your flow, and try again. The flow you posted is not importable. However, as I said before, we need to know the name of the node you are using (node-red-contrib-something problable), assuming you are using a contrib node, so we can look it up to see what format it needs the data to be in.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [29 July 2020 21:46 UTC](https://discourse.nodered.org/t/function-node-light-questions/30816/6 "2020-07-29T21:46:58Z")

</div>

You need to edit the `debug` nodes.

 ![Screenshot from 2020-07-30 07-43-16](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/e/3ef02fc5c523cf9429ef496e4c8ee5eeab1d9fc3.png)

Then you will see what the payloads are.

By default the `debug` node only shows `msg.payload`, as that is usually what is used/needed.

As you (we) are using `msg.brightness` it won't be shown.

Now:  
You say that isn't working.  
Ok. Not sure why, but all we can do is try.

I don't have those nodes installed and am not going to only to help you.

> [@Higgis](#):
>
> If I write {"brightness": 150} in the data field, it changes brightness, but how do you write such in function node has tried to read me to this but does not get wiser.

Can you take a screen shot of what you are doing at this stage?  
I am missing something in what you said, and a screen shot may save a lot of time.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [30 July 2020 08:04 UTC](https://discourse.nodered.org/t/function-node-light-questions/30816/7 "2020-07-30T08:04:56Z")

</div>

Without knowing which node he is using we don't know where the brightness should be in the message.

---

<div class="post-metadata">

**Author:** ![Higgis](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/higgis/32/26469_2.png) [@Higgis](https://discourse.nodered.org/u/Higgis)\
**Post date:** [30 July 2020 12:07 UTC](https://discourse.nodered.org/t/function-node-light-questions/30816/8 "2020-07-30T12:07:09Z")

</div>

Thank you for the help I took some pictures, If I turn on the lamp with the help of the first picture and I get this information in debug node.

 ![IMG_20200730_135610039](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/a/ca39e2111d348a23fdbab948ba16be1e2f2e71e1.jpeg) ![IMG_20200730_135011594](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/e/1e447bfba7a1437ff09bceccf165389718351b33.jpeg)

But when I run it true the chanche node, I get this in the debug

 ![IMG_20200730_135032849](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/2/725cc38893c86d1796702766a29f0dc39da89567.jpeg)

this is the chanche node

 ![IMG_20200730_135043510](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/8/2858ea9d2a49170357f24382ae8d41a495bb6319.jpeg)

Have also tried to write data.brightness in the chanche node.  
Does not seem like the lamp takes into account what I send into it.  
I try with big chanche in tje numbers so i will se if it chanche.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [30 July 2020 14:54 UTC](https://discourse.nodered.org/t/function-node-light-questions/30816/9 "2020-07-30T14:54:25Z")

</div>

Ah, Home Assistant, you should have said (and put it in the title). I don't know anything about HA.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [30 July 2020 21:38 UTC](https://discourse.nodered.org/t/function-node-light-questions/30816/10 "2020-07-30T21:38:33Z")

</div>

Just a quick thing:

Usually just to the right of the `F12` key there is a button on the keyboard called: "Print screen"  
Pressing this takes a screen shot - usually. Depending on which O/S you are running.

These pictures then can be added to the post by drag and drop or by clicking on the "attach" button at the top which looks like a big up pointing arrow.

I'm torn between what I should do.

How much computer work experience do you have?  
A lot; pretty good; some; not too bad; learning.

What O/S do you run (more for the screen shot problem)

How much experience do you have with Node-Red?  
(as above)

---

<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:** [28 September 2020 21:38 UTC](https://discourse.nodered.org/t/function-node-light-questions/30816/11 "2020-09-28T21:38:35Z")

</div>

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