As a cloud developer advocate, my job is to explore and work with different IBM Cloud services. Based on my interest in IoT, Node-RED and Watson have always grabbed my attention. Recently, I was searching through some recipes and came across Weather service integration with Watson Text–to–Speech on Node-RED. Following are my experiences in completing the recipe.

Node-RED primer

Node-RED is a drag-and-drop programming tool based on a web browser. It’s used for wiring hardware devices, APIs, and other IoT systems with online services. Built on Node.js, it can run locally or in the cloud.

Nodes used in the recipe

The most common nodes used in flows are:

  • Inject: Sends messages in the flow, either manually or at regular intervals
  • Function: Run the message
  • Debug: Displays selected message properties

  • common nodes

The other nodes used in this recipe are: Template, Http In, Weather Insights, and Watson Text-to-Speech service

  • Template: Sets a property based on the provided guide
  • Http In: Sends HTTP requests and returns the response
  • Weather Insights: Enables you to access historical and real-time weather data from The Weather Company
  • Watson Text-to-Speech service: Understands text and natural language to generate synthesized audio output complete with appropriate cadence and intonation
main nodes


Start with an inject node, which will trigger the message into the flow. Add a function node and define the location for which you want to hear out the weather.

msg={ street: "Hilal road", city: "Islamabad", country: "pakistan" }; 
return msg;

Next, add a template node that will fetch the location from the HTTP request for Geo Location. The address will be extracted in the form of latitude and longitude using the following code

return msg;

After collecting the location data, join the Weather Insight node in the flow to call the Weather Company data service. In this recipe, I extracted the temperature from the data collected from the Weather Company for my location using the following code:

msg={ temp: msg.observation.temp, city: msg.observation.obs_name}; 
return msg;

After collecting and extracting data, I now had to create a complete answer sentence. For this purpose, the recipe suggests to add another template node with the following configurations:


Adding a debug node at this point will display the temperature as output, which is a traditional way to check the temperature.

The most interesting and fun part for me was the ending where I integrated Watson Text-to-Speech (TTS) service to hear the weather. I dragged the TTS node from the palette and connected it with the answer node.


After setting the values, I added a function that acts like a buffer to reorder the parameters:

return {payload:msg.speech};

Finally, I added the Play Audio node. This node takes the audio file and plays it directly from the Node-RED framework on your computer's speakers.


This recipe was a fun way to integrate multiple services of IBM Cloud with each other. We can also play around with the flow and further refine it by extracting weather data for different dates or changing the locations. It can also be used as a demo by cloud developer advocates for engaging developers and grabbing their attention.

I'd love to hear your results! Leave me a comment below and let me know how you do with the recipe.

Join The Discussion

Your email address will not be published. Required fields are marked *