I have the following code in a function node. That’s the entire code in that flow and function. Assuming that the entity ID is correct, shouldn’t it turn on that light? Right now it is not.
No, you use a call service node
The output from your function node fits the required data in a service node.
And node.send is just the same as return msg here.
Send.node does not stop execution in the node unlike return msg does, but there is nothing more in the node anyway.
What would be simplest way to call whatever API call service node uses so that I can continue with other code in that function node after turning on the light?
I do a lot of calculation and preparing in function nodes too, but the service calls are still placed in the nodes for that.
You can generally do all the calculations in one function node with the help of the global variable for HA values.
I am not even sure that there is a function available in a function node to make a service call.
A service call is a HA specific feature and Node Red is not made specifically for HA, but rather as a general automation tool.
You could use an API call to HA.
But if you don’t like the graphics of Node red then use HA automations instead.
Either way the question is far too vague and generally that we can only speculate or guess.
If you make your question more precise then we might be able to help you.
That would be great. Please point me to some documentation or example of an API call to HA from a function node. That is the help I am looking for.
Here’s an simple example of what I would like to do:
if a person arrives home
— turn on their room lights using custom brightness and color temperature curve that they can configure
—— while the light stays on update the light every 5 mins based on same curve
—— but if the lights get turned off manually keep them off till turned on manually
— if the room is hot turn on the AC
—— turn off the AC when room temperature is at a configured level
— if the room is cold turn on the heater
—— turn off the heater when room temperature is at a configured level
— but if there is no motion in room in some configured minutes turn off everything and suspend automation for the room
— if there is motion in the room restart all automation for the room
— if the person leaves turn off devices that are still on
—— if HomePods in room are playing pause them
There is lot more to do, but on a mobile so taking too long. My groovy code for this is on GitHub. I don’t necessarily want to replicate all of it but some parts of it:
I strongly advice against such a setup.
Having all that in one function node (if it’s even possible) will be a mess and you would need to loop indefinitely inside this loop.
There is really nothing good.
You are not using any of the benefits of HA when you set it up like that.
Make sure your automations don’t run all the time, instead make them run when they should run.
The way I understand your code it’s almost like “are we there yet? are we there yet?”
Nah. SmartThings groovy code was also trigger based and single threaded like HA so a lot of that is achieved through maintaining various state and checking combination of conditions on trigger. Nothing in the code that I have, executes for more than a few ms at a time and is always triggered by device or time conditions.
Please point me to some documentation or example of an API call to HA from a function node. That is the help I am looking for.
I’m not your servant.
Feel free to google home assistant API yourself and finding a way to do this from function node.
I doubt you can do it from a function node but you can send the message to a http node.
My current thinking is, because I would then be able to control a variety of devices from the function node without having to use msg.payload from the function node with a switch node to control which all devices need to be set to various states.