Google Assistant

From Domoticz
Jump to navigation Jump to search

Google Assistant allows you to control things via Google Assistant on your mobile or tablet or a Google Home device

Controlicz

Simple setup

Controlicz is the gateway between your Voice Assistants such as Google Home, Echo or Google Assistant on your phone and Domoticz Home Automation running on your Raspberry Pi. Simply create an account with us, subscribe, then setup your voice assistants via their respective apps and you are ready to go. Subscription to Controlicz is simply £2/month, or £20/year - and grants you full access to all the Smart Home services we offer Register at https://www.controlicz.com/ - Please read the FAQ first

Add the devices you want to control into Room Plans in your Domoticz instance. Setup port forwarding for your SSL port - this only works with HTTPS

Domoticz Google Assistant (dzga)

Advanced setup

Free and Open Source, Standalone implementation. It means that you can put this server wherever you want, even on another machine. More info, report bugs, contribute to domoticz google assistant on github

Domoticz-Google-Assistant delivers:

  • The oauth authorization and smarthome endpoint for the google assistant
  • Two-factor authentication pin for domoticz protected devices (limited language support)
  • Acknowledgement with Yes or No. (limited language support)
  • Arm Disarm Securitypanel (limited language support)
  • On/Off, Brightness, Thermostat, Color Settings, speaker volume, Lock/Unlock, Scene and Open/Close
  • Stream surveillance camera to chromecast
  • Toogle selector switches
  • Thermostat modes
  • and more

Required

  • Public IP
  • python >= 3.5
  • Make local deployment available trough HTTPS with valid certificate with one below:
    • Use ngrok for a secure SSL tunnel with valid public HTTPS URL
    • Configure reverse proxy with domain name and valid certificate using Lets Encrypt
    • SSL with own domain or dynamic DNS, require ssl key and ssl certficate

You need to create an API Key with the Google Cloud API Console which (instructions below) allows you to update devices without unlinking and relinking an account (see below). If you don’t provide one, the google_assistant.request_sync service is not exposed. It is recommended to set up this configuration key as it also allows the usage of the following command, “Ok Google, sync my devices”. Once you have set up this component, you will need to call this service (or command) each time you add a new device that you wish to control via the Google Assistant integration.

RPI/Ubuntu Installation with autostart

This installs the dzga in a virtual enviroment.

NOTE: "${USER}" will automatically take your username. No need to change that. Just copy and paste.

Just open a terminal window and execute this command. Thats it!

bash <(curl -s https://raw.githubusercontent.com/DewGew/dzga-installer/master/install.sh)

Start/stop Domoticz-Google-Assistant server:

sudo systemctl start dzga
sudo systemctl stop dzga

Check if service is running:

sudo systemctl status dzga

To update run installer again:

bash <(curl -s https://raw.githubusercontent.com/DewGew/dzga-installer/master/install.sh)

To run manually:

cd /home/${USER}/
sudo systemctl stop dzga #If service is running
source Domoticz-Google-Assistant/env/bin/activate
python3 Domoticz-Google-Assistant

Uninstall:

cd /home/${USER}/
sudo systemctl stop dzga
sudo systemctl disable dzga
sudo rm /etc/systemd/system/dzga.service
sudo rm -r /home/${USER/Domoticz-Google-Assistant

Docker Installation

Require docker-compose

Read more at Domoticz-Google-Assistant for Docker

Manual Installation

NOTE: "${USER}" will automatically take your username. No need to change that. Just copy and paste.

Open a terminal window and execute those commands:

cd /home/${USER}/
git clone https://github.com/DewGew/Domoticz-Google-Assistant
pip install -r ~/Domoticz-Google-Assistant/requirements/pip-requirements.txt

Manual start (stop with 'ctrl-c'):

cd /home/${USER}/
python3 Domoticz-Google-Assistant

Update:

cd /home/${USER}/Domoticz-Google-Assistant/
git pull

Uninstall:

cd /home/${USER/
sudo rm -r /home/${USER/Domoticz-Google-Assistant

Configuration

You can access the interface via http://localhost:3030/settings. The default username is admin and the default password is admin.

Configuration and Actions on Google must be modified properly. You can also edit config.yaml in Domoticz-Google-Assistant folder to change the configuration.

Minimal configuration:

# Configuration:
port_number: 3030
loglevel: 'Info'
logtofile: true
userinterface: true

# Login on Google Home app and configuration interface
auth_user: 'admin'
auth_pass: 'admin'

# Google Assistant Settings:
ClientID: 'clientid_from aog'
ClientSecret: 'clientsecret_from_aog
  
# Domoticz Settings:
Domoticz:
  ip: 'http://192.168.1.100'
  port: '8080'
  roomplan: '0'
  username: 'username'
  password: 'password'
  switchProtectionPass: '1234' #Set this to false if ask for pin function is not needed

# Report low battry
Low_battery_limit: 9

Setup Actions on Google Instructions

Use the Actions on Google Console to add a new project with a name of your choosing and click - Create Project.

  • Click Home Control, then click Smart Home.
  • On the top menu click Develop, then on the left navigation menu click on Invocation.
  • Add your App's name. Click Save.
  • Click Save.

Note: Ensure that you are using the correct GCP project when performing following steps. This is the project that matches your smart home project ID. At Google Cloud Platform Console at the top left corner in the blue bar next to Google Cloud Platform. There is a drop down menu where you can choose your projects.

Add Request Sync and Report State with Service Account (optional but recomended)

The Request Sync feature allows a cloud integration to send a request to the Home Graph to send a new SYNC request. The Report State feature allows a cloud integration to proactively provide the current state of devices to the Home Graph without a QUERY request. These are done securely through JWT (JSON web tokens).

  • Navigate to the Google Cloud Console API Manager for your project id.
  • Enable the HomeGraph API.
  • Navigate to the Google Cloud Console API & Services page.
  • Select Create Credentials and create a Service account key
    • Create a new Service account
    • Use the role Service Account > Service Account Token Creator
    • Click Done
  • Click on the newly created Email Account under Service Accounts
  • Add key > create new key
  • Choose JSON
  • Click create and download the JSON file.
  • Upload and Save this in ../Domoticz-Google-Assistant/config folder as smart-home-key.json

Navigate back to the Actions on Google Console.

  • On the top menu click Develop, then on the left navigation menu click on Actions.
  • Enter the URL for fulfillment, e.g. https://<YOUR REVERSE PROXY URL>/smarthome (replace with your actual URL), click Done.
  • On the left navigation menu under Account Linking.
  • Under Client Information:
    • Client ID: some ID, just remember it and add it in config.yaml
    • Client secret: some password, just remember it and add it in config.yaml
  • Change Authorization URL to https://<YOUR REVERSE PROXY URL>/oauth (replace with your actual URL).
  • Change Token URL to https://<YOUR REVERSE PROXY URL>/token (replace with your actual URL).

Do NOT check "Google to transmit clientID and secret via HTTP basic auth header".

  • Click Save at the top right corner, then click Test to generate a new draft version of the Test App.

Connect smart home devices to your Google Home device

  • On your mobile device, open the Google Home app.
  • On the Home tab, tap the Add quick action .
  • Tap Set up a device
  • Tap Have something already set up?
  • Select your device app e.g: "[test]Your Appname"
  • Login with Oauth credentials from config.py

Share devices

If you want to allow other household users to control the devices:

  • Go to Actions on Google Console.
  • Click three dots icon next to your profile icon, then click Manage user access
  • In Google Cloud Platform, click ADD.
  • type the new user’s Google Account mail address as New member.
  • Select a role choose Project -> Viewer.
  • Click SAVE.
  • Have the new user go to their Google Home app to add "[test]Your Appname" to their account. Login with Oauth credentials from configuration

Stream camera to chromecast

Stream security camera to chromecast. Supports hls, dash, smooth streaming, Progressive MP4 urls. More info: https://developers.google.com/actions/smarthome/traits/camerastream#video-formats. You need a to convert your video url to one of above. Try with ffmpeg or with a surveillance software system. Try out http://shinobi.video. In domoticz you need to attach a switch to your camera (create a switch then in Settings/Camera, add the switch to the camera)

Example convert rtsp to hls or mp4 using ffmpeg:

 ffmpeg -rtsp_transport tcp -i rtsp://admin:[email protected]/live/ch1 \
   -acodec copy \
   -vcodec copy \
   -hls_wrap 40 \
   -flags -global_header \
   /var/www/html/cam/cam.m3u8
 ffmpeg -rtsp_transport tcp -i rtsp://admin:[email protected]/live/ch1 \
   -c:a aac \
   -vcodec copy \
   -f mp4 \
   -y \
   -flags -global_header \
   /var/www/html/cam/cam.mp4

In config.py:

Camera_Stream:
  Enabled: false
  Cameras:
    Idx:
      - '123'
      - '234'
      - '345'
    Camera_URL:
      - 'http://your.web.server/cam/cam.m3u8'
      - 'https://content.jwplatform.com/manifests/yp34SRmf.m3u8'
      - 'http://user:[email protected]:8080/mp4/cctv/camera2/s.mp4'

Additional settings

Portnumber for Domoticz Google Assistant server

port_number : 3030

Ligths, switches, media, etc. are using domoticz's "Light/Switch" type. So to differentiate them additionaly image names are used.

Image_Override:
  Switch:
    - 'Generic'
  Light:
    - 'Light'
  Media:
    - 'Media'
    - 'TV'
  Outlet:
    - 'WallSocket'
  Speaker:
    - 'Speaker'

Nicknames, rooms and ack can be set in the Domoticz user interface. Hide devices from Google Assistant still but can still see this in UI as type 'Hidden'. Simply put the device configuration in the device description, in a section between 'voicecontrol' tags like:

 <voicecontrol>
   nicknames = Kitchen Blind One, Left Blind, Blue Blind
   room = Kitchen
   ack = True
   hide = True
 </voicecontrol>

Other parts of the description are ignored, so you can still leave other useful descriptions. Every variable should be on a separate line. If there is no such configuration in the Domoticz device it will still try the config:

Device_Config:
  123:
    ack: true
    room: 'Livingroom'
    nicknames:
      - 'Celing light'
      - 'Smart light'
  234:
    room: 'Bedroom'
    hide: true
    
Scene_Config:
  3:
    room: 'Kitchen'
    nicknames:
        - 'Cool scene'

For thermostat devices only.

Function to merge actual temperature from another temp device or modes from selector device to thermostat. Merged device will automaticly hidden. Levels from selector device supported is: Off - Heat - Cool - Auto - Eco. Bug Thermostat idx must be a number above Temp/selector idx.

<voicecontrol>
  actual_temp_idx = 123
  selector_modes_idx = 234
</voicecontrol>

or in config.yaml:

Device_Config:
  456:
    actual_temp_idx: '123'
    selector_modes_idx: '234'

User-friendly name for the level in your language. See: https://developers.google.com/actions/smarthome/traits/#supported-languages

Armhome:
  level_synonym:
    - 'zuhause und bewachen'
    - 'Level 1'
    - 'SL1'
  lang: 'de'
Armaway:
  level_synonym:
    - 'weg und bewachen'
    - 'Level 2'
    - 'SL2'
  lang: 'de'
For more additional configuration visit Domoticz-Google-Assistant Wiki

Useful commands

With ack = True:

User: Turn on the dining room light.
Google Assistant: Turning on the dining room light. Are you sure?
User: Yes.
Google Assistant: Turning on the dining room light.

Protected device:

User: Turn on the dining room light.
Google Assistant: Can I have your security code?
User: 1234
Google Assistant: Turning on the dining room light.

Security device:

User: Set the security system to armed away.
Google Assistant: Can I have your security code?
User: 1234
Google Assistantt: Ok, arming the security system to armed away.
User: Is my security system armed?
Google Assistant: The security system is armed to armed away.

Speaker volume:

User: Set volume on living room speaker to 50%
Google Assistant: Sure
User: Turn up the volume on living room speaker?
Google Assistant: Alright (Volume increases with 1%)

When a device has low battery:

User: Lock front door.
Google Assistant: The front door lock has low battery. Locking the front door.

Stream front door camera to TV.

User: Show front door camera on [Chromecast device name].
Google Assistant: Streaming front door on [Chromecast device name].

Selector switch.

User: Turn on [Level Name] on living room light.  
Google Assistant: Turning on [Level Name] on living room light?

Force devices sync

 https://[YOUR REVERSE PROXY URL]/sync

Run as service for autorun at startup

(If installation made manually) Open terminal or putty.

cd /etc/systemd/system/
sudo nano dzga.service

Add this in nano (change 'pi' to match your user):

[Unit]
Description=Domoticz-Google-Assistant Service
After=multi-user.target
Conflicts=[email protected]

[Service]
Type=simple
ExecStart=/usr/bin/python3 /home/pi/Domoticz-Google-Assistant/
StandardInput=tty-force
User=pi
Restart=on-failure

[Install]
WantedBy=multi-user.target

Then ctrl-x save and close. Enable service:

sudo systemctl enable dzga.service
sudo systemctl start dzga.service

Uninstall service:

sudo systemctl stop dzga
sudo systemctl disable dzga
sudo rm /etc/systemd/system/dzga.service

Links

Report bugs, contribute to Domoticz Google Assistant on github
Forum thread