i8beef / HomeAutio.Mqtt.GoogleHome

MIT License
215 stars 29 forks source link

Question about Fulfillment URL #73

Closed CoderFX closed 4 years ago

CoderFX commented 4 years ago

Should the Fulfillment URL in Google Actions be https://blah.com/google/home/switch or just https://blah.com/google/home/ ? Does it have any affect on googleDevices.json?

i8beef commented 4 years ago

https://github.com/i8beef/HomeAutio.Mqtt.GoogleHome/wiki/Setup:-Google-Actions-Console

This is answered in the wiki. Register, step 5.

CoderFX commented 4 years ago

It's not really clear what is a "smarthome" route and how this is connected to googleDevices.json.

i8beef commented 4 years ago

I.e., if proxying this application through nginx at https://mydomain.com/google/home, it would be https://mydomain.com/google/home/smarthome.

It should be set to https://mydomain.com/google/home/smarthome. It has no relation to googleDevices.json.

i8beef commented 4 years ago

And I am open to any change in wording that would make this clearer in the docs if you found it hard to understand. Its a little tough because Google makes this much more complicated than it needed to be, so theres a lot of technical details.

CoderFX commented 4 years ago

Well I'm getting error when trying to add device: Couldn't update the setting. Check your connection

So how this smarthomeendpoint should lead message to mosquitto:1883? I'm not using any mqtt bridge though I have mqtt-bridge in my docker setup where I could use smartthingspreface

I have a flashed Sonoff Basic with tasmota and named it SB1 and this command also works: mosquitto_pub -d -t SB1/cmnd/power -m "on"

and this is my googleDevices.json:

{
  "SB1": {
    "id": "SB1",
    "type": "action.devices.types.SWITCH",
    "disabled": false,
    "willReportState": true,
    "roomHint": "Bedroom",
    "name": {
      "defaultNames": [],
      "name": "SB1",
      "nicknames": []
    },
    "deviceInfo": {
      "manufacturer": "Sonoff",
      "model": "Basic",
      "hwVersion": "1.0",
      "swVersion": "1.0"
    },
    "traits": [
      {
        "trait": "action.devices.traits.OnOff",
        "attributes": null,
        "commands": {
          "action.devices.commands.OnOff": {
            "on": "SB1/cmnd/POWER"
          }
        },
        "state": {
          "on": {
            "topic": "SB1/stat/POWER",
            "googleType": "bool",
            "valueMap": [
              {
                "mqtt": "on",
                "type": "value",
                "google": true
              },
              {
                "mqtt": "off",
                "type": "value",
                "google": false
              }
            ]
          }
        }
      }
    ],
    "customData": null
  }
}
CoderFX commented 4 years ago

Finally got it to work with https://mydomain.com/google/home/smarthome somehow. But I'm still not sure why we need to have smarthome there.

i8beef commented 4 years ago

A bridge links two things conceptually. This app links Google Assistant's smart home functionality to MQTT. To do that, it has to speak two "languages" and translate between them, and because that translation takes a lot of setup, it needs a lot of options and configuration to do that. As such this app consists of (a) a Google Actions implementation for smart home implementations, (b) an OAuth server to serve the Google authentication scheme, (c) an MQTT connection to control / get state from your home automation system, and (d) a web application to allow configuration outside of the config file (convenience).

An endpoint, or a route is just a URL. As this is a web app, oauth is a web based authorization scheme, and google actions integrations are implemented as an API that Google's servers can call to execute commands, get state, etc., this app has many endpoints. Because YOU are in control of where this app is hosted, and because there is no standard route path Google can assume for an integration, you have to SET everything in various places so everything knows what endpoints to call to do stuff.

This app's integration thus has several "routes" in it that you have to point everything to. The "smarthome" route or endpoint is just the one that answers Google Action's calls, which you have to tell Google about in your Action Console setup. The URL has to be https://YourHost/proxyPathToAppRoot/smarthome because this app's Google endpoint is hosted at approot/smarthome, and your app root is https://YourHost/proxyPathToAppRoot. The details of which you don't really need, but Im providing because you asked, you just have to trust the directions here.

Your googleDevices.json looks ok for a single on/off switch. A Google Action ONOFF command intent for the device SB1 will send the value of the incoming "on" property (true or false) to the mapped MQTT topic "SB1/cmnd/POWER", and will use the specified "valueMap" to turn "true" to "on" and "false" to "off" before doing so. Then, when the status topic "SB1/stat/POWER" gets published with the new status, it will use that same valueMap to convert the values to Google accepted values (property "on" = true or false appropriately), and report this state change to Google via the "ReportState" setup.