Using Node-Red to push media and TTS messages to your Xiaomi Gateway 3

Before starting, this guide assumes you’ve been able to do the following things on your Gateway:

  • You’ve been able to flash your Xiaomi Gateway 3 with OpenLumi
  • You’ve been able to connect to your Gateway via SSH and it has a static IP
  • You’ve been able to set up an MPD Server on your OpenLumi and know it’s working because you’ve tested it with Auremo.
  • You’ve been able to upload the mp3 files you need and set up your MPD device on Home Assistant using Yaml.
  • You have Node-Red configured and have some degree of experience with it.

If you have not been able to do these things, please check out my previous post.

What was particularly hard to set up while working with the MPD Daemon on my Lumi Gateway was being able to figure out how to send Text To Speech (TTS) commands and play audio files from Node-Red.

Before moving forward, make sure you can play the files you have uploaded to your gateway using Auremo and you can send TTS commands directly from Home Assistant.

If you can do these things and you are also able to work with Node-Red within your home assistant, then please, continue.

If you need help setting up Node-Red Home Assistant, I highly recommend the Node-Red videos from The Hookup Youtube Channel.

Now, to set up our gateway on Node-Red we’ll need to use the following nodes: Trigger, Inject and call service.

We will use inject to test commands and trigger our Node-Red flows.

The first thing we need to do is to learn to manage the volume of what we want to hear in your Gateway. To do this I use the following, double click on your call service node and fill it up will the following information:

Name: Volume (Or whatever you feel comfortable with)
Server: Home Assistant
Domain: media_player
Service: volume_set
Entity: Xiaomi Gateway or use the name you chose for your gateway
On Data, make sure you chose JSON and type the volume you desire, this one goes from 0.0 to 1, on this case I've chosen 0.6, {"volume_level":"0.6"}

After you can click now on the red button labeled “Done” in the upper right corner of the node window.

You should have something like this:

After this step we would like our gateway to be able to say or play something, I will choose now to play a sound, so, again will I use the call service node for this.

Then we connect the nodes:

Then I added a new call service node and I’ve called it “Ding”, so here is the configuration as follows:

Name: Ding (Or whatever you feel comfortable with)
Server: Home Assistant
Domain: media_player
Service: play_media (Dont confuse this with media_play)
Entity: Xiaomi Gateway or use the name you chose for your gateway
On Data, make sure you chose JSON and type the name of an uploaded mp3 on your /mpd/music folder, on my case I'm choosing {"media_content_type":"music","media_content_id":"Doorbell.mp3"}

After this step, we press the red button “Done” and then “Deploy”, you’ll find the deploy button on the top right corner of Node-Red.

You should be able to play the sound “Doorbell.mp3” or whatever file you’ve chosen using the inject node.

Now to make it say something, you need to have something like this, again we’ll use the call service node, but first, notice I’ve also placed a trigger node between the played audio node “Ding” and the TTS node “Someone at the door”. This is because if you don’t use the trigger, Node-Red will not wait until the sounds finish playing before playing the TTS message. You’ll only hear the “Someone at the door” node without the “Ding” node.

Now, to make it say something, make sure you have something like this on your “Someone at the door” call service node:

Notice we are using J: expression instead of {} JSON this time. The node configuration is as follows:

Name: Someone at the door (Or whatever you feel comfortable with)
Server: Home Assistant
Domain: tts
Service: cloud_say or google_say (Try the one you like the most)
Entity: Xiaomi Gateway or use the name you've chosen for your gateway
On Data, make sure you select J:Expression  and type {"message":"There is someone at the door"}. 

I believe it also works if you chose JSON.

After you’ve configured the node, hit the red done button and the deploy button and your flow should be ready, you should be able to push TTS and sound messages from Node-Red to your Xiaomi Gateway now.