Using Node-Red for Google Home TTS announcements and other stuff eWeLink

{"topic":"Lounge:Fan:Status",
 "payload":true,
 "_msgid":"e318722d.db515"}

so you have
msg.topic - which can identify which switch and room and variable (Status as it tells us switch state).
msg.payload - witch tells you the state of the switch
you have no way of telling which device you want to cast to or the message, these would have to be held in a function node, or in context data.

I’ve come up with half a solution for dynamic TTS text sent to more than one Google Home speaker.

Using two “Change” nodes. I have specified each Google Home devices IP address.

image

image

And in the HTTP IN node I changed its URL so not to conflict with the original URL of “sceneTrigger” we were using.

image

So I can now send dynamic TTS text in my URL to that Google Home “Group” of two devices.

http://NODE-RED-IP:1880/sceneTriggerMulti?message=test

I can just create other flows for other Google Home groups of speakers etc.

Try this in the function node, i have not tested as do not use cast.

var IPS = msg.payload.ip.split("|");
for (var i in IPS) { 
msg.payload = {"message": msg.payload.message, "ip": IPS[i]};
node.send(msg);
}
return;

url
http://ip:1880/sceneTrigger?message=test&ip=12.12.12.12|12.12.12.13|12.12.12.14

let us know how you get on

[{"id":"428703f9.dabacc","type":"tab","label":"Flow 3","disabled":false,"info":""},{"id":"b17b5476.57a298","type":"http in","z":"428703f9.dabacc","name":"http request from scene","url":"sceneTrigger","method":"get","upload":false,"swaggerDoc":"","x":200,"y":240,"wires":[["3b703b98.327224","532c9cdb.e466dc"]]},{"id":"532c9cdb.e466dc","type":"http response","z":"428703f9.dabacc","name":"http response","statusCode":"","headers":{},"x":490,"y":240,"wires":[]},{"id":"3b703b98.327224","type":"function","z":"428703f9.dabacc","name":"create response","func":"var IPS = msg.payload.ip.split(\"|\");\nfor (var i in IPS) { \nmsg.payload = {\"message\": msg.payload.message, \"ip\": IPS[i]};\nnode.send(msg);\n}\nreturn;\n","outputs":1,"noerr":0,"x":480,"y":280,"wires":[["f154932f.09e67"]]},{"id":"f154932f.09e67","type":"debug","z":"428703f9.dabacc","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":600,"y":320,"wires":[]}]

OK thanks, I will give it a try later and report back.

HTTP response in the web browser:

image

Debug window output:

image

However I don’t hear the TTS from the speakers.

This was the URL I sent, I changed the HTTP IN nodes URL to “MultiCast3”

http://192.168.0.2:1880/MultiCast3?mesage=“test”&ip=192.168.0.16|192.168.0.19

The message doesn’t appear to be passed to the Cast node it doesn’t say Playing like it normally does.

Thanks

Here is the function:

image

image

Not sure what the browser response say “mesage” with one S not “message”

remove the “” from “test” in url and add a s to message

My bad typo
http://192.168.0.2:1880/MultiCast3?message=test&ip=192.168.0.16|192.168.0.19

1 Like

Yeah just spotted that in the URL.

Its working now ! Both speakers say TEST

Nice one ! :grinning:

The HTTP IN nodes are now fully dynamic via the URL sent to them.

Just the MIOS IN nodes are not, but I don’t have many, only a few door sensors for opening and closing etc.

As i said earlier you could use reactor to send these url’s when a switch is turned on. No need for mios flows then.

I have also update function node so you can retrun an ok

var IPS = msg.payload.ip.split("|");
for (var i in IPS) { 
msg.payload = {"message": msg.payload.message, "ip": IPS[i]};
node.send([null, [msg]]);
}
msg.payload = "ok"; // the response message
return [msg];
[{"id":"3b703b98.327224","type":"function","z":"428703f9.dabacc","name":"create response","func":"var IPS = msg.payload.ip.split(\"|\");\nfor (var i in IPS) { \nmsg.payload = {\"message\": msg.payload.message, \"ip\": IPS[i]};\nnode.send([null, [msg]]);\n}\nmsg.payload = \"ok\"; // the response message\nreturn [msg];\n","outputs":2,"noerr":0,"x":460,"y":240,"wires":[["532c9cdb.e466dc"],["f154932f.09e67"]]}]

The OK response breaks it.

Debug says:

“configuration error: IP is missing”

Make sure the function has 2 outputs,
the cast goes where the debug is.

OK cool that works now

Remove the link from http in and http response, it’s not needed

1 Like

Result, I’ve gone from a shit load of nodes in and cast devices out, to just two now haha

Thanks again for your help. :grinning:

1 Like

Does the second flow not accept a single ip. I would think you only need one.

Also export the multi cast flow and post it for others.

Yes it does LOL work with only one IP

1 Like

EXAMPLE URLs:

Single IP address of a Cast / Google Home Device:

http://NODE-RED-IP:1880/sceneTrigger?message=TEST&ip=192.168.0.16

Multiple IP addresses of Cast / Google Home Devices:

http://NODE-RED-IP:1880/sceneTrigger?message=TEST&ip=192.168.0.16|192.168.0.17|192.168.0.18

To send from a vera scene use luup.inet.wget e.g

luup.inet.wget("http://NODE-RED-IP:1880/sceneTrigger?message=TEST&ip=192.168.0.16")

I hope this is formatted correctly. If not I’ve attached the json file.flows.zip (850 Bytes)

[{"id":"3a72f933.689e06","type":"tab","label":"TTS-Dynamic","disabled":false,"info":""},{"id":"c994868d.7f48d8","type":"function","z":"3a72f933.689e06","name":"create response","func":"msg.payload = {\"message\": msg.payload.message,\n \"ip\": msg.payload.ip\n }\nreturn msg;","outputs":1,"noerr":0,"x":1120,"y":220,"wires":[[]]},{"id":"47fdc09d.f9c04","type":"cast-to-client","z":"3a72f933.689e06","name":"","url":"","contentType":"","message":"","language":"En-gb","ip":"","port":"","volume":"","x":550,"y":140,"wires":[["3495f4ac.b008ec"]]},{"id":"3495f4ac.b008ec","type":"debug","z":"3a72f933.689e06","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":710,"y":140,"wires":[]},{"id":"8fe0bf3c.4e32","type":"comment","z":"3a72f933.689e06","name":"TTS Cast - Specify IP(s) in the URL","info":"","x":160,"y":60,"wires":[]},{"id":"e482f40a.8af9b8","type":"http in","z":"3a72f933.689e06","name":"http request from scene","url":"sceneTrigger","method":"get","upload":false,"swaggerDoc":"","x":120,"y":100,"wires":[["fc546d4b.dd073"]]},{"id":"1d4c3b30.18d375","type":"http response","z":"3a72f933.689e06","name":"http response","statusCode":"200","headers":{},"x":580,"y":100,"wires":[]},{"id":"fc546d4b.dd073","type":"function","z":"3a72f933.689e06","name":"IP-Addresses-Function","func":"var IPS = msg.payload.ip.split(\"|\");\nfor (var i in IPS) { \nmsg.payload = {\"message\": msg.payload.message, \"ip\": IPS[i]};\nnode.send([null, [msg]]);\n}\nmsg.payload = \"ok\"; // the response message\nreturn [msg];","outputs":2,"noerr":0,"x":350,"y":100,"wires":[["1d4c3b30.18d375"],["47fdc09d.f9c04"]]}]

1 Like