Google home <-> Node-red <-> Domoticz (without 3rd party)

Moderator: leecollings

Post Reply
marchutt
Posts: 12
Joined: Monday 06 July 2020 5:12
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Netherlands
Contact:

Google home <-> Node-red <-> Domoticz (without 3rd party)

Post by marchutt »

I was searching for a way to combine my Google Nest mini with Domoticz and didn't want a 3rd party site in between.
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.
Image

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;
}
If a device status is changed in Domoticz, this will also be updated within Google home.
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;
For every controlled device in Domoticz, i have added a dummy device that get the output from Node-red. When this dummy device is called, it will check the status of the real device, and change this if needed. This works the most stable for controlling the devices with the Google home flow..
(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
5. is triggered one time when you have changed the nodes and deploy the flow again. This node will call a custom event in Domoticz.

Code: Select all

// init device statussen

msg.payload = {"command" : "customevent", "event" : "InitSmarthome" , "data" : "init devices Smarthome" };       

return msg;
The custom event update the devices with the same status that they allready have. The status is then send to Node-red (1) and the Google home nodes (3) will be updated with the actual status.

Code: Select all

sw = domoticz.devices('Lamp bank')
if (sw.state == 'On') then
	sw.switchOn()    
else
	sw.switchOff()     
end
I hope the above information is usefull for others that are searching for a Google home and Domoticz combination and don't want to use a 3rd party site.
Last edited by marchutt on Thursday 24 June 2021 18:21, edited 3 times in total.
freijn
Posts: 536
Joined: Friday 23 December 2016 16:40
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands Purmerend
Contact:

Re: Google home <-> Node-red <-> Domoticz (without 3rd party)

Post by freijn »

Wauw! Well done Marc, will defenitely have a look into it. Very interesting!

Thanks,

Frank
User avatar
EdwinK
Posts: 1820
Joined: Sunday 22 January 2017 21:46
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Rhoon
Contact:

Re: Google home <-> Node-red <-> Domoticz (without 3rd party)

Post by EdwinK »

Will a dynamic addres (as noip.org or similair) work?
Running latest BETA on a Pi-3 | Toon® Thermostat (rooted) | Hue | Tuya | IKEA tradfri | Dashticz V3 on Lenovo Huawei Tablet | Conbee
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Google home <-> Node-red <-> Domoticz (without 3rd party)

Post by jvdz »

With the upcoming change of IFTTT, which will totally cripple the variable commands for devices, I checked out this option and must say it is looking pretty good.

Thanks for sharing.
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
mgugu
Posts: 208
Joined: Friday 04 November 2016 12:33
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: France
Contact:

Re: Google home <-> Node-red <-> Domoticz (without 3rd party)

Post by mgugu »

Free alternative to Smart Nora but with much more configuration (Google action setup, SSL,..)
User avatar
FireWizard
Posts: 1745
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Google home <-> Node-red <-> Domoticz (without 3rd party)

Post by FireWizard »

Hi @mgugu,

You wrote:
Free alternative to Smart Nora but with much more configuration (Google action setup, SSL,..)
I moved away from SmartNora November last year, when SmartNora became a paid service, at least, if you use more than 5 devices.
It took some time to set it up, but conversion from SmartNora was very easy. I'm not against the fact that SmartNora needs income to operate the service, but it was the last push, I needed, as I wanted to control my devices myself and not being dependant on, whether a third party want to add it or not.

Now I have everything under control and I run it for Lights, Switches, Dimmers, Sensors, Locks, Security device, Thermostat and Media device.

The biggest hurdle, you have to take, is to configure SSL

As Google only accepts "Secure Communication", you will need a valid "real" certificate. A self-signed certificate is not accepted.
So to get a free certificate, you can use Let's Encrypt. However Let's Encrypt requires a (sub)domain name and does not accept an IP address only.
So you have to register a Domain name for your IP Address. Let's Encrypt also requires access to your Webserver, via port 80
If you do not run a Webserver in your Local Domain you can use Caddy as a reverse proxy.

To configure Google Actions, Homegraph, Google Log in, Local fulfillment is just a matter of carefully follow the recipe, described at: https://github.com/mikejac/node-red-con ... uctions.md

Regards
Last edited by FireWizard on Saturday 14 October 2023 15:43, edited 2 times in total.
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Google home <-> Node-red <-> Domoticz (without 3rd party)

Post by jvdz »

Agree it was a bit of a puzzle but got all basics running within a day.
How have you done the conversion from the received information to domoticz?
For example I have some Milight CCT/RGB bulb, so I still need to look at the best way to convert the received info into something domoticz understands. Switches (On/Off/Open/Close) is easy and working on a test device.
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
mgugu
Posts: 208
Joined: Friday 04 November 2016 12:33
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: France
Contact:

Re: Google home <-> Node-red <-> Domoticz (without 3rd party)

Post by mgugu »

Thank you @FireWizard for your feedback, you convinced me. I will try this solution.
I have about 150 devices running with Smart Nora but the conversion can be donr step by step.
mgugu
Posts: 208
Joined: Friday 04 November 2016 12:33
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: France
Contact:

Re: Google home <-> Node-red <-> Domoticz (without 3rd party)

Post by mgugu »

jvdz wrote: Saturday 06 August 2022 15:14 Agree it was a bit of a puzzle but got all basics running within a day.
How have you done the conversion from the received information to domoticz?
For example I have some Milight CCT/RGB bulb, so I still need to look at the best way to convert the received info into something domoticz understands. Switches (On/Off/Open/Close) is easy and working on a test device.
The conversion from or to domoticz (through JSON or MQTT) is never direct, you need always minimum JS code in nodered functions and some imagination...
It could become really complicated for some advanced devices. For example, the HomeCinema device of Smart Nora was not working for me for som reason. To avoid splitting in a lot of elementary devices, I used a dimmer with discrete values, each value corresponding to a specific action.
mgugu
Posts: 208
Joined: Friday 04 November 2016 12:33
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: France
Contact:

Re: Google home <-> Node-red <-> Domoticz (without 3rd party)

Post by mgugu »

I installed everything this morning, here is my feedback: For SSL setup, about 30 minutes only were needed by using a reverse proxy based on caddy/docker (provided you already own a domain name).
For google action 2 hours were sufficient due to high quality error-free provided documentation.
Comparison with SmartNora (first impressions):
- Device types are the mirror of google smarthome capabilities (no direct correspondance in SmartNora).
- Response time seems to be quicker (effect of local fullfillment ?)
- Possibility to add nicknames directly in the device configuration
I tested 3 devices, on/off switch, brightness light, percentage blinds without any problem.
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Google home <-> Node-red <-> Domoticz (without 3rd party)

Post by jvdz »

Agree!
I must say I am pretty happy with the setup as well. I am running 2 instances in Node-Red for 2 different homes and one has a number of lights defined which I currently only support On/Off/Brightness. The other I have 6 switches mainly used for Screens/Blinds, which support Open/Close/level and 10+ scenes, which drive the lightning definitions in Domoticz. The whole setup is pretty responsive and seems generally faster than my previous free IFTTT setup.
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
mgugu
Posts: 208
Joined: Friday 04 November 2016 12:33
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: France
Contact:

Re: Google home <-> Node-red <-> Domoticz (without 3rd party)

Post by mgugu »

Hi all,
For those who have difficulties to setup SSL, the author has published a tuto based on caddy https://github.com/mikejac/node-red-con ... s/caddy.md
Following my tests, I found a very annoying issue when trying to put a device in a subflow in order to group all the glue necessary to work with Domoticz.
This lead to a complete mess in the google app, not only a device with the name given to the subflow instance but also a ghost device with the name given in the subflow for referencing to an environment variable, are created.
The instance works but... it is impossible now de remove both instance and ghost in the google app, to clean everything you need to unlink the service, restart nodered and relink the service.
Did you observe such behaviour ?
tourolouco
Posts: 1
Joined: Thursday 12 October 2023 12:05
Target OS: Linux
Domoticz version: Stable
Location: The Netherlands
Contact:

Re: Google home <-> Node-red <-> Domoticz (without 3rd party)

Post by tourolouco »

Hi 'marchutt',

Greet stuff!! So far I've managed to install Node-RED, node-red-contrib-google-smarthome (including public certificate and Google sign-in) and figured out the communication with Domoticz goes by MQTT. But being a cmd line/text oriented guy I'm stuck on how to continue next. I read MQTT communicates using JSON, right? I installed the MQTTExplorer on my phone and enabled MQTT on the LAN for debugging. But how can I make the JSON part visable for programming/debugging? And does the Google API also work with JSON? What tools do you use?

Regards,
Emanuel
PS I found the node-red-contrib-zigbee2mqtt plugin and how the send the msg to a debug window, we're getting there. If only I could find a flow connecting zigbee2mqtt to the Google Home API (I'm skipping interfacing through Domoticz, it will use the zigbee2mqtt plugin to control zigbee directly).
JuanUil
Posts: 497
Joined: Friday 22 May 2015 12:21
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.11083
Location: Asten NB Nederland
Contact:

Re: Google home <-> Node-red <-> Domoticz (without 3rd party)

Post by JuanUil »

Looks very promishing, going to have a try.
Thnx for sharing!
Your mind is like a parachute,
It only works when it is opened!

RPI4 several Fibaro, KaKu, Neocoolcam switches, Z-Wave, Zigbee2Mqtt, Ikea bulbs and remote, Zigbee temp nodes
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests