Domoticz Google Assistant integration with node-red Easy Free Controlicz alternative!

Alexa, Google Home and Siri

Moderator: leecollings

Devious
Posts: 20
Joined: Sunday 30 December 2018 19:02
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: Oss NL
Contact:

Re: Domoticz Google Assistant integration with node-red Easy Free Controlicz alternative!

Post by Devious »

Gravityz wrote: Sunday 22 December 2019 9:28 he means from domoticz to Node-red.

what i would do is make a generic text device, put text in there and let domoticz send a MQTT broadcast for that switch.
i would think the status gets send through MQTT which you can pick up in Node-RED
other option is you let domoticz send a telegram and pick that up in Node-Red
i use telegram to send status updates so that would be perfect for the job
pick the right node in node-red because i remember they are not all the same and simple to operate
i think i used this one node-red-contrib-telegrambot

lot's of options in the settings-notifications from domoticz.
pick something you know can be received in Node-Red
Jep, only the step from domoticz to MQTT is missing for me at the moment.

I made a dummy text device for this purpose. But it's not showing up in the log in domoticz or in MQTT in node-red.

Sinds I'm working with MQTT for the switching I would like to use MQTT for this as well.
Gravityz
Posts: 587
Joined: Wednesday 16 December 2015 19:13
Target OS: NAS (Synology & others)
Domoticz version: 2022.2
Location: Netherlands
Contact:

Re: Domoticz Google Assistant integration with node-red Easy Free Controlicz alternative!

Post by Gravityz »

ok maybe not the best programming example but can you try this one
it is not MQTT based but will get the info in Node-Red

change the ip address,port and idx in the http request module to that of your settings
it should filter out the data part which you then can use to create a mp3 file

it does a http request of the idx of the idx you want (the text device)
it parses to a json node which changes everything to javascript object
it then sets the payload to that of the data field of the idx node
you can do then whatever you like with the payload


[
{
"id": "90f2d9a4.92af28",
"type": "json",
"z": "e10a64e2.5e9688",
"name": "",
"property": "payload",
"action": "obj",
"pretty": false,
"x": 550,
"y": 280,
"wires": [
[
"e7626c46.877cb"
]
]
},
{
"id": "54a7b84b.69d3e8",
"type": "debug",
"z": "e10a64e2.5e9688",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"x": 950,
"y": 280,
"wires": []
},
{
"id": "e7626c46.877cb",
"type": "change",
"z": "e10a64e2.5e9688",
"name": "",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "payload.result.0.Data",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 740,
"y": 280,
"wires": [
[
"54a7b84b.69d3e8"
]
]
},
{
"id": "445d27ef.ecf748",
"type": "http request",
"z": "e10a64e2.5e9688",
"name": "",
"method": "GET",
"ret": "txt",
"paytoqs": false,
"url": "http://192.168.1.50:8084/json.htm?type=devices&rid=256",
"tls": "",
"persist": false,
"proxy": "",
"authType": "",
"x": 370,
"y": 280,
"wires": [
[
"90f2d9a4.92af28"
]
]
},
{
"id": "e146b285.120a9",
"type": "inject",
"z": "e10a64e2.5e9688",
"name": "",
"topic": "",
"payload": "",
"payloadType": "date",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 180,
"y": 280,
"wires": [
[
"445d27ef.ecf748"
]
]
}
]
Gravityz
Posts: 587
Joined: Wednesday 16 December 2015 19:13
Target OS: NAS (Synology & others)
Domoticz version: 2022.2
Location: Netherlands
Contact:

Re: Domoticz Google Assistant integration with node-red Easy Free Controlicz alternative!

Post by Gravityz »

also i checked and when you update a textdevice in domoticz the status is broadcasted so you should have als the info in node-red
Sherlock
Posts: 13
Joined: Friday 21 August 2015 17:22
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: netherlands
Contact:

Re: Domoticz Google Assistant integration with node-red Easy Free Controlicz alternative!

Post by Sherlock »

by pvklink » Sunday 22 December 2019 1:13
i use node-red-contrib-cast to let my nest hub speaker talk
I am using node-red-contrib-cast to send a spoken message when my doorbell is pressed.
I am using the following flow:

Code: Select all

[{"id":"13e317fc.3295e","type":"tab","label":"Flow 4","disabled":false,"info":""},{"id":"617706bf.40a8e","type":"mqtt in","z":"13e317fc.3295e","name":"","topic":"domoticz/out","qos":"2","datatype":"auto","broker":"da355387.6ab0e8","x":130,"y":180,"wires":[["b4e236bf.60b238"]]},{"id":"c716740f.d9cb5","type":"switch","z":"13e317fc.3295e","name":"","property":"payload.idx","propertyType":"msg","rules":[{"t":"eq","v":"47","vt":"num"},{"t":"eq","v":"53","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":430,"y":180,"wires":[["7fd7a2b8.c6210c","6d3a12e5.c7694c"],[]]},{"id":"7fd7a2b8.c6210c","type":"debug","z":"13e317fc.3295e","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":710,"y":174,"wires":[]},{"id":"b4e236bf.60b238","type":"json","z":"13e317fc.3295e","name":"","property":"payload","action":"","pretty":false,"x":290,"y":180,"wires":[["c716740f.d9cb5"]]},{"id":"cb54564d.210728","type":"play audio","z":"13e317fc.3295e","name":"","voice":"1","x":710,"y":240,"wires":[]},{"id":"6d3a12e5.c7694c","type":"change","z":"13e317fc.3295e","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"front door","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":460,"y":240,"wires":[["18cdd70e.aafc89","cb54564d.210728"]]},{"id":"fe164df4.ceead8","type":"googlehome-notify","z":"13e317fc.3295e","server":"b24bbd5a.8161b8","name":"","x":740,"y":300,"wires":[]},{"id":"18cdd70e.aafc89","type":"cast-to-client","z":"13e317fc.3295e","name":"","url":"","contentType":"","message":"hallo","language":"nl","ip":"192.168.0.10","port":"","volume":"70","x":730,"y":360,"wires":[[]]},{"id":"da355387.6ab0e8","type":"mqtt-broker","z":"","name":"mqtt broker testpi","broker":"192.168.0.140","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"b24bbd5a.8161b8","type":"googlehome-config-node","z":"","ipaddress":"192.168.0.10","name":"","language":"nl"}]
The issue however is that it takes approx. 7-8 secs before the text is spoken on my google home mini (after having pressed the virtual doorbell in Domoticz). When I use the 'Play audio' node, the message is heard immediately after pressing the doorbell. So the delay is caused in the node-red-contrib-cast node.

Please, can you tell me what I am doing wrong.

Thanks in advance
pvklink
Posts: 822
Joined: Wednesday 12 November 2014 15:01
Target OS: Raspberry Pi / ODroid
Domoticz version: latest b
Contact:

Re: Domoticz Google Assistant integration with node-red Easy Free Controlicz alternative!

Post by pvklink »

No idea...
I use s nest hub and my local lan (gb) and a quick internet connection
It takes about 2 sec between activate my switch and playing the sound on my hub
cast.jpg
cast.jpg (42.23 KiB) Viewed 3746 times
Raspberry (raspbian on rpi 3) , Domoticz Beta, dzVents , RFXtrx433e, P1, Hue, Yeelight, Zwave+, X10, ESP(easy), MQTT,Weather Underground, System Alive Checker, Domoticz Remote Server to RPI with Google Assistant,
Jablotron connection, Ikea
Sherlock
Posts: 13
Joined: Friday 21 August 2015 17:22
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: netherlands
Contact:

Re: Domoticz Google Assistant integration with node-red Easy Free Controlicz alternative!

Post by Sherlock »

Hi pvklink,
Thank you for your answer. As I told you the delay must have been caused by the node-red-contrib-cast. When I use the ‘play audio’ node I get an instant response.
My lan is also gigabit and my internet connection is 100/20 Mbit/s (SKP in Pijnacker).

An alternative could be to play a local mp3 audio file via node-red on my google home mini (so I don’t have to connect to Google’ servers).
But I don’t exactly know how to do that.
Maybe you or someone else know how to do that?
salvacalatayud
Posts: 112
Joined: Monday 26 June 2017 21:16
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Spain
Contact:

Re: Domoticz Google Assistant integration with node-red Easy Free Controlicz alternative!

Post by salvacalatayud »

Hi, I' testing with Thermostat node, but I can't get it to work.

In the output function I try:

Code: Select all

var idx = parseInt(msg.topic)
var setpoint = msg.payload.setpoint

{
msg.payload = { "idx": idx, "svalue": setpoint};
return [null, msg]
}
In domoticz I get an error of invalid data

Also, in the function node to translate from domoticz to Nora I use:

Code: Select all

msg.topic = msg.payload.idx
var Setset = msg.payload.svalue1
{
    msg.payload = {"setpoint": Setset}
}
    return msg;
But it seems that nothing changes the Nora value


Thanks in advance
EvJd
Posts: 13
Joined: Tuesday 11 February 2020 11:24
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Domoticz Google Assistant integration with node-red Easy Free Controlicz alternative!

Post by EvJd »

Hello,
I used someones flow that posted here to controll my milights with Nora and Domoticz. I am not a programmer at all, I used Kappelt-Gbridge, and needed an alternative.

With this flow I can turn my lights on and off. But my milights are also RGB so I want to add the brightness controll/brightness change/Color support.
But when I check the boxes on, the message that domoticz recieves isn't right anymore. So I think I need to add something to the function out + Gen MQTT on my flow.

Is there somebody who can help me? What should I add to have full posibilities from my milights? Thanks for this forum, I came so far without any programmer skills !

This is my flow for now:

Code: Select all

[{"id":"3c92e734.171818","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"41536b1a.23a72c","type":"mqtt in","z":"3c92e734.171818","name":"","topic":"domoticz/out","qos":"0","datatype":"auto","broker":"c774ffd3.5056a8","x":90,"y":660,"wires":[["d3d38b58.c22548"]]},{"id":"d3d38b58.c22548","type":"json","z":"3c92e734.171818","name":"","property":"payload","action":"","pretty":false,"x":130,"y":300,"wires":[["c1c1221.3dde76"]]},{"id":"c1c1221.3dde76","type":"function","z":"3c92e734.171818","name":"Function In on/off","func":"msg.topic = msg.payload.idx\nif (msg.payload.nvalue === 1)\n{\n    msg.payload = true\n}\nelse if (msg.payload.nvalue === 0)\n{\n    msg.payload = false\n}\n    return msg;","outputs":1,"noerr":0,"x":310,"y":300,"wires":[["e20c4746.7cba2"]]},{"id":"e20c4746.7cba2","type":"switch","z":"3c92e734.171818","name":"","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"112","vt":"str"},{"t":"eq","v":"92","vt":"str"},{"t":"eq","v":"42","vt":"str"},{"t":"eq","v":"151","vt":"str"},{"t":"eq","v":"66","vt":"str"},{"t":"eq","v":"169","vt":"str"},{"t":"eq","v":"170","vt":"str"},{"t":"eq","v":"171","vt":"str"},{"t":"eq","v":"172","vt":"str"},{"t":"eq","v":"173","vt":"str"},{"t":"eq","v":"174","vt":"str"},{"t":"eq","v":"53","vt":"str"},{"t":"eq","v":"155","vt":"str"}],"checkall":"true","repair":false,"outputs":13,"x":510,"y":300,"wires":[[],[],[],[],[],[],["c9a6badd.48a34"],["c423af4b.628d48"],["29a47fec.b643b8"],["536ac963.3a9dd8"],[],[],[]]},{"id":"c9a6badd.48a34","type":"nora-light","z":"3c92e734.171818","devicename":"Woonkamerlamp","lightcolor":false,"brightnesscontrol":true,"turnonwhenbrightnesschanges":false,"passthru":false,"statepayload":true,"brightnessoverride":"","roomhint":"Woonkamer","name":"Woonkamerlamp","nora":"ee0cddb4.0c0618","topic":"7","onvalue":"true","onvalueType":"bool","offvalue":"false","offvalueType":"bool","x":790,"y":120,"wires":[["b26b1405.3cd0a"]]},{"id":"b26b1405.3cd0a","type":"function","z":"3c92e734.171818","name":"Function Out ON/OFF","func":"var idx = msg.topic\nif ( msg.payload === true )\n{\nmsg.payload = { \"command\": \"switchlight\", \"idx\": idx, \"switchcmd\": \"On\" };\n}\nelse if ( msg.payload === false )\n{\nmsg.payload = { \"command\": \"switchlight\", \"idx\": idx, \"switchcmd\": \"Off\" };\n}\nreturn msg\n","outputs":1,"noerr":0,"x":1020,"y":280,"wires":[["97ed54ee.bdb78"]]},{"id":"97ed54ee.bdb78","type":"template","z":"3c92e734.171818","name":"Gen MQTT On/Off","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\"command\": \"switchlight\", \"idx\": {{payload.idx}}, \"switchcmd\": \"{{payload.switchcmd}}\" }","output":"str","x":1230,"y":280,"wires":[["e285baf1.c8221"]]},{"id":"e285baf1.c8221","type":"mqtt out","z":"3c92e734.171818","name":"","topic":"domoticz/in","qos":"","retain":"","broker":"c774ffd3.5056a8","x":1290,"y":360,"wires":[]},{"id":"c423af4b.628d48","type":"nora-light","z":"3c92e734.171818","devicename":"Eettafellamp","lightcolor":false,"brightnesscontrol":false,"turnonwhenbrightnesschanges":false,"passthru":false,"statepayload":true,"brightnessoverride":"","roomhint":"Woonkamer","name":"Eettafellamp","nora":"ee0cddb4.0c0618","topic":"8","onvalue":"true","onvalueType":"bool","offvalue":"false","offvalueType":"bool","x":770,"y":220,"wires":[["b26b1405.3cd0a"]]},{"id":"29a47fec.b643b8","type":"nora-light","z":"3c92e734.171818","devicename":"Keukenlamp","lightcolor":false,"brightnesscontrol":false,"turnonwhenbrightnesschanges":false,"passthru":false,"statepayload":true,"brightnessoverride":"","roomhint":"Woonkamer","name":"Keukenlamp","nora":"ee0cddb4.0c0618","topic":"9","onvalue":"true","onvalueType":"bool","offvalue":"false","offvalueType":"bool","x":770,"y":300,"wires":[["b26b1405.3cd0a"]]},{"id":"536ac963.3a9dd8","type":"nora-light","z":"3c92e734.171818","devicename":"Slaapkamerlamp","lightcolor":false,"brightnesscontrol":false,"turnonwhenbrightnesschanges":false,"passthru":false,"statepayload":true,"brightnessoverride":"","roomhint":"Slaapkamer","name":"Slaapkamerlamp","nora":"ee0cddb4.0c0618","topic":"10","onvalue":"true","onvalueType":"bool","offvalue":"false","offvalueType":"bool","x":800,"y":420,"wires":[["b26b1405.3cd0a","8a1a9da.bb3cc6"]]},{"id":"8a1a9da.bb3cc6","type":"debug","z":"3c92e734.171818","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1080,"y":460,"wires":[]},{"id":"c774ffd3.5056a8","type":"mqtt-broker","broker":"localhost","port":"1883","clientid":""},{"id":"ee0cddb4.0c0618","type":"nora-config","z":"","name":"nora config","group":""}]
User avatar
FireWizard
Posts: 1863
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Domoticz Google Assistant integration with node-red Easy Free Controlicz alternative!

Post by FireWizard »

Hello.

@salvacalatayud

See the information pane.
The output payload for the "Thermostat" node indicates the following:
setpoint - number. Setpoint temperature in degrees celsius; (if mode is not 'heatcool').
So your setpoint is a number and not a string.
You can change

Code: Select all

msg.payload = { "idx": idx, "svalue": setpoint};
into

Code: Select all

msg.payload = { "idx": idx, "svalue": (setpoint.toString())};
or even

Code: Select all

msg.payload = { "idx": idx, "svalue": (msg.payload.setpoint.toString())};
and then you can omit the 2nd line (var setpoint = msg.payload.setpoint).

I also do not understand the last line.

Code: Select all

return [null, msg]
I think

Code: Select all

return msg
is sufficient.

If this does not work, can you post your flow?

Regards
User avatar
FireWizard
Posts: 1863
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Domoticz Google Assistant integration with node-red Easy Free Controlicz alternative!

Post by FireWizard »

Hello,

@EvJd

Welcome on this forum.

You wrote:
With this flow I can turn my lights on and off
Yes, this flow was just made for it and not more.
But my milights are also RGB so I want to add the brightness controll/brightness change/Color support.
The in/output function should be extended. See: https://www.domoticz.com/wiki/MQTT
{"command": "switchlight", "idx": 2450, "switchcmd": "On" }
{"command": "switchlight", "idx": 2450, "switchcmd": "Set Level", "level": 100 }
{"command": "setcolbrightnessvalue", "idx": 2450, "hue": 274, "brightness": 40, "iswhite": false }
{"command": "setcolbrightnessvalue", "idx": 2450, "hex": "RRGGBB", "brightness": 100, "iswhite": false }
{"command": "setcolbrightnessvalue", "idx": 2450, "color": {"m":3,"t":0,"r":0,"g":0,"b":50,"cw":0,"ww":0}, "brightness": 40}
See also: https://www.domoticz.com/wiki/Domoticz_API/JSON_URL%27s

So you have to select, what you need.
One other thing: You can replace your template node, called "Gen MQTT On/Off", with a json node. (Identical to the first one).

Can you connect a debug node after the first json node and post its output, if you operate the "Slaapkamerlamp".
Post also the output of the currently connected debug node.

But, isn't it easier to control your Milight not directly from Google Assistant instead of using nora and Domoticz?
https://www.milight-nederland.nl/nl/pro ... z-gateway/

Regards
EvJd
Posts: 13
Joined: Tuesday 11 February 2020 11:24
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Domoticz Google Assistant integration with node-red Easy Free Controlicz alternative!

Post by EvJd »

Hello! Thanks a lot! I will add it to my flow and hope this takes me a step further

I allready bought the gateway you refered to, because of the kappelt bridge server that was down a lot and I needed something instead. Unfurtunaly the gateway only let me control all my milights at once and no seperate lights .
EvJd
Posts: 13
Joined: Tuesday 11 February 2020 11:24
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Domoticz Google Assistant integration with node-red Easy Free Controlicz alternative!

Post by EvJd »

FireWizard wrote: Tuesday 11 February 2020 14:38 Hello,

@EvJd

Welcome on this forum.

You wrote:
With this flow I can turn my lights on and off
Yes, this flow was just made for it and not more.
But my milights are also RGB so I want to add the brightness controll/brightness change/Color support.
The in/output function should be extended. See: https://www.domoticz.com/wiki/MQTT
{"command": "switchlight", "idx": 2450, "switchcmd": "On" }
{"command": "switchlight", "idx": 2450, "switchcmd": "Set Level", "level": 100 }
{"command": "setcolbrightnessvalue", "idx": 2450, "hue": 274, "brightness": 40, "iswhite": false }
{"command": "setcolbrightnessvalue", "idx": 2450, "hex": "RRGGBB", "brightness": 100, "iswhite": false }
{"command": "setcolbrightnessvalue", "idx": 2450, "color": {"m":3,"t":0,"r":0,"g":0,"b":50,"cw":0,"ww":0}, "brightness": 40}
See also: https://www.domoticz.com/wiki/Domoticz_API/JSON_URL%27s

So you have to select, what you need.
One other thing: You can replace your template node, called "Gen MQTT On/Off", with a json node. (Identical to the first one).

Can you connect a debug node after the first json node and post its output, if you operate the "Slaapkamerlamp".
Post also the output of the currently connected debug node.

But, isn't it easier to control your Milight not directly from Google Assistant instead of using nora and Domoticz?
https://www.milight-nederland.nl/nl/pro ... z-gateway/

Regards
Thanks for your help, I added the command in the in/output function, but think I am missing something, cause it immediately lets me see a red triangle.
I attached flow:

Code: Select all

[{"id":"3c92e734.171818","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"41536b1a.23a72c","type":"mqtt in","z":"3c92e734.171818","name":"","topic":"domoticz/out","qos":"0","datatype":"auto","broker":"bbb8a5f8.078ff","x":90,"y":660,"wires":[["d3d38b58.c22548"]]},{"id":"d3d38b58.c22548","type":"json","z":"3c92e734.171818","name":"","property":"payload","action":"","pretty":false,"x":130,"y":300,"wires":[["c1c1221.3dde76","8f1008e.edf9bf8"]]},{"id":"c1c1221.3dde76","type":"function","z":"3c92e734.171818","name":"Function In on/off","func":"msg.topic = msg.payload.idx\nif (msg.payload.nvalue === 1)\n{\n    msg.payload = true\n}\nelse if (msg.payload.nvalue === 0)\n{\n    msg.payload = false\n}\n{\"command\": \"switchlight\", \"idx\": 2450, \"switchcmd\": \"On\" }\n{\"command\": \"switchlight\", \"idx\": 2450, \"switchcmd\": \"Set Level\", \"level\": 100 }\n{\"command\": \"setcolbrightnessvalue\", \"idx\": 2450, \"hue\": 274, \"brightness\": 40, \"iswhite\": false }\n{\"command\": \"setcolbrightnessvalue\", \"idx\": 2450, \"hex\": \"RRGGBB\", \"brightness\": 100, \"iswhite\": false }\n{\"command\": \"setcolbrightnessvalue\", \"idx\": 2450, \"color\": {\"m\":3,\"t\":0,\"r\":0,\"g\":0,\"b\":50,\"cw\":0,\"ww\":0}, \"brightness\": 40} \n    return msg;","outputs":1,"noerr":11,"x":310,"y":300,"wires":[["e20c4746.7cba2"]]},{"id":"e20c4746.7cba2","type":"switch","z":"3c92e734.171818","name":"","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"112","vt":"str"},{"t":"eq","v":"92","vt":"str"},{"t":"eq","v":"42","vt":"str"},{"t":"eq","v":"151","vt":"str"},{"t":"eq","v":"66","vt":"str"},{"t":"eq","v":"169","vt":"str"},{"t":"eq","v":"170","vt":"str"},{"t":"eq","v":"171","vt":"str"},{"t":"eq","v":"172","vt":"str"},{"t":"eq","v":"173","vt":"str"},{"t":"eq","v":"174","vt":"str"},{"t":"eq","v":"53","vt":"str"},{"t":"eq","v":"155","vt":"str"}],"checkall":"true","repair":false,"outputs":13,"x":510,"y":300,"wires":[[],[],[],[],[],[],["c9a6badd.48a34"],["c423af4b.628d48"],["29a47fec.b643b8"],["536ac963.3a9dd8"],[],[],[]]},{"id":"c9a6badd.48a34","type":"nora-light","z":"3c92e734.171818","devicename":"Woonkamerlamp","lightcolor":false,"brightnesscontrol":true,"turnonwhenbrightnesschanges":false,"passthru":false,"statepayload":true,"brightnessoverride":"","roomhint":"Woonkamer","name":"Woonkamerlamp","nora":"ee0cddb4.0c0618","topic":"7","onvalue":"true","onvalueType":"bool","offvalue":"false","offvalueType":"bool","x":790,"y":120,"wires":[["b26b1405.3cd0a"]]},{"id":"b26b1405.3cd0a","type":"function","z":"3c92e734.171818","name":"Function Out ON/OFF","func":"var idx = msg.topic\nif ( msg.payload === true )\n{\nmsg.payload = { \"command\": \"switchlight\", \"idx\": idx, \"switchcmd\": \"On\" };\n}\nelse if ( msg.payload === false )\n{\nmsg.payload = { \"command\": \"switchlight\", \"idx\": idx, \"switchcmd\": \"Off\" };\n}\n{\"command\": \"switchlight\", \"idx\": 2450, \"switchcmd\": \"On\" }\n{\"command\": \"switchlight\", \"idx\": 2450, \"switchcmd\": \"Set Level\", \"level\": 100 }\n{\"command\": \"setcolbrightnessvalue\", \"idx\": 2450, \"hue\": 274, \"brightness\": 40, \"iswhite\": false }\n{\"command\": \"setcolbrightnessvalue\", \"idx\": 2450, \"hex\": \"RRGGBB\", \"brightness\": 100, \"iswhite\": false }\n{\"command\": \"setcolbrightnessvalue\", \"idx\": 2450, \"color\": {\"m\":3,\"t\":0,\"r\":0,\"g\":0,\"b\":50,\"cw\":0,\"ww\":0}, \"brightness\": 40} \nreturn msg\n","outputs":1,"noerr":11,"x":1020,"y":280,"wires":[["97ed54ee.bdb78"]]},{"id":"97ed54ee.bdb78","type":"template","z":"3c92e734.171818","name":"Gen MQTT On/Off","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\"command\": \"switchlight\", \"idx\": {{payload.idx}}, \"switchcmd\": \"{{payload.switchcmd}}\" }","output":"str","x":1230,"y":280,"wires":[["e285baf1.c8221"]]},{"id":"e285baf1.c8221","type":"mqtt out","z":"3c92e734.171818","name":"","topic":"domoticz/in","qos":"","retain":"","broker":"c774ffd3.5056a8","x":1290,"y":360,"wires":[]},{"id":"c423af4b.628d48","type":"nora-light","z":"3c92e734.171818","devicename":"Eettafellamp","lightcolor":false,"brightnesscontrol":false,"turnonwhenbrightnesschanges":false,"passthru":false,"statepayload":true,"brightnessoverride":"","roomhint":"Woonkamer","name":"Eettafellamp","nora":"ee0cddb4.0c0618","topic":"8","onvalue":"true","onvalueType":"bool","offvalue":"false","offvalueType":"bool","x":770,"y":220,"wires":[["b26b1405.3cd0a"]]},{"id":"29a47fec.b643b8","type":"nora-light","z":"3c92e734.171818","devicename":"Keukenlamp","lightcolor":false,"brightnesscontrol":false,"turnonwhenbrightnesschanges":false,"passthru":false,"statepayload":true,"brightnessoverride":"","roomhint":"Woonkamer","name":"Keukenlamp","nora":"ee0cddb4.0c0618","topic":"9","onvalue":"true","onvalueType":"bool","offvalue":"false","offvalueType":"bool","x":770,"y":300,"wires":[["b26b1405.3cd0a"]]},{"id":"536ac963.3a9dd8","type":"nora-light","z":"3c92e734.171818","devicename":"Slaapkamerlamp","lightcolor":false,"brightnesscontrol":false,"turnonwhenbrightnesschanges":false,"passthru":false,"statepayload":true,"brightnessoverride":"","roomhint":"Slaapkamer","name":"Slaapkamerlamp","nora":"ee0cddb4.0c0618","topic":"10","onvalue":"true","onvalueType":"bool","offvalue":"false","offvalueType":"bool","x":800,"y":420,"wires":[["b26b1405.3cd0a","8a1a9da.bb3cc6"]]},{"id":"8a1a9da.bb3cc6","type":"debug","z":"3c92e734.171818","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1080,"y":460,"wires":[]},{"id":"8f1008e.edf9bf8","type":"debug","z":"3c92e734.171818","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":280,"y":400,"wires":[]},{"id":"bbb8a5f8.078ff","type":"mqtt-broker","z":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"ee0cddb4.0c0618","type":"nora-config","z":"","name":"nora config","group":""},{"id":"c774ffd3.5056a8","type":"mqtt-broker","broker":"localhost","port":"1883","clientid":""}]
Also attached the debug:
The one connected to slaapkamerlamp says "true".

The one connected to JSON: {"Battery":255,"Color":{"b":182,"cw":0,"g":248,"m":3,"r":255,"t":0,"ww":0},"Level":73,"RSSI":12,"description":"gBridge-Slaapkamerlamp","dtype":"Color Switch","id":"1","idx":10,"name":"Slaapkamerlamp","nvalue":1,"stype":"RGBWW","svalue1":"73","switchType":"Dimmer","unit":4}
User avatar
FireWizard
Posts: 1863
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Domoticz Google Assistant integration with node-red Easy Free Controlicz alternative!

Post by FireWizard »

@EvJd

You wrote:
I allready bought the gateway you refered to, because of the kappelt bridge server that was down a lot and I needed something instead. Unfurtunaly the gateway only let me control all my milights at once and no seperate lights .
You have seen this: https://ehoco.nl/milight-ibox2-installeren-domoticz/?

It is pity that it does not work, so you have to use nora.

Another link that may be of interest: https://www.domoticz.com/wiki/Limitless/AppLamp_LED.
I added the command in the in/output function, but think I am missing something, cause it immediately lets me see a red triangle.
I attached flow:
You should not add all commands, but you should select one.

As you see, the first command corresponds with the one you already had and is for On/Off lights only
The second command is for only dimmable lights.

To set a light to a certain color or color temperature, you have several options. See: https://www.domoticz.com/wiki/Domoticz_ ... emperature.

As I do not own a MiLight lamp so I have to rely on what you post.

The MiLight lamp publishes the following:

Code: Select all

{"Battery":255,"Color":{"b":182,"cw":0,"g":248,"m":3,"r":255,"t":0,"ww":0},"Level":73,"RSSI":12,"description":"gBridge-Slaapkamerlamp","dtype":"Color Switch","id":"1","idx":10,"name":"Slaapkamerlamp","nvalue":1,"stype":"RGBWW","svalue1":"73","switchType":"Dimmer","unit":4}
And that means that we have to use the last command.
{"command": "setcolbrightnessvalue", "idx": 2450, "color": {"m":3,"t":0,"r":0,"g":0,"b":50,"cw":0,"ww":0}, "brightness": 40}
I will see, what I can do, but I'm not able to test it.

Regards
EvJd
Posts: 13
Joined: Tuesday 11 February 2020 11:24
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Domoticz Google Assistant integration with node-red Easy Free Controlicz alternative!

Post by EvJd »

Thanks a lot, will take a look tomorrow.
Yes the topics I used for getting the milights into domoticz.

That works great!
I need Nora to communicate between domoticz and google home (speech).
So great you help me so much!!!!
salvacalatayud
Posts: 112
Joined: Monday 26 June 2017 21:16
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Spain
Contact:

Re: Domoticz Google Assistant integration with node-red Easy Free Controlicz alternative!

Post by salvacalatayud »

FireWizard wrote: Tuesday 11 February 2020 13:54 Hello.

@salvacalatayud

See the information pane.
The output payload for the "Thermostat" node indicates the following:
setpoint - number. Setpoint temperature in degrees celsius; (if mode is not 'heatcool').
So your setpoint is a number and not a string.
You can change

Code: Select all

msg.payload = { "idx": idx, "svalue": setpoint};
into

Code: Select all

msg.payload = { "idx": idx, "svalue": (setpoint.toString())};
or even

Code: Select all

msg.payload = { "idx": idx, "svalue": (msg.payload.setpoint.toString())};
and then you can omit the 2nd line (var setpoint = msg.payload.setpoint).

I also do not understand the last line.

Code: Select all

return [null, msg]
I think

Code: Select all

return msg
is sufficient.

If this does not work, can you post your flow?

Regards
It is working now, I will share my flow when it is fine.
Last edited by salvacalatayud on Tuesday 11 February 2020 19:24, edited 1 time in total.
salvacalatayud
Posts: 112
Joined: Monday 26 June 2017 21:16
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Spain
Contact:

Re: Domoticz Google Assistant integration with node-red Easy Free Controlicz alternative!

Post by salvacalatayud »

Gravityz wrote: Monday 11 November 2019 18:40 made a second change.

I noticed that whenever you change the flow and press deploy you loose the current status of all the devices.(and i can not believe this does not bother anybody because it is very annoying)

@waaren created a domoticz script which broadcasts the status when a virtual switch is switched.

I made a flow which calls on that switch and instantly restores the current status of the flow(all lights which were ON are shown as ON again including the levels).

here is the flow(change idx and ip address to match your settings)

Code: Select all

[{"id":"9eada173.2ec46","type":"inject","z":"7c0e1d2a.588314","name":"collect current light status","topic":"","payload":"Started!","payloadType":"str","repeat":"","crontab":"","once":true,"onceDelay":"","x":150,"y":40,"wires":[["8bf5316c.1546f"]]},{"id":"8bf5316c.1546f","type":"http request","z":"7c0e1d2a.588314","name":"MQTT-Broadcast-Domoticz","method":"POST","ret":"txt","paytoqs":false,"url":"http://192.168.1.50:8084/json.htm?type=command&param=switchlight&idx=334&switchcmd=On","tls":"","persist":false,"proxy":"","authType":"","x":460,"y":40,"wires":[["3495cdb9.881a72"]]},{"id":"3495cdb9.881a72","type":"debug","z":"7c0e1d2a.588314","name":"","active":true,"tosidebar":true,"console":false,"complete":"false","x":710,"y":40,"wires":[]}]
here is the domoticz dzVents script. change the variables to adapt it to your situation
You also have to create a virtual switch and give it the name MQTT-Broadcast

Code: Select all

--[[ dumpMQTT for all switch type devices 

    this dzVents script sends current status of all switch-type devices with ()optionally) the string mqttsync in the descriptionfield to 
    the defined mqtt broker with the topic domoticz/out in the same json format as domoticz mqtt hardware sends it on a device update
    it uses the mosquitto_pub OS program for this.

    configurable items: 
                            MQTTBokerhost   // hostnamae or IP where MQTT Broker is active   ; defaults to localhost
                            mosquitto_pub   // location of full /path/executable             ; defaults to /usr/bin/moquitto_pub
                            MQTTTopic       // MQTT topic to be used                         ; defaults to domoticz/out
                            MQTTSyncTrigger // string in description-field of device to enable syncTrigger ; defaults to All switch type devices           

    Thanks to @Gravityz for the initial idea, testing-, and feedback.
    
]]--

local scriptTrigger = 'MQTT-Broadcast'

return 
{
    on = 
    {
        -- timer = {'every 10 minutes'}, -- when frequent broadcasts are required
        devices = { scriptTrigger },
    },

    logging = { level = domoticz.LOG_ERROR }, -- switch to LOG_DEBUG when not eoowrking as expected

    execute = function(dz)
        
       -- ************** Your settings (when not default) below this line *********************

        local MQTTBrokerHost  
        local MQTTTopic 
        local mosquitto_pub                   -- set to '/volume1/@appstore/mosquitto/bin/mosquitto_pub' for Synology NAS
        local MQTTSyncTrigger                -- only sync switches with this string in description field leave as nil when all need to be syncd

      -- ************** No changes required below this line ************************
      
       -- set defaults 
        _G.logMarker =  _G.logMarker or _G.moduleLabel -- set logmarker to scriptname
             
        local MQTTBrokerHost = MQTTBokerHost or 'localhost'
        local MQTTTopic = MQTTTopic or 'domoticz/out'
        local mosquitto_pub = mosquitto_pub or '/usr/bin/mosquitto_pub'
        local MQTTSyncTrigger = MQTTSyncTrigger ~= nil and MQTTSyncTrigger  
       
       local function osCommand(cmd)
            dz.log('Executing Command: ' .. cmd,dz.LOG_DEBUG)

            local fileHandle = assert(io.popen(cmd .. ' 2>&1 || echo ::ERROR::', 'r'))
            local commandOutput = assert(fileHandle:read('*a'))
            local returnTable = {fileHandle:close()}

            if commandOutput:find '::ERROR::' then     -- something went wrong
               dz.log('Error ==>> ' .. tostring(commandOutput:match('^(.*)%s+::ERROR::') or ' ... but no error message ' ) ,dz.LOG_ERROR)
            else -- all is fine!!
                dz.log('ReturnCode: ' .. returnTable[3] .. '\ncommandOutput:\n' .. commandOutput, dz.LOG_DEBUG)
            end

            return commandOutput,returnTable[3] -- rc[3] contains returnCode
        end

        local function composeMQTT(dv)
            local json = {}

           if dv.deviceSubType == 'Selector Switch' then
                json.LevelActions = dv.levelActions
                json.LevelNames = table.concat(dv.levelNames,'|')
                json.LevelOffHidden = dv.levelOffHidden
                json.SelectorStyle = "0"
                json.svalue1 = dv.levelVal
            elseif dv.switchType == 'Dimmer' then
                json.Level = dv.level 
            end

            if dv.color ~= '' then
                json.Color = dz.utils.fromJSON(dv.color) 
            end

            if not(json.svalue1) then
                for key, value in ipairs(dv.rawData) do
                    json['svalue' .. key] = value:match('%d+%.*%d*') 
                end 
            end

            json.battery = (dv.batteryLevel or 255)
            json.RSSI = (dv.signalLevel or 12) 
            json.description = (dv.description):sub(0,99)
            json.dtype = dv.deviceType
            json.id = dv.deviceId
            json.idx = dv.id
            json.name = dv.name
            json.nvalue = dv.nValue
            json.stype = dv.deviceSubType
            json.switchType = dv.switchType
            json.unit = (dv.unit or 1)

            json = dz.utils.toJSON(json)
            
            local jsonFormatted = json:gsub(',',',\n  '):gsub('}','\n }'):gsub('{','{ \n  '):gsub(':',' : ')
            dz.log('Composed json: ' .. jsonFormatted,dz.LOG_DEBUG)
            return ( mosquitto_pub ..  ' -h '.. MQTTBrokerHost  .. ' -t '  .. MQTTTopic .. " -m '" .. jsonFormatted .. "'")
        end

        -- Main code
        dz.devices().forEach(function(dv) -- loop over all devices in domoticz instance
            -- All switch like devices ( with ( optionally ) MQTTSyncTrigger in description )  
            if (dv.deviceType or ''):find('witch') and ( not(MQTTSyncTrigger) or dv.description:find(MQTTSyncTrigger)) then 
                dz.log(dv.id .. ', ' .. dv.name .. ', ' .. dv.deviceSubType,dz.LOG_DEBUG) 
                osCommand(composeMQTT(dv))
            end
        end)
    end
}
Is there any way to add temperature and thermostat setpoint to your script?

Thanks
User avatar
FireWizard
Posts: 1863
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Domoticz Google Assistant integration with node-red Easy Free Controlicz alternative!

Post by FireWizard »

Hi,

@EvJd

You wrote:
I need Nora to communicate between domoticz and google home (speech).
I think you need communication between Domoticz and the "nora node" and also communication between the "nora node" and Domoticz.

It is important that the status of the "nora node" is synchronized with Domoticz. That means that, if you switch on your light with a Switch in Domoticz that "nora" knows that the Switch is "On" and vice versa. Google Assistant will not switch a lamp to "On", while the "nora node" has still the "On" status, but the lamp is "Off". In that case you have to switch it to "Off" with Google Assistant, before you can switch it to "On". So Google Assistant will not switch lights "On", if the "nora node" has still the status "On". and will not switch "Off" if the status is already "Off".

This may cause a problem if you "deploy" a flow (not for every deploy). In this case all statusses are initialized to "Off".

Therefore @waaren made an excellent script that can synchronize all the devices

The disadvantage is that it requires a switch to activate the script. You might want to consider to activate that script with a voice command from Google Assistant (e.g. by IFTTT) and a text, such as "Synchronize Devices".

An alternative is to save the state of the "nora node". It even survives a reboot of your Raspberry Pi.

See: https://flows.nodered.org/node/node-red-contrib-persist

The disadvantage of this is that it does not save per topic, and so requires 2 nodes (persist in and persist out) for each "nora node".
Another disadvantage is that it causes extra writes to your SD-card.

In a separate post I will describe the node red solution to control the MiLight.

Regards
xury
Posts: 48
Joined: Monday 10 December 2018 23:32
Target OS: Linux
Domoticz version:
Location: Poland
Contact:

Re: Domoticz Google Assistant integration with node-red Easy Free Controlicz alternative!

Post by xury »

Take a look my nora usage and control switches, lights, Panasonic TV etc.:
As you see nora nodes are between domoticz/out and domoticz/in topics.
On the second screen is to control RGBCCT led strips using milight hub plugin https://www.domoticz.com/forum/viewtopic.php?t=27771
nodered.png
nodered.png (238.42 KiB) Viewed 3555 times
noderedl.png
noderedl.png (181.48 KiB) Viewed 3555 times
If someone interested I can share my flows, but before I have to make sure not leave any tokens etc.
I use more than 50 nora nodes.
User avatar
FireWizard
Posts: 1863
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Domoticz Google Assistant integration with node-red Easy Free Controlicz alternative!

Post by FireWizard »

Hi,

@xury

Impressive picture. :o

@EvJd

As promised, I will share my solution.

I had to test it in a full operational environment and therefore I will not distribute the MQTT input and MQTT output nodes, as this will interfere with your MQTT configuration.

I tested it with a virtual switch, which gave the same MQTT response, as you presented.

Screenshot_Button_Test_MiLight.png
Screenshot_Button_Test_MiLight.png (64.81 KiB) Viewed 3549 times

As you click on the 3 colored cubes, the screen with the color selector will open.

Screenshot_ColorCircle_Test_MiLight.png
Screenshot_ColorCircle_Test_MiLight.png (95.14 KiB) Viewed 3549 times

You have to select the left circle. The right circle is for cool white and warm white, but will not function for this light.

In my flow, I use, beside the "nora" node, 2 other non core nodes.

I prefer to use a filter node, in order to prevent that topics not related to the flow are giving error messages.
For the filter node, you have to load "node-red-contrib-filter" from the "Manage palette" option in the top right menu.
More info: https://flows.nodered.org/node/node-red-contrib-filter.

As Domoticz uses RGB colors and "nora" uses HSV(Hue, Saturation and Value) I use a Color converter node.
I see that @xury uses a function node for it. However the calculation is quite complex.
So load the "node-red-contrib-color-convert" node from the library to your palette.
See: https://flows.nodered.org/node/node-red ... or-convert.

If you have installed these 2 non core nodes, you can import the flow.
Be aware that the configuration of the "nora" node might interfere with your configuration.

So, after import, pick up the left part of the flow and connect it to the input of the "nora" node and then pick the right part and connect it to the output of the "nora" node.

The flow will be published and described in the next post.
xury
Posts: 48
Joined: Monday 10 December 2018 23:32
Target OS: Linux
Domoticz version:
Location: Poland
Contact:

Re: Domoticz Google Assistant integration with node-red Easy Free Controlicz alternative!

Post by xury »

Yes I use function.
I think in better than node-red-contrib-color-convert
I can show these functions:
RGB to HSV

Code: Select all

function rgb2hsv (r, g, b) {
    let rabs, gabs, babs, rr, gg, bb, h, s, v, diff, diffc, percentRoundFn;
    rabs = r / 255;
    gabs = g / 255;
    babs = b / 255;
    v = Math.max(rabs, gabs, babs),
    diff = v - Math.min(rabs, gabs, babs);
    diffc = c => (v - c) / 6 / diff + 1 / 2;
    percentRoundFn = num => Math.round(num * 100) / 100;
    if (diff === 0) {
        h = s = 0;
    } else {
        s = diff / v;
        rr = diffc(rabs);
        gg = diffc(gabs);
        bb = diffc(babs);

        if (rabs === v) {
            h = bb - gg;
        } else if (gabs === v) {
            h = (1 / 3) + rr - bb;
        } else if (babs === v) {
            h = (2 / 3) + gg - rr;
        }
        if (h < 0) {
            h += 1;
        }else if (h > 1) {
            h -= 1;
        }
    }
    return {
        hue: Math.round(h * 360),
        saturation: percentRoundFn(s),
        value: percentRoundFn(v)
    };
}
if (typeof msg.payload.color === 'undefined') {
    msg.payload.color = {};
}

msg.payload.color.spectrumHsv = {};
msg.payload.color.spectrumHsv = rgb2hsv(msg.payload.color.r,msg.payload.color.g,msg.payload.color.b);
return msg;

HSV to RGB

Code: Select all

function mix(a, b, v)
{
    return (1-v)*a + v*b;
}

function HSVtoRGB(H, S, V)
{
    var V2 = V * (1 - S);
    var r  = ((H>=0 && H<=60) || (H>=300 && H<=360)) ? V : ((H>=120 && H<=240) ? V2 : ((H>=60 && H<=120) ? mix(V,V2,(H-60)/60) : ((H>=240 && H<=300) ? mix(V2,V,(H-240)/60) : 0)));
    var g  = (H>=60 && H<=180) ? V : ((H>=240 && H<=360) ? V2 : ((H>=0 && H<=60) ? mix(V2,V,H/60) : ((H>=180 && H<=240) ? mix(V,V2,(H-180)/60) : 0)));
    var b  = (H>=0 && H<=120) ? V2 : ((H>=180 && H<=300) ? V : ((H>=120 && H<=180) ? mix(V2,V,(H-120)/60) : ((H>=300 && H<=360) ? mix(V,V2,(H-300)/60) : 0)));

    return {
        r : Math.round(r * 255),
        b : Math.round(b * 255),
        g : Math.round(g * 255)
    };
}
//msg.payload.Color = {};
msg.payload.color = HSVtoRGB(msg.payload.color.spectrumHsv.hue, msg.payload.color.spectrumHsv.saturation, msg.payload.color.spectrumHsv.value);

return msg;
In my opinion is faster than node-red-contrib-color-convert
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest