Call Home Assistant Service from Function Node?

Can someone help me figure out the syntax to call a service from a Node Red Function Node? I know about the call service node, but I don’t want 100 of them lying about, when I can write a little bit of code.

I can get as far as global.get('homeassistant').homeAssistant.services.light.turn_on, but that’s not a function.

How do I use this (and other) services?

Thanks!

I think you will need to call the api directly using an http/request nodejs module if you want to do it in the function node. The services you are seeing are the description of the domain, service and data that appear in the call service node and retrieved by the ws api.

You don’t need a 100, the call service node can be ran with dynamic input(settings) you just need so set the payload correctly of domain, service and data. before it. I do this a lot in node-red

What is it exactly you are trying to solve here ?
I make really complex flows in NR, but never had the need to call services in function nodes (and I use function nodes a lot - really a lot)

Thank you both. I’ve got it sorted; it was just a matter of taking the programmer out of the programmer, and thinking differently. I appreciate it!

Did to figure it out? I’m also interested. To me is also much easier to program a function than messing, wiring a bunch of boxes.

1 Like

Wonderful. What the “eff” did you do? Share your result please!

1 Like