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

As long as it’s not the chain, enjoy.

I’ve never stepped foot into a Starbucks store, but fracking hell, Ellen Tigh is a Cylon. I’d forgotten haha.

There’s one left I think…

Hi

It works for both sending a HTTP command to it and a door opening and closing etc.

She has turned in to an American woman however.

What is meant to happen with the volume when a door is opened or closed?

It doesn’t appear to change at all but I see you have references in the second function to volume 35.

volume not set yet working on it, as to voice i remove the language property, as system will use default, your default must be US i will add langauge back with next update.

to add more sensors just add a mois in, and in function add a property for that sensor in sensors json.

I am working on volume now.

I think adding this line in to the first function has fixed the language I am still testing

language: "En-gb",

I am adding my Garden Gate now see if I can add another one.

OK that works I have added myself another MIOS device to be monitored.

 },
    "Back Garden:Garden Gate:Tripped":{
        "ips":"192.168.0.16|192.168.0.19",
        "message":["Garden Gate Closed","Garden Gate Opened"],
        "volume":35

here is new function i need debugs from output of castv2 node when run. This will set volume to what ever you set

i have added an inject if you connect that to input of`second function you can trigger a tts manually

[{"id":"a5e81c85.6cb888","type":"function","z":"66b3988b.4a2ea8","name":"","func":"var IPS = msg.payload.ip.split(\"|\");\nvar message = msg.payload.message;\nvar ttsVolume = msg.payload.volume || 35;\nfor (var i in IPS) { \n    //msg.ttsVolume = true;\n    msg.payload = {\"type\":\"VOLUME\",\"volume\":msg.payload.volume,\"ip\":IPS[i]};\n    node.send([null,msg]);\nmsg.payload = {\n    type: \"TTS\",\n    text: message,\n    language: \"En-gb\",\n    ip: IPS[i]\n    }\nmsg.iptts = IPS[i];\nnode.send([null, [msg]]);\n}\nif(!msg.sensor){\nmsg.payload = \"ok\"; // the response message\nreturn [msg];\n}else{\n return;\n}\n","outputs":2,"noerr":0,"initialize":"","finalize":"","x":200,"y":160,"wires":[["ac7159a9.0806d8"],["67b423dd.7a9a1c"]]},{"id":"5aee325.02598cc","type":"inject","z":"66b3988b.4a2ea8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"Kitchen:Patio Door:Tripped","payload":"1","payloadType":"num","x":230,"y":440,"wires":[["e81dc498.0a1308"]]}]

OK thanks I’m just adding my fireplace and I will try it.

Overall the CastV2 node seems much more reliable than the old Cast node which sometimes wouldn’t say the TTS every time.

So far CastV2 is working much better in that respect.

I haven’t loaded your last update yet.

Still working on the fireplace. I have a button on my Harmony Elite to turn on / off the fireplace and I use this as my test for Google TTS to see if its still working etc.

I’ve added the fireplace device in to the function but I hear no TTS and get an error.

“Error: Unknown command”

let sensors={
    "Kitchen:Patio Door:Tripped":{
        "ips":"192.168.0.16|192.168.0.19",
        "message":["Patio Door Closed","Patio Door Opened"],
        "volume":35
    },
    "Porch:Front Door:Tripped":{
        "ips":"192.168.0.16|192.168.0.19",
        "message":["Front Door Closed","Front Door Opened"],
        "volume":35
    },
    "Porch:Letterbox:Tripped":{
        "ips":"192.168.0.16|192.168.0.19",
        "message":["null","Letter box Opened"],
        "volume":35
    },
    "Back Garden:Garden Gate:Tripped":{
        "ips":"192.168.0.16|192.168.0.21",
        "message":["Garden Gate Closed","Garden Gate Opened"],
        "volume":35
    },
    "Lounge:Fireplace:Status":{
        "ips":"192.168.0.16",
        "message":["Turning Off Fireplace","Turning On Fireplace"],
        "volume":35
    }
}
let sensor = sensors[msg.topic];
if(sensor["message"][msg.payload] !== "null"){
msg.payload = {
    "message": sensor["message"][msg.payload],
    "ip": sensor["ips"],
    "volume": sensor["volume"]
    }
msg.sensor = true;
return msg;
}else{
    return;
}

The Garden Gate I added before is working OK however.

What is the debug directly after the fireplace mios in node.
full msg including msg.topic

image

“Lounge:Fireplace:Status” should work its what I was using before on the other flow.

Is it because its a boolean?

This is the Garden Gate that works and speaks the TTS.

However that has an error also

image

It is returning a boolean instead of 1 or 0, i have added a check to return 1 if true 0 if false. try this

[{"id":"e81dc498.0a1308","type":"function","z":"66b3988b.4a2ea8","name":"","func":"let sensors={\n    \"sensors:Door sensor:Tripped\":{\n        \"ips\":\"192.168.0.16|192.168.0.19\",\n        \"message\":[\"Patio Door Closed\",\"Patio Door Opened\"],\n        \"volume\":50\n    },\n    \"Porch:Front Door:Tripped\":{\n        \"ips\":\"192.168.0.16|192.168.0.19\",\n        \"message\":[\"Front Door Closed\",\"Front Door Opened\"],\n        \"volume\":50\n    },\n    \"Porch:Letterbox:Tripped\":{\n        \"ips\":\"192.168.0.16|192.168.0.19\",\n        \"message\":[\"null\",\"Letter box Opened\"],\n        \"volume\":35\n    }\n}\nif(sensors[msg.topic]){\nlet sensor = sensors[msg.topic];\nmsg.payload = msg.payload === true ? 1 : 0;\nif(sensor[\"message\"][msg.payload] !== \"null\"){\nmsg.payload = {\n    \"message\": sensor[\"message\"][msg.payload],\n    \"ip\": sensor[\"ips\"],\n    \"volume\": sensor[\"volume\"]\n    }\nmsg.sensor = true;\nreturn msg;\n}\n}else{\n    return;\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","x":270,"y":380,"wires":[["a5e81c85.6cb888"]]}]

P.S. you can now remove all mios in nodes and replace with one mios in, leave the item blank.

That works now for the fireplace Status boolean

slight update for using one mios in node.

[{"id":"e81dc498.0a1308","type":"function","z":"66b3988b.4a2ea8","name":"","func":"let sensors={\n    \"sensors:Door sensor:Tripped\":{\n        \"ips\":\"192.168.0.16|192.168.0.19\",\n        \"message\":[\"Patio Door Closed\",\"Patio Door Opened\"],\n        \"volume\":50\n    },\n    \"Porch:Front Door:Tripped\":{\n        \"ips\":\"192.168.0.16|192.168.0.19\",\n        \"message\":[\"Front Door Closed\",\"Front Door Opened\"],\n        \"volume\":50\n    },\n    \"Porch:Letterbox:Tripped\":{\n        \"ips\":\"192.168.0.16|192.168.0.19\",\n        \"message\":[\"null\",\"Letter box Opened\"],\n        \"volume\":35\n    }\n}\nif(sensors[msg.topic]){\nlet sensor = sensors[msg.topic];\nmsg.payload = msg.payload === true ? 1 : 0;\nif(sensor[\"message\"][msg.payload] !== \"null\"){\nmsg.payload = {\n    \"message\": sensor[\"message\"][msg.payload],\n    \"ip\": sensor[\"ips\"],\n    \"volume\": sensor[\"volume\"]\n    }\nmsg.sensor = true;\nreturn msg;\n}else{\n    return;\n}\n}else{\n    return;\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","x":270,"y":380,"wires":[["a5e81c85.6cb888"]]}]

Trying that now.

I have something strange happening now with the door contacts.

Front Door for example when I tripped it to 1 it says “Front Door Closed” and not opened anymore.

If I tripped it to 0 is also says “Front Door Closed” which is correct.

For the Garden Gate if I tripped it to 0 both Google Home speakers say “Garden Gate Closed”

However if I trip it to 1 one speaker says “Garden Gate Closed” but the other says “Garden Gate Opened”

So some strange stuff happening now.

EDIT

I didn’t try your update for using one MIOS IN.

Trying again now.

Nope its the same as I described above.

The strangeness started after you fixed the fireplace boolean.

This is what I have in the function now

let sensors={
    "Kitchen:Patio Door:Tripped":{
        "ips":"192.168.0.16|192.168.0.19",
        "message":["Patio Door Closed","Patio Door Opened"],
        "volume":35
    },
    "Porch:Front Door:Tripped":{
        "ips":"192.168.0.16|192.168.0.19",
        "message":["Front Door Closed","Front Door Opened"],
        "volume":35
    },
    "Porch:Letterbox:Tripped":{
        "ips":"192.168.0.16|192.168.0.19",
        "message":["null","Letter box Opened"],
        "volume":35
    },
    "Back Garden:Garden Gate:Tripped":{
        "ips":"192.168.0.16|192.168.0.19",
        "message":["Garden Gate Closed","Garden Gate Opened"],
        "volume":35
    },
    "Lounge:Fireplace:Status":{
        "ips":"192.168.0.16",
        "message":["Turning Off Fireplace","Turning On Fireplace"],
        "volume":35
    }
}
if(sensors[msg.topic]){
let sensor = sensors[msg.topic];
msg.payload = msg.payload === true ? 1 : 0;
if(sensor["message"][msg.payload] !== "null"){
msg.payload = {
    "message": sensor["message"][msg.payload],
    "ip": sensor["ips"],
    "volume": sensor["volume"]
    }
msg.sensor = true;
return msg;
}else{
    return;
}
}else{
    return;
}

Try this

[{"id":"e81dc498.0a1308","type":"function","z":"66b3988b.4a2ea8","name":"","func":"let sensors={\n    \"sensors:Door sensor:Tripped\":{\n        \"ips\":\"192.168.0.16|192.168.0.19\",\n        \"message\":[\"Patio Door Closed\",\"Patio Door Opened\"],\n        \"volume\":50\n    },\n    \"Porch:Front Door:Tripped\":{\n        \"ips\":\"192.168.0.16|192.168.0.19\",\n        \"message\":[\"Front Door Closed\",\"Front Door Opened\"],\n        \"volume\":50\n    },\n    \"Porch:Letterbox:Tripped\":{\n        \"ips\":\"192.168.0.16|192.168.0.19\",\n        \"message\":[\"null\",\"Letter box Opened\"],\n        \"volume\":35\n    }\n}\nif(sensors[msg.topic]){\nlet sensor = sensors[msg.topic];\nmsg.payload = (msg.payload === true || msg.payload === 1) ? 1 : 0;\nif(sensor[\"message\"][msg.payload] !== \"null\"){\nmsg.payload = {\n    \"message\": sensor[\"message\"][msg.payload],\n    \"ip\": sensor[\"ips\"],\n    \"volume\": sensor[\"volume\"]\n    }\nmsg.sensor = true;\nreturn msg;\n}else{\n    return;\n}\n}else{\n    return;\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","x":270,"y":380,"wires":[["a5e81c85.6cb888"]]}]

That works now, all the strangeness I just described has gone.

Door contacts say the correct thing now for open and close and on both speakers.

The Fireplace also still working and saying the correct thing for on and off.

OK so what were we doing for volume tests ?