Search code examples
actions-on-googlegoogle-homegoogle-smart-home

Trait action.devices.traits.Modes does not seem to be working


I am trying to get the action.devices.traits.Modes trait working. On action.devices.SYNC request, I return the following response:

{
   "payload":{
      "devices":[
         {
            "id":"12345",
            "type":"action.devices.types.SWITCH",
            "traits":[
               "action.devices.traits.OnOff",
               "action.devices.traits.StartStop",
               "action.devices.traits.Modes"
            ],
            "name":{
               "defaultNames":null,
               "name":"David",
               "nicknames":null
            },
            "willReportState":false,
            "roomHint":"living room",
            "attributes":{
               "pausable":true,
               "availableModes":[
                  {
                     "name":"speed",
                     "name_values":[
                        {
                           "name_synonym":[
                              "speed"
                           ],
                           "lang":"en"
                        }
                     ],
                     "settings":[
                        {
                           "setting_name":"slow",
                           "setting_values":[
                              {
                                 "setting_synonym":[
                                    "slow"
                                 ],
                                 "lang":"en"
                              }
                           ]
                        },
                        {
                           "setting_name":"normal",
                           "setting_values":[
                              {
                                 "setting_synonym":[
                                    "normal"
                                 ],
                                 "lang":"en"
                              }
                           ]
                        },
                        {
                           "setting_name":"fast",
                           "setting_values":[
                              {
                                 "setting_synonym":[
                                    "fast"
                                 ],
                                 "lang":"en"
                              }
                           ]
                        }
                     ],
                     "ordered":true
                  }
               ]
            }
         }
      ]
   }
}

I validated this response on https://developers.google.com/actions/smarthome/tools/validator/, and got feedback that it's fine.

Now, when I type in the console or the Assistant on my smartphone one of the following phrases, the fulfillment service is not being called:

What mode is David in?
What speed is David in?
What is the David's speed?
Set the speed of David to normal.
Set David's speed to normal.
Set David to normal speed.
...

All of these simply fall back to a Google search.

The traits action.devices.traits.OnOff and action.devices.traits.StartStop however work fine. The following phrases work as expected:

Turn David on
Resume David.
...

I have no clue what is going wrong and what I should do to debug this. AFAIK, the Smart Home service is more or less a black box, so I am not sure what is going on/wrong here.


Solution

  • As noted in the documentation for the Modes trait for availableModes:

    Currently, you must use the names in the example JSON; custom names are not yet supported.

    Names can be created manually on an individual basis by filing an issue on the GitHub sample.

    However, in your specific case of speeds, you should take a look at the FanSpeed trait. It provides the same functionality, where you can define several speed modes and then switch between them. You could update your device JSON to look more like this:

    {
     "payload":{
       "devices":[
         {
            "id":"12345",
            "type":"action.devices.types.SWITCH",
            "traits":[
               "action.devices.traits.OnOff",
               "action.devices.traits.StartStop",
               "action.devices.traits.FanSpeed"
            ],
            "name":{
               "defaultNames":null,
               "name":"David",
               "nicknames":null
            },
            "willReportState":false,
            "roomHint":"living room",
            "attributes":{
               "pausable":true,
               "availableFanSpeeds": {
                 "speeds": [{
                   "speed_name": "Low",
                   "speed_values": [{
                     "speed_synonym": ["low", "slow"],
                     "lang": "en"
                   },
                   {
                     "speed_synonym": ["low", "slow"],
                     "lang": "de"
                   }]
                 },
                 {
                   "speed_name": "High",
                   "speed_values": [{
                     "speed_synonym": ["high"],
                     "lang": "en"
                   },
                   {
                     "speed_synonym": ["high"],
                     "lang": "de"
                   }]
               }],
               "ordered": true
             },
             "reversible": true
            }
         }
      ]}
    }