# Lightbulb color based on sensor input

**URL:** <https://discourse.nodered.org/t/lightbulb-color-based-on-sensor-input/88271>\
**Category:** General\
**Created:** [26 May 2024 03:35 UTC](https://discourse.nodered.org/t/lightbulb-color-based-on-sensor-input/88271 "2024-05-26T03:35:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![MerMarky](https://avatars.discourse-cdn.com/v4/letter/m/4af34b/32.png) [@MerMarky](https://discourse.nodered.org/u/MerMarky)\
**Post date:** [26 May 2024 03:35 UTC](https://discourse.nodered.org/t/lightbulb-color-based-on-sensor-input/88271/1 "2024-05-26T03:35:48Z")

</div>

I use function to generate a value for data field for my lightbulb node but it appears that it is not populated correctly. Any ideas?

**Function code:**

```auto
msg.payload = parseFloat(msg.payload); // Convert payload to a number

if (msg.payload < 2) {
  msg.payload = {
    "brightness": 255, // Full brightness (0-255)
    "rgb_color": [0, 0, 255] // Blue color
  };
} else {
  msg.payload = {
    "brightness": 255,
    "rgb_color": [255, 0, 0] // Red color
  };
}

return msg;

```

 ![Screenshot 2024-05-25 at 22.24.58](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/9/f932d08c0ef619af20be5a2cbba6dc2ec0efaf15.png)

**-------**  
Error: Call-service error. extra keys not allowed @ data['0']

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [26 May 2024 07:22 UTC](https://discourse.nodered.org/t/lightbulb-color-based-on-sensor-input/88271/2 "2024-05-26T07:22:02Z")

</div>

Hi and welcome.  
Not a HA user, but i remember that mustache does not allow object replacement.  
Why not select `msg.` and then just type` payload` in the data field.

---

<div class="post-metadata">

**Author:** ![MerMarky](https://avatars.discourse-cdn.com/v4/letter/m/4af34b/32.png) [@MerMarky](https://discourse.nodered.org/u/MerMarky)\
**Post date:** [26 May 2024 15:26 UTC](https://discourse.nodered.org/t/lightbulb-color-based-on-sensor-input/88271/3 "2024-05-26T15:26:16Z")

</div>

replacing {{{payload}}} in data field in Light node with payload only gives "invalid properties: -data" error.

I guess the question is how to properly populate the field with the message from the Function node which is:  
{"brightness":255,"rgb\_color":[255,0,0]}

When I enter this result manually in the Light node - it works, so the message seems to be in correct format.

---

<div class="post-metadata">

**Author:** ![MerMarky](https://avatars.discourse-cdn.com/v4/letter/m/4af34b/32.png) [@MerMarky](https://discourse.nodered.org/u/MerMarky)\
**Post date:** [26 May 2024 15:34 UTC](https://discourse.nodered.org/t/lightbulb-color-based-on-sensor-input/88271/4 "2024-05-26T15:34:01Z")

</div>

I think you were correct. Once I changed data to "payload" (it was JSON) previously - it worked.

THANK YOU SO MUCH!!!!!!!

---

<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:** [24 August 2024 15:34 UTC](https://discourse.nodered.org/t/lightbulb-color-based-on-sensor-input/88271/5 "2024-08-24T15:34:32Z")

</div>

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