Passing variables to Node-RED endpoint

Hi, I’m new to Node-RED and am setting up endpoints to allow me to control some thermostats in HomeAssistant. I’d like to set up an endpoint to set the temperature for the thermostat but I’m unclear how to do this.

Let’s say my endpoint is xxx/endpoint/mbr_set_temp. Can I add a token to the endpoint and do something like this?

xxx/endpoint/mbr_set_temp?setpoint=72

If I can do this, how do I format the JSON text in the data field in Node-RED so the 72 gets passed to the set_temperature service call?

Thanks in advance for your help.

For anyone who is interested, I figured out how to accomplish this:

  • In the “http in” node name your endpoint like this (in this example I’m trying to send a temperature to Node-RED): homeassistant.local/endpoint/mbr_set_temp/:settemp

  • Ini the “call service” node define the data field using the following format: { "temperature": "{{req.params.settemp}}" }

Hope this can help someone trying to control Node-RED using endpoints and simple HTTP requests coming from other home automation platforms, or from browsers.

1 Like

This was very helpful, thank you! I used this to pass a target entity as well. It required a little more work, so I thought I’d add to this post.

To pass more than one variable I set the “http in” endpoint to:

/sonos_queue/:player/:position

In the “call service” node the JSON Data looks like this:

{
    "entity_id": "media_player.{{req.params.player}}",
    "queue_position": "{{req.params.position}}"
}

When I enter the following into my browser it starts playing the kitchen queue at position 10:

http://homeassistant:1880/endpoint/sonos_queue/kitchen/10