Call HA service from Node-Red

Entity
I have device within HA and 3 buttons that I can control it. It is window opener and therefore three operations are possible: up, down and stop. I would like to call it from Node-Red, but never done anything similar. I understand I would need call service (have node-red-contrib-home-assistant-websocket in my pallete), but where do I find service that I need to call? Or should I think differently within node-red to complete the action of opening or closing window.

Guessing you have a cover entity, the services you are looking for are:

  • cover.open_cover
  • cover.close_cover
  • cover.stop_cover

with “cover” is the domain, you have to use in Node-RED and the part after the “.” is the service name:

1 Like

Thank you so much, works great! I am curious, were man can read all the functionality that can be used? How do you know that it is ‘open_cover’ you need to type into service??? Also, could that be some extra functions that are there? This device can also be controlled by Smart Life app, where you can use slide to open let’s say 20% of total. So I was thinking, could there be a way to send command from Node red to open X % ?

Can I use msg.payload to give value to Service line? I do check temperature and based on it’s value would like to call either Open_cover or Close_cover comand

Hi, most things are well documented, when one know where to look :wink:

There you can also find cover.set_cover_position which is the service you are looking for right now.

1 Like

Here is an example flow which shows you both.

  • Make a decision based on payload with a switch node
  • Call a service set_cover_position with the current payload as parameter for position

You can import this to Node RED:

[{"id":"a78225cb.a468e8","type":"inject","z":"17c6db5.4c69d25","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"25","payloadType":"num","x":130,"y":120,"wires":[["76ade4d5.ca094c"]]},{"id":"c10ad79a.9bccf","type":"inject","z":"17c6db5.4c69d25","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"10","payloadType":"num","x":130,"y":200,"wires":[["76ade4d5.ca094c"]]},{"id":"76ade4d5.ca094c","type":"switch","z":"17c6db5.4c69d25","name":"> 15 ?","property":"payload","propertyType":"msg","rules":[{"t":"gt","v":"15","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":310,"y":160,"wires":[["9c35531a.6263f"],["3d4d5eca.4bd2ba"]]},{"id":"3d4d5eca.4bd2ba","type":"api-call-service","z":"17c6db5.4c69d25","name":"","server":"90f84041.e17b8","version":1,"debugenabled":false,"service_domain":"cover","service":"open_cover","entityId":"cover.arbeitszimmer","data":"","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":500,"y":180,"wires":[[]]},{"id":"9c35531a.6263f","type":"api-call-service","z":"17c6db5.4c69d25","name":"","server":"90f84041.e17b8","version":1,"debugenabled":false,"service_domain":"cover","service":"close_cover","entityId":"cover.arbeitszimmer","data":"","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":510,"y":140,"wires":[[]]},{"id":"cc19fa75.c4eaa8","type":"api-call-service","z":"17c6db5.4c69d25","name":"","server":"90f84041.e17b8","version":1,"debugenabled":false,"service_domain":"cover","service":"set_cover_position","entityId":"cover.arbeitszimmer","data":"{\"position\":\"{{payload}}\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":440,"y":320,"wires":[[]]},{"id":"42b798cc.45bdb8","type":"inject","z":"17c6db5.4c69d25","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"30","payloadType":"num","x":160,"y":320,"wires":[["cc19fa75.c4eaa8"]]},{"id":"90f84041.e17b8","type":"server","name":"Home Assistant","addon":true}]

thanks a lot, I am nearly there. Opening and closing works, but set_cover_position is not working. Could that be dependant on device type that I selected when setting it up in Smart Life app?