Page 1 of 1

Controlicz Alternative (Node red + ifttt) -Google Home

Posted: Friday 20 July 2018 4:23
by pabloalcantara
Hi,
Since Controliz is now a paid subscription, i decided to take onother route and create my simple alternartive version, that is in no way is up to par with Controliz but it is working pretty well for what I need.
So I have created an flow on node red and is using ifttt as the integration with google home.
For this to work you´ll need:

1) Expose node red on public web, and if your IPs is dynamic, an Dynamic DNS (please, read this for security reasons: https://github.com/node-red/cookbook.no ... e-Internet)

2) Create 2 applets on ifttt
2.1) Google Assistant --> Voice command "Turn on $" and "OK" as response --> Web Hook --> url: "https://<<your public ip/name/dynamic dns>>/ghome?cmd=on&device={{TextField}}"
2.2) Google Assistant --> Voice command "Turn off $" and "OK" as response --> Web Hook --> url: "https://<<your public ip/name/dynamic dns>>/ghome?cmd=off&device={{TextField}}"

3) Add this to node red pallet: node-red-contrib-filter, node-red-contrib-splitter and node-red-contrib-google-home-notify

3) Import the flow attached

4) Adjust as desired the variable on the node "Flow Variables":
4.1) domoticzServer: IP/hostame of the Domoticz Server
4.2) domoticzPort: Web port of the Domoticz Server
4.3) domoticzLogin: A user in Domoticz
4.4) domoticzPassword: Password for the user above
4.5) voiceOnCmd: Frase to say when Turning on the device <Ex: Turning on ...., Ligando ...>
4.6) voiceOffCmd: Frase to say when Turning off the device <Ex: Turning off ...., Ligando ...>
4.7) voiceDeviceBegin: Frase to say on the beggining when the device is not recognized <Ex: Device ..... 'voiceDeviceEnd'>
4.8) voiceDeviceEnd: Frase to say on the end when the device is not recognized <Ex: 'voiceDeviceBegin' ..... Not Recognized>
5) Edit the node "domoticz/in" and adjust your ip of your mqtt server
6) Edit the node "Google Home Notify" and use the IP address of your Google Home
7) Now edit each device on Domoticz and on Description use something like this:
;ghome:<word 1>,<word 2>,<word 3>,....,<word 99>; (Do no use spaces between commas)
ex: Kithchen Light --> ;ghome:kitchen;
My bedroom Light --> ;ghome:my bedroom,my room;
Garden Light --> ;ghome:Garden Lights;
Rules:
7.1) Do not use the same word one more than one device
Ex: My bedroom Light --> ;ghome:bedroom,my room,my bedroom;
Chliderns bedroom Light --> ;ghome:Chliderns bedroom;
In the case above, the word bedroom appear on both devices, so if you say "Hey google, Turn on Bedroom", It will turn on the two lights, Because "bedroom" exists on "Chliderns bedroom";

7.2) Always try to use specific words to describe the device, so in the case above, the right way is:
Ex: My bedroom Light --> ;ghome:my room,my bedroom;
Chliderns bedroom Light --> ;ghome:Chliderns bedroom;


So, this is the alfa Version 0.00000000001. Bugs will appear, probably a lot of them...

Help is apreciated.
To do list:
1) Add secutity to the call between ifttt and node red url webhook;
2) Better word detection
3) Better Google Home integration without the need of ifttt
4) ????????? Help....

Sorry for my bad english, I´m Brazilian

Import this on node red

Code: Select all

[{"id":"c912b393.34004","type":"tab","label":"Domoticz Google Home","disabled":false,"info":""},{"id":"9bce9ee0.0ac6b","type":"http response","z":"c912b393.34004","name":"","statusCode":"","headers":{},"x":630,"y":480,"wires":[]},{"id":"21aef424.ca2ffc","type":"http in","z":"c912b393.34004","name":"","url":"/ghome","method":"get","upload":false,"swaggerDoc":"","x":150,"y":540,"wires":[["b85f0027.ba98e","c4d8dfb4.10fb7"]]},{"id":"b85f0027.ba98e","type":"template","z":"c912b393.34004","name":"Simple response","field":"payload","fieldType":"msg","format":"html","syntax":"plain","template":"Ok","x":430,"y":480,"wires":[["9bce9ee0.0ac6b"]]},{"id":"c4d8dfb4.10fb7","type":"function","z":"c912b393.34004","name":"Read Dictionare","func":"var cmd = msg.payload.cmd\ncmd = cmd.toLowerCase();\nvar device = msg.payload.device;\ndevice = device.toLowerCase();\nwords = flow.get('words');\nvar idx = 0;\nvar voicecmd;\nif (cmd === \"on\")\n{\n    cmd = 1;\n    voicecmd = flow.get('voiceOnCmd');\n}\nelse if (cmd === \"off\")\n{\n    cmd = 0;\n    voicecmd = flow.get('voiceOffCmd');\n}\nif (cmd === 1 || cmd === 0 )\n{\n    for (i = 0; i < words.length; i++)\n    {\n        var word = words[i].split(\":\");\n        if (device.indexOf(word[0]) > -1)\n        {\n            idx = word[1];\n            name = word[2];\n        }\n    }\n    if (idx !== 0)\n    {\n        msg.payload = '{\"idx\":' + idx + ',\"nvalue\":' + cmd + ',\"svalue\":\"\"}';\n        var msg2 = { payload:\"\" };\n        msg2.payload = voicecmd + \" \" + name;\n        return [ msg, msg2];\n    }\n    else\n    {\n        msg.payload = flow.get('voiceDeviceBegin') + ' ' + device + ' ' + flow.get('voiceDeviceEnd');\n        return [ null, msg];\n    }\n}","outputs":2,"noerr":0,"x":420,"y":600,"wires":[["3d00d6b6.3cb84a"],["26102169.1fc89e"]]},{"id":"3d00d6b6.3cb84a","type":"mqtt out","z":"c912b393.34004","name":"","topic":"domoticz/in","qos":"0","retain":"false","broker":"f52a5e5a.a2be4","x":650,"y":560,"wires":[]},{"id":"4e5aa7a5.f6e1e8","type":"inject","z":"c912b393.34004","name":"","topic":"","payload":"","payloadType":"date","repeat":"600","crontab":"","once":true,"onceDelay":"1","x":130,"y":160,"wires":[["ea87fd01.125c3"]]},{"id":"ee4d95a4.da2a08","type":"change","z":"c912b393.34004","name":"","rules":[{"t":"delete","p":"responseUrl","pt":"msg"},{"t":"delete","p":"headers","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":720,"y":160,"wires":[["84c00300.5edff"]]},{"id":"84c00300.5edff","type":"splitter","z":"c912b393.34004","name":"","property":"payload.result","x":890,"y":160,"wires":[["6c0c3262.814a3c"]]},{"id":"6c0c3262.814a3c","type":"filter","z":"c912b393.34004","name":"","property":"payload.Description","propertyType":"msg","asArray":false,"itemProperty":"payload","itemPropertyType":"item","rules":[{"t":"cont","v":"ghome:","vt":"str","output":1}],"checkall":"true","outputs":1,"x":1010,"y":160,"wires":[["cf4a4597.950788"]]},{"id":"cf4a4597.950788","type":"change","z":"c912b393.34004","name":"","rules":[{"t":"delete","p":"payload_unsplit","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":200,"y":300,"wires":[["358aace.3cd7654"]]},{"id":"358aace.3cd7654","type":"function","z":"c912b393.34004","name":"Idx to word","func":"var description = msg.payload.Description;\nvar ghome;\nvar words = new Array();\ndescription = description.split(\";\");\nfor (i = 0; i < description.length; i++) \n{ \n    var option = description[i];\n    if (option.indexOf('ghome') > -1)\n    {\n        msg.idx = msg.payload.idx;\n        msg.name = msg.payload.Name;\n        option = option.split(\":\");\n        ghome = option[1]\n        ghome = ghome.split(\",\");\n        for (j = 0; j< ghome.length; j++)\n        {\n            var line = ghome[j] + \":\" + msg.idx + \":\" + msg.name;\n            line = line.toLowerCase();\n            words.push(line);\n        }\n        msg.words = words;\n        msg.ghome = ghome;\n        return msg;\n    }\n}","outputs":1,"noerr":0,"x":470,"y":300,"wires":[["477f2b7c.41f184"]]},{"id":"477f2b7c.41f184","type":"join","z":"c912b393.34004","name":"","mode":"custom","build":"string","property":"words","propertyType":"msg","key":"idx","joiner":",","joinerType":"str","accumulate":false,"timeout":"10","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":630,"y":300,"wires":[["da510cfa.33f45"]]},{"id":"da510cfa.33f45","type":"function","z":"c912b393.34004","name":"Create Dictionare","func":"words = msg.words\nwords = words.split(\",\");\nflow.set('words',words);\nreturn msg;","outputs":1,"noerr":0,"x":790,"y":300,"wires":[[]]},{"id":"26102169.1fc89e","type":"googlehome-notify","z":"c912b393.34004","server":"a47505a0.d18cb8","name":"","x":680,"y":640,"wires":[]},{"id":"ea87fd01.125c3","type":"change","z":"c912b393.34004","name":"Flow Variables","rules":[{"t":"set","p":"domoticzServer","pt":"flow","to":"localhost","tot":"str"},{"t":"set","p":"domoticzPort","pt":"flow","to":"80","tot":"num"},{"t":"set","p":"domoticzLogin","pt":"flow","to":"","tot":"str"},{"t":"set","p":"domoticzPassword","pt":"flow","to":"","tot":"str"},{"t":"set","p":"voiceOnCmd","pt":"flow","to":"Turning On","tot":"str"},{"t":"set","p":"voiceOffCmd","pt":"flow","to":"Turning Off","tot":"str"},{"t":"set","p":"voiceDeviceBegin","pt":"flow","to":"device","tot":"str"},{"t":"set","p":"voiceDeviceEnd","pt":"flow","to":"not recognized","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":260,"y":40,"wires":[["c5398e08.fafe6"]]},{"id":"668e7ea1.4792f","type":"http request","z":"c912b393.34004","name":"","method":"GET","ret":"obj","url":"","tls":"","x":550,"y":160,"wires":[["ee4d95a4.da2a08"]]},{"id":"c5398e08.fafe6","type":"function","z":"c912b393.34004","name":"url create","func":"domoticzLogin = flow.get('domoticzLogin');\ndomoticzPassword = flow.get('domoticzPassword');\ndomoticzServer = flow.get('domoticzServer');\ndomoticzPort = flow.get('domoticzPort');\nif (domoticzLogin === '' || domoticzPassword === '')\n{\n    msg.url = 'http://' + domoticzServer + ':' + domoticzPort + '/json.htm?type=devices&filter=light&used=true';\n}\nelse\n{\n    msg.url = 'http://' + domoticzLogin + ':' + domoticzPassword + '@' + domoticzServer + ':' + domoticzPort + '/json.htm?type=devices&filter=light&used=true';\n}\nreturn msg;","outputs":1,"noerr":0,"x":400,"y":160,"wires":[["668e7ea1.4792f"]]},{"id":"f52a5e5a.a2be4","type":"mqtt-broker","z":"","name":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"30","cleansession":true,"birthTopic":"/nodered/connected","birthQos":"0","birthRetain":"false","birthPayload":"","closeTopic":"","closePayload":"","willTopic":"/nodered/disconnected","willQos":"0","willPayload":""},{"id":"a47505a0.d18cb8","type":"googlehome-config-node","z":"","ipaddress":"192.168.25.171","language":"pt"}]

Re: Controlicz Alternative (Node red + ifttt) -Google Home

Posted: Friday 20 July 2018 5:51
by Wob76
Thanks for sharing, I also needed to install node-red-contrib-splitter.

I have tested it yet, but I will have a play.

I also might dust off my old solution, it was a variation of one in this thread (viewtopic.php?f=69&t=13607&start=20#p150149).

The limitation I didn't like at the time was it would stop any music playing to talk back, looks like node-red-contrib-google-home-notify has the same limitation as node-red-contrib-chromecast that I was using.

Re: Controlicz Alternative (Node red + ifttt) -Google Home

Posted: Friday 20 July 2018 10:55
by pabloalcantara
Thanks,
I"ll take a look on what have you done and see if I can make mine some adjust

Re: Controlicz Alternative (Node red + ifttt) -Google Home

Posted: Friday 20 July 2018 16:08
by EdwinK
I don't understand a word of it. So I better wait till you have at least gone to a beta version 1 or so :)

Re: Controlicz Alternative (Node red + ifttt) -Google Home

Posted: Friday 20 July 2018 16:14
by pabloalcantara
I can help, Whats part do you have trouble?
You already works with ifttt and nodered?

Re: Controlicz Alternative (Node red + ifttt) -Google Home

Posted: Friday 20 July 2018 16:36
by EdwinK
Nope, so that is the problem ;). At the moment I don't really have much time to all this ;) Thanks anyway

Re: Controlicz Alternative (Node red + ifttt) -Google Home

Posted: Friday 20 July 2018 17:07
by jvdz
This is indeed an interesting approach and fully understand that this needs a more elaborate setup/config description for people starting with MQTT/Node-Red/IFTTT as it does take some effort to install it all correctly.
The basics work quite nicely though so really nicely done!
Thanks for sharing,
Jos

Re: Controlicz Alternative (Node red + ifttt) -Google Home

Posted: Friday 20 July 2018 17:44
by pabloalcantara
Thanks @jvdz
If you have any suggestions, fell free to say.
jvdz wrote: Friday 20 July 2018 17:07 This is indeed an interesting approach and fully understand that this needs a more elaborate setup/config description for people starting with MQTT/Node-Red/IFTTT as it does take some effort to install it all correctly.
The basics work quite nicely though so really nicely done!
Thanks for sharing,
Jos

Re: Controlicz Alternative (Node red + ifttt) -Google Home

Posted: Sunday 22 July 2018 23:01
by jvdz
pabloalcantara wrote: Friday 20 July 2018 17:44 Thanks @jvdz
If you have any suggestions, fell free to say.
I have this already running with 3 IFTTT applets:
  • switch $ On -or- change $ On -or- Open $
  • switch $ Off -or- change $ Off -or- Close $
  • Set $ level # -or- Change $ level #
which sends the text to a single Text Sensor with the "Make a Web request" option:
  • IFTTT:{{TextField}}!on
  • IFTTT:{{TextField}}!off
  • IFTTT:{{TextField}}!{{NumberField}}
A lua event script is fired when the text sensor changes in which I've defined the logic for acting upon the receive Device/Action command.
This allowed me to use Regex like logic to cope with variations on the receive text.
I then use a NodeRed process, which monitors another domoticz text sensor, to cast text of the sensor to the Google Home stating whether the command was executed or states it doesn't understand the Devices/Action.

Your solution makes it easier to implement on the existing devices without a lot of programming, ones you've overcome the initial hurdle of going through the implementation steps.

So no real suggestion at this moment other than maybe at some point put this into a Wiki in

Jos

Re: Controlicz Alternative (Node red + ifttt) -Google Home

Posted: Wednesday 25 July 2018 22:21
by curious
I now use IFTTT with google assist and webhook.
Why is it better to use it with node red ? Is it for the ease of adding devices ?

My apoligies for my bad english too :)

Re: Controlicz Alternative (Node red + ifttt) -Google Home

Posted: Wednesday 25 July 2018 22:27
by pabloalcantara
Yes, you com use only Two Applets on iftth e then just adjust the description on your switch on domoticz. Way easier and simples.
The node Red you can create just on time and forget it, and just use domoticz

Re: Controlicz Alternative (Node red + ifttt) -Google Home

Posted: Sunday 12 August 2018 15:07
by dswinton
Hi Guys,

I've put together a script that might be an easier solution for this if you're interested:
https://github.com/dswinton/domo-ifttt

Cheers

Re: Controlicz Alternative (Node red + ifttt) -Google Home

Posted: Wednesday 05 September 2018 18:39
by takomo
Hi,
Thanks for this great idea!
I had one problem with the mqtt message and I want to share my solution for it.
After setting up IFTTT, Node Red, MQTT and Domoticz, I could see the switch commands to change the switch status in Domoticz dashboard, but the actual real life switches did not change state. I realized that the mqtt message {"idx":446,"nvalue":1,"svalue":""} did not switch the actual switches either.
I changed the mqtt message into this:
{"command": "switchlight", "idx":446, "switchcmd": "Off"}
and the code in Read Dictonare accordingly.
And now it works perfectly!

Re: Controlicz Alternative (Node red + ifttt) -Google Home

Posted: Friday 14 September 2018 22:05
by randytsuch
You can do this without IFTTT if you want.
Also without exposing node red to the internet. Alexa will be using the cloud, but it already does.

I added this palette to node red:
https://flows.nodered.org/node/node-red ... lexa-local

Works fine. Add a alexa node to your flow, and then go to alexa.amazon, smart home, devices and discover. You may need to hit discover twice.
You can also ask alexa to discover devices, but I like to see what devices I have.

so then your node should show up as a device.
For instance, I added hallway as an alexa node name.
Discover to have hallway become an alexa device
Now I can say "Alexa, turn on hallway" and the hallway light turns on.
Of course you need to setup the MQTT output to go turn on the light or whatever, but I have a bunch of alexa devices now just for this

Randy

Re: Controlicz Alternative (Node red + ifttt) -Google Home

Posted: Friday 14 September 2018 22:12
by jvdz
That is a nice solution, but Alexa <> Google home, so is this also possible for Google home?

Jos