Ok i’m new at node red and what looks simple seems to be harder than i expect.
I’m trying to manage the brightness of my lights, i’m sure this is the “hello world” of Node Red, but i also want to learn how it works.
but now the brightness_pct property isn’t being added to the message and the brightness isn’t being set. This makes me sad, any one have any hints as to the probably very simple thing ive missed.
Maybe it can’t be done inside a service call? If so then perhaps adding a function node upstream that formats the proper data can be used to feed the service call?
I don’t have it in front of me to test, but I’m fairly sure msg.attributes.brightness should be attributes.brightness. You skip the msg part within JSONata. It used to warn you about this, but maybe the latest version no longer does. So maybe you’re effectively getting msg.msg.attributes.brightness which doesn’t exist and so the property doesn’t get set.
I would guess attributes.brightness is the incorrect path. Drop a debug node with full output before the call-service node. My guess would be you need to use data.attributes.brightness.
is the debug from the previous node, i’m using it in the JSONata editor test message.
I’m accessing the incoming message fine, “attributes.brightness” is correctly being read as 12 and is going through my maths, to become "brightness_pct": 15 as per the results above.
I’m struggling because a JSONata result of
{
"brightness_pct": 15
}
behaves differently to JSON
{"brightness_pct": 15}
the JSON version ends up in my output message and the JSONata version doesn’t, as per the debug dumps in my last message.