Unable to pass flow variable to Call Service node

Having a difficult time getting a variable into a Call Service node. Research here and on Node Red forums have produced many possible answers but not a solution for my use case. In the Data field of the call service, I am trying to replace: {"hvac_mode":"cool"} with {"hvac_mode": "{{global.mode_hvac}}"}

Have tried several variations of where the quotes go and always get API Errors. Usually either:
“Call-service error. expected HVACMode or one of ‘off’, ‘heat’, ‘cool’, ‘heat_cool’, ‘auto’, ‘dry’, ‘fan_only’ for dictionary value @ data[‘hvac_mode’]” OR
Call-service error. extra keys not allowed @ data[‘0’]

Any thoughts on where to head next?
Cheers,

Are using json on the data type, not j;expression? The first example is right. On the right hand side there is a tab context → there is a section globals, hit refresh, is the value there?

Mikefila,
JSON Yes. And actually no I don’t see the variable showing in context tab. That is likely the root of my problem. I am setting the variable with a function.(Below) I started with a flow variable and only tried the global for a test. A debug node shows me the payload being set and I see that in debug output, but I may not actually be getting the variable set properly. (New to Node Red) I will investigate that angle further. Thanks for the reply.
Cheers

var hvacmode = msg.payload

if ((hvacmode == "cool") ||
    (hvacmode == "heat_cool") ||
    (hvacmode == "heat"))
{
    context.set("flow.mode_hvac",hvacmode);
    msg.payload = context.get("flow.mode_hvac");
}
else

{
    msg.payload = "ignore";
}
return msg

The first post you use global the second flow they are not interchangeable. globals are available on all tabs. flow is only available on the same tab.

Yes. Thank you. I started with the flow context but only switched to global as a troubleshooting test when I could get nothing working (Again, new to node red.) My goal was to have and use the flow variable so that is reflected in the function code in my last message. Regardless, neither seems to show in the context tab you mentioned so that is where I am troubleshooting now. Might need to use a different function or other means to set that flow variable. In my first post, the global shown has actually been flow.mode_hvac in most of my testing.
Cheers,

I personally don’t use context.set I use flow.set/get or global.set/get respectively. Then just with the name flow.set("mode_hvac", hvacmode) then {{ flow.mode_hvac }} in the data field

1 Like

Mikefila, SOLVED! Thank you very much.
I think I was over complicating things with my function. Based on your suggestions, I simplified by replacing my function with a simple Change node to set the flow.mode_hvac. Running that, I immediately see the value on the context tab. And my JSON on the Call Service also worked as expected.