# Can't get my head around how to add a value to an brightness attribute

**URL:** <https://discourse.nodered.org/t/cant-get-my-head-around-how-to-add-a-value-to-an-brightness-attribute/60081>\
**Category:** General\
**Tags:** function-node\
**Created:** [19 March 2022 17:02 UTC](https://discourse.nodered.org/t/cant-get-my-head-around-how-to-add-a-value-to-an-brightness-attribute/60081 "2022-03-19T17:02:13Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![adrieg](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/adrieg/32/47897_2.png) [@adrieg](https://discourse.nodered.org/u/adrieg)\
**Post date:** [19 March 2022 17:02 UTC](https://discourse.nodered.org/t/cant-get-my-head-around-how-to-add-a-value-to-an-brightness-attribute/60081/1 "2022-03-19T17:02:13Z")

</div>

I have an attribute called brightness and I just want to add some value to it say + 50.  
Now I can not figure out to get the brightness value and send it back with the new value.

Hope someone can help.

```auto
[{"id":"2207ca62eaa5238c","type":"inject","z":"1c5c34058085e784","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":140,"y":1560,"wires":[["ad8b96aa54b62730"]]},{"id":"0b13b99a1c3a2849","type":"function","z":"1c5c34058085e784","name":"","func":"r = Number;\nr = msg.data.attributes.brightness;\nmsg.data.attributes.brightness = r + 50\n\nreturn r;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":560,"y":1560,"wires":[["a04e59c3cb0274ed"]]},{"id":"a04e59c3cb0274ed","type":"debug","z":"1c5c34058085e784","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"attributes.brightness","targetType":"msg","statusVal":"","statusType":"auto","x":790,"y":1560,"wires":[]},{"id":"ad8b96aa54b62730","type":"api-current-state","z":"1c5c34058085e784","name":"","server":"a465afba.fb6ee","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"light.lcl001","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"data.attributes.brightness","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":350,"y":1560,"wires":[["0b13b99a1c3a2849"]]},{"id":"a465afba.fb6ee","type":"server","name":"Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30"}]

```

---

<div class="post-metadata">

**Author:** ![mickym2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mickym2/32/36128_2.png) [@mickym2](https://discourse.nodered.org/u/mickym2)\
**Post date:** [19 March 2022 17:26 UTC](https://discourse.nodered.org/t/cant-get-my-head-around-how-to-add-a-value-to-an-brightness-attribute/60081/2 "2022-03-19T17:26:42Z")

</div>

You have to return a msg. object and not a number like r. If your msg . Object contains an a property msg.data.attributes.brightness then just return the whole msg. object.

```auto
msg.data.attributes.brightness += 50;

return msg;

```

---

<div class="post-metadata">

**Author:** ![adrieg](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/adrieg/32/47897_2.png) [@adrieg](https://discourse.nodered.org/u/adrieg)\
**Post date:** [19 March 2022 17:40 UTC](https://discourse.nodered.org/t/cant-get-my-head-around-how-to-add-a-value-to-an-brightness-attribute/60081/3 "2022-03-19T17:40:11Z")

</div>

Thank you mickym2.

I have adjusted as you say and now I get the following output and that's not the brightness with added 50.

{"brightness":"[object Object]50"}

```auto
[{"id":"2207ca62eaa5238c","type":"inject","z":"1c5c34058085e784","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":140,"y":1560,"wires":[["ad8b96aa54b62730"]]},{"id":"0b13b99a1c3a2849","type":"function","z":"1c5c34058085e784","name":"","func":"msg.data.attributes.brightness += 50;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":560,"y":1560,"wires":[["a04e59c3cb0274ed"]]},{"id":"a04e59c3cb0274ed","type":"debug","z":"1c5c34058085e784","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":730,"y":1560,"wires":[]},{"id":"ad8b96aa54b62730","type":"api-current-state","z":"1c5c34058085e784","name":"","server":"a465afba.fb6ee","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"light.lcl001","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"data.attributes.brightness","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":350,"y":1560,"wires":[["0b13b99a1c3a2849"]]},{"id":"a465afba.fb6ee","type":"server","name":"Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30"}]
type or paste code here

```

---

<div class="post-metadata">

**Author:** ![mickym2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mickym2/32/36128_2.png) [@mickym2](https://discourse.nodered.org/u/mickym2)\
**Post date:** [19 March 2022 19:42 UTC](https://discourse.nodered.org/t/cant-get-my-head-around-how-to-add-a-value-to-an-brightness-attribute/60081/4 "2022-03-19T19:42:53Z")

</div>

The problem is have not the node. So it would be helpful to post the output of the state. So please post the output of the debug node and the whole object.

---

<div class="post-metadata">

**Author:** ![adrieg](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/adrieg/32/47897_2.png) [@adrieg](https://discourse.nodered.org/u/adrieg)\
**Post date:** [19 March 2022 20:35 UTC](https://discourse.nodered.org/t/cant-get-my-head-around-how-to-add-a-value-to-an-brightness-attribute/60081/5 "2022-03-19T20:35:28Z")

</div>

Just found the solution.

```auto
[{"id":"f7a2a579792a8a54","type":"function","z":"8cb1e594b3a81f5c","name":"","func":"msg.payload += 35;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":700,"y":120,"wires":[["2d22a28cfa0fa6cc"]]},{"id":"5593fb4bd8184782","type":"inject","z":"8cb1e594b3a81f5c","name":"","props":[],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":170,"y":120,"wires":[["39217c44d8e0cc14"]]},{"id":"39217c44d8e0cc14","type":"api-current-state","z":"8cb1e594b3a81f5c","name":"","server":"a465afba.fb6ee","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"light.lcl001","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"$entity().attributes.brightness","valueType":"jsonata"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":470,"y":120,"wires":[["f7a2a579792a8a54"]]},{"id":"2d22a28cfa0fa6cc","type":"api-call-service","z":"8cb1e594b3a81f5c","name":"Philips on","server":"a465afba.fb6ee","version":5,"debugenabled":false,"domain":"light","service":"turn_on","areaId":[],"deviceId":[],"entityId":["light.lcl001"],"data":"{\"brightness\": \"{{payload}}\"}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":940,"y":120,"wires":[[]]},{"id":"a465afba.fb6ee","type":"server","name":"Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30"}]

```

---

<div class="post-metadata">

**Author:** ![adrieg](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/adrieg/32/47897_2.png) [@adrieg](https://discourse.nodered.org/u/adrieg)\
**Post date:** [19 March 2022 20:36 UTC](https://discourse.nodered.org/t/cant-get-my-head-around-how-to-add-a-value-to-an-brightness-attribute/60081/6 "2022-03-19T20:36:11Z")

</div>

Thank you for your help.

---

<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:** [2 April 2022 20:36 UTC](https://discourse.nodered.org/t/cant-get-my-head-around-how-to-add-a-value-to-an-brightness-attribute/60081/7 "2022-04-02T20:36:53Z")

</div>

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