The correct way to include an NR variable msg.i in a data JavaScript string?

Hello everyone. I’m trying to simulate a sunrise with a dimmable daylight lamp. It’s a form of daylight therapy during the darker months and helps me wake up more peacefully.
For this, I’ve chosen a modification to a while loop example in Node Red. The loop works. Unfortunately, passing a counter isn’t working yet. Can someone tell me the correct way to include an NR variable msg.i in a data JavaScript string?

I added an action node and a delay note. The action node turns on the light and, more importantly, controls the light intensity. The delay node allows the light to reach full brightness in 15 minutes.

Data {“rgb_color”:[255,100,100],“brightness_pct”: msg.i }
When I enter a number from 1 to 100, this string works, but there’s no change in light intensity.

One of the error messages was :expected a fload. Does it matter if I use a number? What about other variable types?

I’ve searched, read, and tried a lot, and now I’m here. Please help.

I enjoy solving problems, not creating them. Hopefully I haven’t done the latter.

Could you post your flow? I’m not clear on what your problem is. How to pass variables depends on the nodes involved.

The first time I tried to upload the images, it was blocked, bewbe. I didn’t read it properly. I wasn’t allowed to upload two.

Here is the second one.

Inside home assistant nodes you do not use the msg portion only the path.

There are 2 options for the data section. JSON{} or J expression/jsonata J:

image

JSON use "brightness_pct": {{ i }}

J expression use "brightness_pct": i

Thank you very much.
I do have programming experience, but YAML and JSON are new to me. I’ve tried i, {i}, {{i}}, and {{{i}}} in JSON, and nothing worked. So I tried most of the variations I could think of and searched for hours. Hence this thread. I rarely ask for help. I usually find the answer somewhere.
Only after your answer did I switch to J(expression) and only enter i did it work. Because I thought I’d found a bug, I tried {{ i }} and {{i}} in JSON, and everything works as it should. We have a saying in the Netherlands, “Schiet mij maar lek”. I was chasing a ghost for hours.
I also understand your reaction; it should have worked.
But it works now, thanks again.

1 Like

This topic can be closed