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

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.

[{"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"}]

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.

msg.data.attributes.brightness += 50;

return msg;

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"}

[{"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

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.

Just found the solution.

[{"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"}]

Thank you for your help.

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