OrangeAssist - Google Assistant Integration

At the risk of turning this into a Linux support thread (sorry):

ran sudo apt-get install portaudio19-dev libffi-dev libssl-dev libmpg123-dev seemed to work downloading and installing.

From the linked google doc:

[21:54:14] root@openHABianPi:/home/openhabian/orange-assist# apt-get install python3-dev python3-venv
Reading package lists... Done
Building dependency tree
Reading state information... Done
python3-dev is already the newest version (3.5.3-1).
python3-venv is already the newest version (3.5.3-1).
0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.
[21:55:55] root@openHABianPi:/home/openhabian/orange-assist# python -m or
Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 163, in _run_module_as_main
    mod_name, _Error)
  File "/usr/lib/python2.7/runpy.py", line 119, in _get_module_details
    code = loader.get_code(mod_name)
  File "/usr/lib/python2.7/pkgutil.py", line 283, in get_code
    self.code = compile(source, self.filename, 'exec')
  File "/home/openhabian/orange-assist/or.py", line 28
    f = f"output/{f}"
                    ^
SyntaxError: invalid syntax

It references Python v2.7 so I tried:

[21:56:34] root@openHABianPi:/home/openhabian/orange-assist# python3 -m or
Traceback (most recent call last):
  File "/usr/lib/python3.5/runpy.py", line 183, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "/usr/lib/python3.5/runpy.py", line 153, in _get_module_details
    code = loader.get_code(mod_name)
  File "<frozen importlib._bootstrap_external>", line 775, in get_code
  File "<frozen importlib._bootstrap_external>", line 735, in source_to_code
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/home/openhabian/orange-assist/or.py", line 28
    f = f"output/{f}"
                    ^
SyntaxError: invalid syntax

Like in my earlier post it references Python 3.5 but still no worky. :frowning: Sorry I’m a total noob.

When I do:

[21:57:32] root@openHABianPi:/home/openhabian/orange-assist# python --version
Python 2.7.13

It shows 2.7.13. So I don’t understand why it says it wont update to 3.5.

Edit: I saw your edits, so looks like I need at least Python v3.6. Ok, back to googling to see how to do that. Everything I have seen so far talks about having to compile the source but that sounds difficult…

sudo apt-get install python3.7
python3.7 -m pip install virtualenv
source env/bin/activate

If more people aren’t able to run in 3.6+, I will downgrade/refactor code to be 2.7 compatible.

[20:34:03] openhabian@openHABianPi:~$ sudo apt-get install python3.7
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package python3.7
E: Couldn't find any package by glob 'python3.7'
E: Couldn't find any package by regex 'python3.7'

:frowning:

I ran into this:

We have to build Python for RPi as nothing later than 3.4 is in the repos.

Note, I used https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tar.xz as the URL instead of https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tar.xz.

@luckymallari, it might be worth downgrading as the latest Raspbian is stuck back on version 3.4 which will be a problem for the majority of users.

For those who want to wait, I just followed the instructions through step 2. I didn’t clean up so do that step at your risk.

I’m playing around with getting it set up. There are not a lot of details about what is appropriate to fill in on the first steps so I filled in the minimum required. I assumed I needed to select a SPEAKER as the device type. We will see if I chose correctly. Building Python on an RPi is not a fast process. :wink:

Yeah I might downgrade it to 2.7. Weird you mention rPI and 3.4. I was able to run this on a smaller orange pi but I did have to install 3.7, but yeah for the usability and compatibility, I’ll downgrade code to 2.7, the most used python version. So stay tuned guys :slight_smile:

2 Likes

Clearly Armbian is keeping up with Python 3 better than Raspbian.

Hehehe true. I will also make the speaker part optional.

Not sure if I should code for 2.7 or the python 3 that rPi supports. Looks like 3.4.2 is the latest Python rPi has official support for. I will be coding for that instead.

3.4.2 should cover the RPis well.

I built 3.7.2 on my RPi but the SSL module didn’t build so I can’t pip install anything. Grrrr. Guess I’ll have to wait.

Created a 3.4.2 branch. Let me know if this works for you so I can merge this back to master.

3.4.2 branch

I noticed, on the pi, a requirement (grpcio) takes forever!

Also, note that if you have is_debug true in config.json, the mode becomes CLI and the REST API will not be enabled. This is just so you can test it out.

After much fumbling, (I am useless at Linux), I managed to get the 3.4.2 branch installed and the code to run… but then:

python -m or
Cred file: /root/.config/google-oauthlib-tool/credentials.json
 + Found!
ERROR:root:Failed to register device: {
  "error": {
    "code": 400,
    "message": "Could not create the device instance. Project_id from side channel and project_id from url do not match.",
    "status": "INVALID_ARGUMENT"
  }
}

I’m pretty sure I gathered the credentials correctly and pointed to the correct creds file, (I only have one), since I followed the instructions closely.
I don’t know what I messed up.
Any ideas?

Follow the instruction on OP to register a device.
You need to use that info and put that on config.json, particulary device_id and device_model_id, as well as the project_id.

https://developers.google.com/assistant/sdk/guides/library/python/embed/register-device

I had already registered as per instructions and copied the creds file to the Pi but I missed that I needed to update the config file to point to the creds file location. Did that, got further, then…

python -m or
Traceback (most recent call last):
  File "/usr/lib/python3.5/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.5/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/openhabian/orange-assist/tmp/or.py", line 19, in <module>
    cfg = Config()
  File "/home/openhabian/orange-assist/tmp/config.py", line 7, in __init__
    j = json.load(json_data_file)
  File "/usr/lib/python3.5/json/__init__.py", line 268, in load
    parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
  File "/usr/lib/python3.5/json/__init__.py", line 319, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.5/json/decoder.py", line 339, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.5/json/decoder.py", line 355, in raw_decode
    obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Invalid \escape: line 11 column 26 (char 321)

Thanks for all your help thus far btw!

paste your config.json… don’t worry about device-id, etc. No one can use without your creds file.

{
    "is_debug": true,
    "is_verbose": true,
    "host": "0.0.0.0",
    "port": "2828",
    "username": "lucky",
    "password": "charms",
    "device_model_id" : "orangeassistant-orangeassistant-yp61iy",
    "device_id" : "orangeassistant",
    "on_success_post_to": "http://url_to/post_to",
    "credentials_file": "\home\openhabian\orange-assist-secret\client_secret_1050646114254-jjufv1qtdgndsp7gv6t3ko50cqc7jrs1.apps.googleusercontent.com.json",
    "delete_output_files_sec": 60,
    "screen_mode": "SCREEN_MODE_UNSPECIFIED",
    "project_id": "orangeassistant"
}

Clearly I have no idea what I’m doing by this point :sweat_smile:

EDIT
I didn’t update the device ID did I?!!!

EDIT2
OK, maybe I need to chill and R all of TFM. I see there is a section about the config file further down but I was too excited about the step:

it doesnt work like that.

You need to register your device! I see you are still using mine:

    "device_model_id" : "orangeassistant-orangeassistant-yp61iy",
    "device_id" : "orangeassistant",

When you register your device, it will give you your own device and model ids.
https://developers.google.com/assistant/sdk/guides/library/python/embed/register-device

Also did you run the google auth tool?
You run it like this:

google-oauthlib-tool --scope https://www.googleapis.com/auth/assistant-sdk-prototype \
      --scope https://www.googleapis.com/auth/gcm \
      --save --headless --client-secrets /path/to/client_secret_client-id.json

After the google auth tool, a credentials.json file is create in the same folder where the tool is. So in your config.json, just use “credentials.json” and my code will hunt that down. I have mentioned all these above… https://developers.google.com/assistant/sdk/guides/library/python/embed/install-sample

After registring the device, if you want your device to show in your Google Home app, you need to create an instance of that device… https://developers.google.com/assistant/sdk/reference/device-registration/device-tool

Let me know if you need more assistance before I go to bed :slight_smile:

I messed up the json file with my slashes the wrong way round (windows brain).
Fixed that and updated the rest of the config file.

Yes, I had done all of the creds generation steps etc. I just didn’t have my config file correct to point to them.

Got this error on running:

 python -m or
Cred file: /home/openhabian/orange-assist-secret/creds.json
 + Found!
Traceback (most recent call last):
  File "/home/openhabian/orange-assist/tmp/orangeassist.py", line 64, in getcredentials
    token=None, **json.load(f))
TypeError: __init__() got an unexpected keyword argument 'installed'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.5/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.5/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/openhabian/orange-assist/tmp/or.py", line 20, in <module>
    orange = OrangeAssistant(cfg)
  File "/home/openhabian/orange-assist/tmp/orangeassist.py", line 94, in __init__
    cfg.credentials_file)
  File "/home/openhabian/orange-assist/tmp/orangeassist.py", line 68, in getcredentials
    logging.error("Error loading credentials:" + e)
TypeError: Can't convert 'TypeError' object to str implicitly

p.s. don’t stay up, this can wait until another day! :slight_smile:

Make sure it is the credentials file created by google auth tool and not the clientsecrets file you downloaded from google site.

 python -m or
Cred file: /root/.config/google-oauthlib-tool/credentials.json
 + Found!
# orange assist v1 #
Server OrangeAssist with config:
{
    "credentials_file": "/root/.config/google-oauthlib-tool/credentials.json",
    "delete_output_files_sec": 60,
    "device_id": "OpenHAB",
    "device_model_id": "mcqwerty-openhab-orangeassist",
    "enable_speaker": false,
    "host": "0.0.0.0",
    "is_debug": true,
    "is_verbose": true,
    "on_success": null,
    "password": "charms",
    "port": "2828",
    "project_id": "mcqwerty-openhab-orangeassist",
    "screen_mode": "SCREEN_MODE_UNSPECIFIED",
    "username": "lucky"
}
Cred file: /root/.config/google-oauthlib-tool/credentials.json
 + Found!
DebugMode! Keep sending request. 'exit' to stop.
[Orange-->]: Lucky is awesome!!
[<--Google]: I feel lucky

:grin::grin::grin::grin::+1:
THANK YOU @luckymallari