Insert variable into a change node

This is Home Assistant related, but I believe someone here may be able to help. I found similar question on here, but it dealth with a http response.

[{"id":"9d4d90de.91179","type":"tab","label":"Flow 5","disabled":false,"info":""},{"id":"b3fe91.07c4e17","type":"server-state-changed","z":"9d4d90de.91179","name":"Brightness changed","server":"817e283a.e704f8","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_number.light_strip_brightness","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":320,"y":200,"wires":[["44c70077.bf323"]]},{"id":"7ff53dc4.9645a4","type":"change","z":"9d4d90de.91179","name":"22","rules":[{"t":"set","p":"topic","pt":"msg","to":"zwave/_CLIENTS/ZWAVE_GATEWAY-Mosquitto/api/sendCommand/set","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"{     \"args\": [     {       \"commandClass\": 112,       \"nodeId\": 12,       \"property\": 23     },     \"set\",     [       23,       {{brightness}},       4     ]   ] }","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":830,"y":200,"wires":[["9a70e8de.15d6c8"]]},{"id":"44c70077.bf323","type":"change","z":"9d4d90de.91179","name":"","rules":[{"t":"set","p":"brightness","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":600,"y":200,"wires":[["7ff53dc4.9645a4"]]},{"id":"9a70e8de.15d6c8","type":"debug","z":"9d4d90de.91179","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":990,"y":200,"wires":[]},{"id":"817e283a.e704f8","type":"server","name":"Home Assistant","addon":true}]

When I change brightness slider, the event state node is triggered and the number is put into msg.payload.

I use the change node to move the number value in msg.payload into msg.brightness

What I then want in the change node labeled 22 is to input that msg.brightness value here:

But when I try that and check the debug, it just sends {{brightness}} instead of the number value. So it will send this…
image

When I want it to send this (assuming brightness slider was set to 99)
image

I would recommend to go through the documentation and specifically how to work with messages.

You are trying to make a new object by using a change node and setting it to text with a new message, this is not how it works (well i guess it could be done in some way, but this is complicating things).

There are multiple ways to do this, create a new object with a change node by means of specifying each property, using jsonata or with a function node. I think a function node will be the easiest.

example in a function node:

let input_brightness = msg.brightness

msg.payload = {args:[{brightness:input_brightness}]} // build your new object here

return msg

This seems like a template node will do the job.
e.g.

[{"id":"d3b9ea1c.861f1","type":"inject","z":"9d4d90de.91179","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"78","payloadType":"num","x":340,"y":200,"wires":[["5c2de512.39f6fc"]]},{"id":"5c2de512.39f6fc","type":"template","z":"9d4d90de.91179","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{     \n    \"args\": \n        [     \n        {\"commandClass\": 112,      \n        \"nodeId\": 12,       \n        \"property\": 23     \n        },     \n        \"set\",     \n        [ 23, {{payload}}, 4]   \n        ] \n    }","output":"str","x":490,"y":200,"wires":[["9a70e8de.15d6c8"]]},{"id":"9a70e8de.15d6c8","type":"debug","z":"9d4d90de.91179","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":650,"y":180,"wires":[]}]

Then just use msg.payload from the dropdown.

2 Likes

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