Need help with if statement in intent_script and MQTT variable

Hi Folks!

I am testing for hours now, and I don’t get it:

I have an intent_script (with snips.ai) and I am trying to switch TV states for an automation.

The intent_script section is like:

modus: #the intent name from snips via mqtt
speech:
type: plain
text: ‘schalte {{ modustv }}’ # modustv is the JSON special variable from mqtt - setting "sky, kodi, playstation…
action:
- service: input_select.select_option
data:
entity_id: input_select.tvscene
option: '{% if modustv == “kodi” %}Kodi{%endif%}'

The option line is my problem. I tried many many versions of if statements in many many variants, but I do not get my wanted “option” set the right way. If I try “option: Sky” manually everything works.

I try to read the intent script mqtt variable “modustv”, and set the right options, depending on the variable:

‘kodi’ should be set as option ‘Kodi’
‘sky’ should be set as option ‘Sky’
and so on
I need it case sensitive…

Please help. I think it must be so easy…

THANKS!

does

option: '{% if {{ modustv }} == “kodi” %}Kodi{% endif %}'

not work?

excat. That is my problem…

The Snips intent is now set to:

modus:
speech:
type: plain
text: ‘schalte {{ modustv }}’
action:
- service: input_select.select_option
data:
entity_id: input_select.tvscene
option: ‘{% if {{ modustv }} == “kodi” %}Kodi{% endif %}’

My JSON returning from snips is:

{
“sessionId” : “a795edb4-e5ce-4fd7-8c93-f7eecd432343”,
“customData” : null,
“siteId” : “default”,
“input” : “tv modus kodi”,
“asrTokens” : [ [ {
“value” : “tv”,
“confidence” : 1.0,
“range_start” : 0,
“range_end” : 2,
“time” : {
“start” : 0.0,
“end” : 0.45
}
}, {
“value” : “modus”,
“confidence” : 1.0,
“range_start” : 3,
“range_end” : 8,
“time” : {
“start” : 0.45,
“end” : 0.48
}
}, {
“value” : “kodi”,
“confidence” : 1.0,
“range_start” : 9,
“range_end” : 13,
“time” : {
“start” : 0.48,
“end” : 2.1
}
} ] ],
“intent” : {
“intentName” : “kruemelbytes:modus”,
“probability” : 0.9818434
},
“slots” : [ {
“confidence” : 1.0,
“rawValue” : “modus kodi”,
“value” : {
“kind” : “Custom”,
“value” : “kodi”
},
“range” : {
“start” : 3,
“end” : 13
},
“entity” : “modustv”,
“slotName” : “modustv”
} ]
}

And the original input select looks like:

tvscene:
name: TV Modus
options:
- wählen
- Sky
- Kodi
- Playstation
- Apple TV
initial: wählen
icon: mdi:television

So, if I set “option: Sky” or Kodi by hand it works, and for me the modustv variable looks right (and the audio feedback from speech: is correct). I have no clue why the “if” combination isn’t working here. And to be honest I have no idea how to have a visual feedback for the set variable at the moment the intent fires…

solved

I found it!

- service: input_select.select_option
  data_template:
    entity_id: input_select.tvscene
     #option: '{% if {{ modustv }} == "kodi" %}Kodi{% endif %}'
    option: '{{ modustv }}'

I had to use “data_template” instead of pure “data”. Now I can choose the plain variable or the “if else” package. The right combination made it!