i8beef / HomeAutio.Mqtt.GoogleHome

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The given key 'action.devices.commands.SetTemperature' was not present in the dictionary.

balthus opened this issue · comments

Hello again,

I'm trying to integrate some temperature sensor and I found the #88 which provide a solution for tasmota.
If we copy/paste the same code as in the ticket:

  "esplight": {
    "id": "esplight",
    "type": "action.devices.types.LIGHT",
    "disabled": false,
    "willReportState": false,
    "roomHint": "Office",
    "name": {
      "defaultNames": [],
      "name": "office light",
      "nicknames": []
    },
    "deviceInfo": null,
    "traits": [
      {
        "trait": "action.devices.traits.TemperatureControl",
        "attributes": {
          "queryOnlyTemperatureControl": true,
          "temperatureUnitForUX": "C"
        },
        "state": {
          "temperatureSetpointCelsius": {
            "topic": "tele/esplight/SENSOR",
            "googleType": "numeric",
            "valueMap": [
              {
                "type": "regex",
                "googleReplace": "$1",
                "mqttSearch": ".*Temperature\":([0-9]+\\.[0-9]+).*"
              }
            ]
          },
          "temperatureAmbientCelsius": {
            "topic": "tele/esplight/SENSOR",
            "googleType": "numeric",
            "valueMap": [
              {
                "type": "regex",
                "googleReplace": "$1",
                "mqttSearch": ".*Temperature\":([0-9]+\\.[0-9]+).*"
              }
            ]
          }
        }
      }
    ],
    "customData": null
  }

it doesn't start due to the following error:

 google_home    | [12:07:43 FTL] The given key 'action.devices.commands.SetTemperature' was not present in the dictionary.
 google_home    | System.Collections.Generic.KeyNotFoundException: The given key 'action.devices.commands.SetTemperature' was not present in the dictionary.
 google_home    |    at System.Collections.Generic.Dictionary2.get_Item(TKey key)
 google_home    |    at HomeAutio.Mqtt.GoogleHome.Validation.DeviceTraitValidator.ValidateTrait(DeviceTrait deviceTrait, CommandType command, IEnumerable 1 commandParams, IEnumerable 1 stateKeys, IEnumerable 1 attributeKeys) in /app/HomeAutio.Mqtt.GoogleHome/Validation/DeviceTraitValidator.cs:line 396
 google_home    |    at HomeAutio.Mqtt.GoogleHome.Validation.DeviceTraitValidator.Validate(DeviceTrait deviceTrait) in /app/HomeAutio.Mqtt.GoogleHome/Validation/DeviceTraitValidator.cs:line 174

I tried to look in the code, but i've limited knowledge on google home and c#. I thought that the given code would work out of the box and would need to adapt it to my settings, but maybe something as changed since then?
I'm using latest docker version (2020-11-16T22:16:15.859900825Z)

Best regards

Its queryOnlyTemperatureSetting, not queryOnlyTemperatureControl. See: https://developers.google.com/assistant/smarthome/traits/temperaturesetting

Hello,
Thanks for such quick answer. I fixed the tag to queryOnlyTemperatureSetting but it still doesn't start unless I specify a command.
It's now working, but we have to specify a command tag.
Here is the full json I'm using for reference. It's a sonoff relay with temperature and humidity. I dissociate the 2 (plug & sensor) for convenience.

  "espperfumeRelay": {
    "id": "espperfumeRelay",
    "type": "action.devices.types.OUTLET",
    "disabled": false,
    "willReportState": false,
    "roomHint": "Hall",
    "name": {
      "defaultNames": [
        "Perfume"
      ],
      "name": "Perfume",
      "nicknames": []
    },
    "deviceInfo": null,
    "traits": [
      {
        "trait": "action.devices.traits.OnOff",
        "commands": {
          "action.devices.commands.OnOff": {
            "on": "esp-perfume/relay/0/set"
          }
        },
        "state": {
          "on": {
            "topic": "esp-perfume/relay/0",
            "googleType": "bool",
            "valueMap": [
              {
                "mqtt": "1",
                "type": "value",
                "google": "true"
              },
              {
                "mqtt": "0",
                "type": "value",
                "google": "false"
              }
            ]
          }
        }
      }
    ],
    "customData": null
  }
,

  "espPerfumeSensor": {
    "id": "espPerfumeSensor",
    "type": "action.devices.types.SENSOR",
    "disabled": false,
    "willReportState": false,
    "roomHint": "Hall",
    "name": {
      "defaultNames": [
        "Hall", "Hall sensor"
      ],
      "name": "Hall sensor",
      "nicknames": []
    },
    "deviceInfo": null,
    "traits": [
      {
        "trait": "action.devices.traits.TemperatureControl",
        "attributes": {
          "queryOnlyTemperatureSetting": true,
          "temperatureUnitForUX": "C"
        },      
        "commands": { "action.devices.commands.SetTemperature": { "temperature": "esp-perfume/temperature/set" } },
        "state": {
          "temperatureSetpointCelsius": {
            "topic": "esp-perfume/temperature",
            "googleType": "numeric"
          },
          "temperatureAmbientCelsius": {
            "topic": "esp-perfume/temperature",
            "googleType": "numeric"
          }
        }
      }
        ,
      {
        "trait": "action.devices.traits.HumiditySetting",
        "attributes": {
          "queryOnlyHumiditySetting": true
        },

        "state": {
          "humiditySetpointPercent": {
            "topic": "esp-perfume/humidity",
            "googleType": "numeric"
          },
          "humidityAmbientPercent": {
            "topic": "esp-perfume/humidity",
            "googleType": "numeric"
          }
        }
      }



    ],
    "customData": null
  }

I think we can close this "non" issue, but seems weird that the setTemperature must still be specified...

Best regards and best wishes for 2021 ;)

Ah, you're using TemperatureControl. not TermperatureSetting. my bad. Your original queryOnlyTemperatureControl is correct for that one, but the existing validation doesn't support that. I'm in the process of abandoning all that validation in favor of a simplified, generated validation layer based on the Google Home trait schemas (i.e., it can actually be actively maintained by a single human without going out of date every other week as Google changes things).

Im trying to get that into a releasable state now while I'm on vacation, but its enough of a rewrite I've been dragging my heels... I have to figure out how to best do a Docker pre-release so I and a few people can try it out...

For now you'll have to live with this, but watch for 2.0. It'll have a number of breaking changes, but pulls the trigger on some much needed changes.