and I’m trying to call it from a service node in NR. I’m confident I’ve got the node setup right with the exception of the variable bit (if I do it with another script it works fine). I’m just struggling with what goes into the data call. Thanks.I have tried {“brightness_var”:1} in the data call and am not sure what else to try.
There is a specific reason to use the script. There will ultimately be a lot of them and creating lots of scripts using find and replace as appropriate is much better than hundreds of nodes.
Edit: Also this is just a sample script. It won’t be this actual script, this is my minimal viable example whilst I figure this out.
I don’t know if it is doable, I would like to know too!!
However, without knowing the “right” way (if there is one), I would do it using a dummy sensor from node-red. Using node red, you can create the sensor, using your example brightness_var and put 1 as a value using the API. Then, on HA you can get the value using sensor.brightness_var
You, kind of, use the sensor information as a variable between the two environments. Maybe not the cleanest option, but, it does the job!
GV
I don’t know the exact use case, but you know you can pass variables such as entity id, and pretty much anything else, into the service call by populating the message in previous nodes?
I’m replacing my scenes since they canned transitions and it broke my setup. Plan was to build one script per room and pass in brightness, x_y color and transition time. But different rooms have different bulb types and different numbers of entities. So the rooms themselves need to be predefined. Hence 10 scripts and passing the data from node red. I could do it all in node red but it feel more messy (there’s already pages of node red to decide what that x_y color should be!)
Ive got it! The trick is not to call the script.turn_on, but to put the script in the service call. The following screenshot works to interact with the script at the start of the thread.