How to get sensors value to snips tts

I am trying to get the temperature sensor reading from HA through Snips
my sensors have two variables most of them DHT11 on ESP8266 using esphomelib. my snips intent is

{
  "input": "tell me the bedroom temperature",
  "intent": {
    "intentName": "name:Query",
    "probability": 1
  },
  "slots": [
    {
      "rawValue": "bedroom",
      "value": {
        "kind": "Custom",
        "value": "bedroom"
      },
      "range": {
        "start": 12,
        "end": 19
      },
      "entity": "house_room",
      "slotName": "Location"
    },
    {
      "rawValue": "temperature",
      "value": {
        "kind": "Custom",
        "value": "temperature"
      },
      "range": {
        "start": 20,
        "end": 31
      },
      "entity": "switch",
      "slotName": "Device"
    }
  ]
}

I have tried multiple combinations like

snips:
intent_script:
  TurnOn:
    speech:
      type: plain
      text: OK, turning on the {{Location}} {{ Entity  }} 
    action:
    - service: switch.turn_on
      data_template:
        entity_id: 'switch.{{Location}}_{{Entity | replace(" ","_")}}'
      #entity_id: switch.bedroom_fan
 
  Query:
    speech:
      type: plain
      text: OK, Asked testing {{ states('sensor.{{Location}}_{{ Device }}') }} 

HA always sends

[Asr] captured text “tell me the bedroom temperature” in 3.0s


[Tts] was asked to say “testing unknown”

Looks like nested variables are not handled. My attempt with variable_template have also failed miserably.

Does anybody face this issue or it is my inability to work with the script. Any guidance is highly appreciated.

it would be helpful, if you managed not only to format the json code, but also the yaml code correctly (see hint at top of every forum page), so that one can see the indentation of your code. this is the intent_script that helps me determine the sensors that i’d like snips to read out loud.

intent_script:
  innenTemperaturIntent:
    action:
      - service: mqtt.publish
        data_template:
          topic: "devices/led-matrix/light/print/set"
          payload: '{{ states("sensor." + room.replace("ü", "ue") + "_temperaturx") }} C'
    speech:
      type: plain
      text: > 
          {% if site_id == "ivan" %}
              {% set room = room | default('kinderzimmer') | replace("ü", "ue") |replace("ä", "ae") |replace("ö", "oe") | lower %}
          {% else %}
              {% set room = room | default('kueche') | replace("ü", "ue") |replace("ä", "ae") |replace("ö", "oe") | lower %}
          {% endif %}
          {% if room == 'hier' and site_id == 'ivanka' %}
              {% set room = "kueche" %}
          {% elif room == 'hier' and site_id == 'ivan' %}
              {% set room = "kinderzimmer" %}
          {% endif %}
          {% if room != 'wohnung' %}
              Die Temperatur {{ room }} ist
              {{ states("sensor." + room.replace("ü", "ue") + "_temperaturx") }}
              Grad, 
              {% if room != 'server' and room != "serverraum" and room != 'balkon' and room != 'hof' %}
                  Die Luftfeuchtigkeit beträgt
                  {{ states("sensor." + room.replace("ü", "ue") + "_luftfeuchtigkeitx") }}
                  Prozent. 
              {% endif %}
              {% if room == 'balkon' or room == "hof" %}
                  {{ [
                       "Der Wetterdienst misst die Aussentemperatur derzeit mit ",
                       "Das Internet sagt, Aussen sei es ",
                       "Offiziell sind draussen ",
                       "Andere Wetterstationen messen derzeit "
                       ] | random }}
                  {{ states("sensor.dark_sky_temperature") | round(0) }}
                  Grad. 
              {% endif %}
          {% endif %}
          {% if room == 'wohnung' %}
              Die Durchschnittstemperatur in der Wohnung beträgt
              {{ states("sensor.wohnung_temperaturx") }}
              Grad, die durchschnittliche Luftfeuchtigkeit liegt im Moment bei
              {{ states("sensor.wohnung_luftfeuchtigkeitx") }}
              Prozent.
          {% endif %}

the probable cause for your „unknown“ is that you don’t have an entity id called sensor.{{Location}}_{{Device}}. it should be something like this (assuming the intent returns both slots values Location and Device):

intent_script:
  Query:
    speech:
      type: plain
      text: OK, Asked testing {{ states(‘sensor.' + Location + '_' + Device) }}

Hi @diplix
Thanks for your reply and that really helped.

Sorry for wrong formatting as this was my first post, I will ensure correct formatting going further.

Somehow, I am not able to get to the correct documentation and being a firmware and Linux device driver engineer have very poor hands on YAML and Python. Can you please point me to the correct documentation.

Thanks again and Merry Christmas.

Hi @diplix,

I was able to implement the sensor reading.

With a single post you taught me multiple things, that are;

  1. use of the intent variables
  2. use of the if-else condition (I am not a python programmer yet.)
  3. Explained how to use variable in the script.

Thank you once again.

I created one script that I would like to share for benefit of someone struggling like me. Hope I get the formatting correct.

snips:
  
intent_script:
  TurnOn:
    speech:
      type: plain
      text: OK, turning on the {{Location}} {{ Entity  }} 
    action:
    - service: switch.turn_on
      data_template:
        entity_id: 'switch.{{Location}}_{{Entity | replace(" ","_")}}'     
  TurnOff:
    speech:
      type: plain
      text: OK, turning off the {{Location}} {{ Entity }} 
    action:
    - service: switch.turn_off
      data_template:
        entity_id: 'switch.{{Location}}_{{Entity| replace(" ","_")}}'
  Query:
    speech:
      type: plain
      text: >
          {% set device_value =  states('sensor.' + Location + '_' + Device)  %}
          {% if  device_value  == "unknown" %}
                I am unable to find the {{ Device }} device in  {{ Location }}
          {% elif Device   == 'temperature' %}
             the {{ Location }}  {{ Device }} is {{ device_value }} Celsius
          {% elif Device  == 'humidiy' %}
             the {{ Location }}  {{ Device }} is {{ device_value }} percent 
          {% else %}
             the {{ Location }}  {{ Device }} is {{ device_value }}         
          {% endif %}

great, glad i could help. the normal HA-documentation is pretty good for basic yaml and template (jinja2) configuration. however most of the stuff i implemented i learned here in the community. there is a lot of tricky stuff you can do with jinja — and a lot of restrictions, too. but i found answers to almost all questions i ran into here in the community.