Problem with Alexa Intent

Hello,

I can successfully get the status of different sensors to Alexa, but I’m having trouble setting the temperature of one of my thermostats from Alexa.

Here’s what I have in my yaml file:
SetDownstairsTemp:
action:
service: climate.set_temperature
data:
entity_id: climate.downstairs
temperature: {{downtemp}}
speech:
type: plaintext
text: Okay, set downstairs temperature to {{downtemp}}

And the intent:

{
“intent”: “SetDownstairsTemp”,
“slots”: [
{
“name”: “downtemp”,
“type”: “AMAZON.NUMBER”
}]
}

I get the following error when restarting HA:

ERROR:homeassistant.util.yaml:invalid key: “OrderedDict([(‘downtemp’, None)])”

If I put in a hardcoded value instead of {{downtemp}} for temperature, it all works fine. How can I use downtemp correctly?

Thank you!

Please use preformatted text so that we can spot formatting errors.

Also, when you test from the tester in the Amazon skill setup, what data are you seeing being sent to HASS? Is it correctly sending the key/value pair of “downtemp” and a number?

Hi ih8gates,

Thanks for the quick reply.

It is being sent across from the Amazon tester correctly. The response text from HA shows the value that Amazon sent. I just can’t start HA when I try to set temperature to {{downtemp}}.

SetDownstairsTemp:
  action:
    service: climate.set_temperature
    data:
      entity_id: climate.downstairs
      temperature: {{downtemp}}
  speech:
    type: plaintext
    text: Okay, set downstairs temperature to {{downtemp}}

    {
      "intent": "SetDownstairsTemp",
      "slots": [
      {
        "name": "downtemp",
        "type": "AMAZON.NUMBER"
      }]
    }

Oh - I see. You need to let HASS know that’s templated data. (data_template vs data)

  action:
    service: climate.set_temperature
    entity_id: climate.downstairs
    data_template:
      temperature: {{downtemp}}

Though this would be fine, too:

  action:
    service: climate.set_temperature
    data_template:
      entity_id: climate.downstairs
      temperature: {{downtemp}}

I tried both of those and I’m still getting the same error, unfortunately.

Looking at one of the example yaml files, it looks like the data_template should work:

action:
        - service: logbook.log
          data_template:
            message: The location of {{ User }} has been queried via Alexa.

I was trying to base mine off of the example on the climate component page:

automation:
  trigger:
    platform: time
    after: "07:15:00"
  action:
    - service: climate.set_temperature
      data:
        entity_id: climate.kitchen
        temperature: 24
        operation_mode: Heat

If I use float({{downtemp}}), HA starts fine. But when Amazon calls the intent, the set_temperature service is passed ‘float(72)’ and it complains about not getting a float value.

Ah. I’d only been using Alexa data in a string context. Casting/typing hadn’t occurred to me.

How 'bout if you try: {{ downtemp | float }}

Jinja uses | to separate filters.

That got me back to the invalid key error. It’s definitely some type of formatting issue, just have to figure out the right way. Thanks again for all the suggestions.

@nbroyer

Did you figured out the Problem? I’m stuck at the same point with OrderedDict Thing

Hey,

I’m on step ahead:

with this in alex.yaml:

  VolumeDenon:
    action:
      service: input_slider.select_value
      data_template:
        entity_id: input_slider.volume_setpoint
        value_template: >
          value: {{ Volume }}

I’m getting in the LOG:

17-02-04 20:47:58 ERROR (MainThread) [homeassistant.core] Invalid service data for input_slider.select_value: extra keys not allowed @ data['value_template']. Got 'value: 20'
required key not provided @ data['value']. Got None

But why?

Sorry for the delay. I did get something working and meant to update this post but forgot. Here’s what I am using:

SetDownstairsTemp:
      action:
        service: climate.set_temperature
        entity_id: climate.downstairs
        data_template:
          temperature: ({{ downtemp }} | float)

He,

hmm looks like this is not working.

Heres my Intent:

  VolumeDenon:
    action:
      service: input_slider.select_value
      entity_id: input_slider.volume_setpoint
      data_template:        
        value: ({{ volume }} | float)

Log now saying:

Invalid service data for input_slider.select_value: expected float for dictionary value @ data['value']. Got '(20 | float)'

Twenty is what i tried to set via Alexa

Sorry, you’re right. I thought I had this working but apparently I don’t… I had moved on to something else and forgot to finish this. I just checked and I am getting the same error as you with this code.

I’m pretty sure you need:

SetDownstairsTemp:
      action:
        service: climate.set_temperature
        entity_id: climate.downstairs
        data_template:
          temperature: {{ downtemp | float }}

Not tested, but that’s how filters and templates work. You won’t ever have () around a template - at least at the outside.

I did try that again, but it’s still giving me this error:

ERROR:homeassistant.util.yaml:invalid key: “OrderedDict([(‘downtemp | float’, None)])”

This is what I wrote for my volume intents:

SetVolumeIntent:
  action:
    service: media_player.volume_set
    data_template:
      entity_id: media_player.yamaha_receiver
      volume_level: >-
        {%- if Level|int in range(10,81) -%}
          {%- set n = Level|float -%}
          {{ (1.0-( n / 100.0 )) | round(0.00) }}
        {%- endif -%}
  speech:
    type: plaintext
    text: OK

You are going to need to figure out the conversion from speech to input. In this case above, I wanted my intent input to be in decibels. So I say “Alexa, ask home to set volume to 25” which converts 25 into the volume (which happens to be 0.75).

Figure out what you need for the conversion and use that template. This is my alexa intent for this:

  "intent": "SetVolumeIntent",
  "slots": [
  {
    "name": "Level",
    "type": "Levels"
  }]

I made a slot with all the Levels I wanted to allow. I didn’t want my speaker to blow up so I use the alexa slot to limit the inputs instead of using AMAZON.NUMBER.

Basically you can use this principle for creating the temperature. You just need to find the attribute you are using and fill it in with the appropriate number. As I said before, you may need to convert the number you speak into the number that the attribute desires. For example, if your temperature attribute requires ºC and you say ºF, then you need to convert it before placing it in that attribute through the design_template.

Try this:

SetDownstairsTemp:
      action:
        service: climate.set_temperature
        data_template:
          entity_id: climate.downstairs
          temperature: {{ downtemp | float }}

Notice that the entity_id is in the data_template.

Hi Petro,

The above did not work for me either, I still got the same error. But looking at your post before that, I was able to get this to work:

SetDownstairsTemp:
  action:
    service: climate.set_temperature
    data_template:
      entity_id: climate.downstairs
      temperature: >-
        {% set n = downtemp|float %}
        {{ n }}

Thanks so much!