While searching i came across this solution, and within 1 day i had this working flawlessy, directly from Google home to Domoticz.
You can find the Node-red nodes page here, including a very good instruction how to set this up.
https://www.npmjs.com/package/node-red- ... -smarthome
The only thing you realy need is a (sub)domain name, that you can redirect to your home ip address. (point A-record to your home ip..)
A number ip address will not work, because google needs a secure connection, and you can only secure domain names, not numbered ip addresses.
I use a Raspberry Pi for Domoticz and Node-red, and have 1 port forwarded in my modem to this Pi.
The only problem i had was with securing my connection, but after many tries i had this secure connection established with my pi.
(losening the directory permissions where the keys are located was the solution, so Node-red had permission to find the secure keys)
So now when i give a command to my Google Nest, Google return a action to my Raspberry Pi, this goes to Node-Red, and Node-Red send a action to Domticz.
1. this switch node get the status for the Google home devices in Domticz.
2. this node convert the domoticz output to Google home input. Like this for a dimmer..
Code: Select all
var aan = msg.payload.nvalue;
var dim = msg.payload.Level;
if (aan === 1) {
msg.payload = {
on: true,
brightness: dim
}
return msg;
}
else if (aan === 0) {
msg.payload = {
on: false,
brightness: dim
}
return msg;
}
else if (aan === 2) {
msg.payload = {
on: true,
brightness: dim
}
return msg;
}
3. are the Google home nodes. When you create a node, a device is automatic added to your Google home app and can be controlled by his name.
4. is converting the Google home node output, to Domticz input. Like this for a dimmer..
Code: Select all
var aan = msg.payload.on;
var dim = msg.payload.brightness;
var idx = 126;
if (aan === true){
msg.payload = {"command": "switchlight", "idx": idx, "switchcmd": "Set Level", "level": dim};
} else {
msg.payload = {"command": "switchlight", "idx": idx, "switchcmd": "Off"};
}
return msg;
(Otherwise you have the risc for looping outputs and inputs in Node-red.)
Code: Select all
if (device.name == 'sh-Lamp bank') then
local lamp = domoticz.devices('Lamp bank')
if (lamp.state ~= device.state) then
if (device.state == 'On') then
lamp.switchOn()
else
lamp.switchOff()
end
end
if (lamp.level ~= device.level) then
lamp.setLevel(device.level)
end
end
Code: Select all
// init device statussen
msg.payload = {"command" : "customevent", "event" : "InitSmarthome" , "data" : "init devices Smarthome" };
return msg;
Code: Select all
sw = domoticz.devices('Lamp bank')
if (sw.state == 'On') then
sw.switchOn()
else
sw.switchOff()
end