Hi, struggling with the correct format to add a dynamic value for fan speed.
This is the output I want to use to set the speed: payload.data.fan_level
This is what I tried in the call service node data field:
{"percentage":"{{payload.data.fan_level}}"} {"percentage":"payload.data.fan_level"} {"percentage":{{payload.data.fan_level}}} {"percentage":payload.data.fan_level}
both as expression and json… please help me with the correct format
Edit: some other tries not successful: {"percentage":"$number(payload.data.fan_level)"} {"percentage":$number(payload.data.fan_level)}
If the incoming message has a payload.data that is an object or parsable into an object these properties will be merged with any config values set.
Merge Resolution
As seen above the data property has a lot going on in the way of data merging, in the end, all of these are optional and the rightmost will win if a property exists in multiple objects
Config Data, Global Data, Flow Data, Payload Data ( payload data property always wins if provided
If you are constructing an object (as you are) for the Data Field in a call-service node, you should always use JSONata (J: expression) as mustache templating does not work correctly.
JSONata expressions evaluate on the incoming message, and you don’t need the msg. bit at the front.
Hence
{ "percentage": payload}
will evaluate payload and create the object with that value.
You can use nested objects using the dot notation, so payload.data.fan_level would also work quite nicely.
However, I believe that the call service node will attempt to merge the incoming payload.data object. I am not about to test this, but my guess is that you are probably ending up with data field being set to {“percentage”: 32, “fan_level”: 32}. A bit like ‘The Fly’.
My suggestion would be to avoid using payload.data in the first place. Perhaps payload.setting.fan_level?