Snips intent_script variable in data_template

Heyho,

I’ve got a quick question about snips and templating. Right know I’m struggling with the following:

  • two different entity_ids (already working in snips and mqtt…)

  • turning up the temperature by one step depending on the entity_id I told snips.

    HeatingUp:
      action:
        - service: climate.set_temperature
          data_template:
            entity_id: climate.heizung_{{ deviceLocation }}
            temperature: {{ states.climate.heizung_{{deviceLocation}}.attributes.temperature + 1 }}
    

The problem is now I have two different deviceLocation and in the upper part of the template everything works fine. The entity_id results in

entity_id: climate.heizung_wohnzimmer or climate.heizung_schlafzimmer.

So far so good, but in the temperature row I can’t get it to work that HA uses the “deviceLocation” variable.
I tried:

  • [’ … '] which don’t give an error in the config but later HA says

Error rendering data template: UndefinedError: ‘None’ has no attribute ‘deviceLocation’

  • ‘deviceLocation’ and {{‘deviceLocation’}} which gives errors like

Invalid config for [intent_script]: invalid template (TemplateSyntaxError: expected token ‘end of print statement’, got ‘string’) for dictionary value @ data


When I hardcode it to:

temperature: "{{ states.climate.heizung_wohnzimmer.attributes.temperature + 1 }}"

everything works fine, but that means I would need 4 different intents (2 for temp. up and 2 for temp. down)


I already google quite a bit if there is a possiblity to make an if elif statement with a condition for ‘entity_id’,‘XYZ’ but I can’t find much. Its always with “state is_state” which won’t help me because the only condition I have is the entity_id at the beginning. Sure I could save the “told” entity_id in a separate (sensor) template and create an automation watching that sensor with state is_state but that’s too much code for that little function…

Welp

Could it be as simple as you need a space before and after deviceLocation, like you have in your entity_id?

Did you solve this problem? I am stuck with the same right now.

i think templates need to be encapsulated in quotes.

       temperature: "{{ states.climate[ 'heizung_' + deviceLocation ].attributes.temperature + 1 }}"

this could work. at least this is what i could get to work in the template-debugger:

{% set var = "ube" %}
{{ states.climate.stube.attributes.temperature + 1 }}
{{ states.climate['st' + var].attributes.temperature + 1 }}

1 Like

This is how i got it to work:

LichtDimmen:
  action:
  - service: light.turn_on
    data_template:
      brightness_pct: > 
        {% if state_attr(lampe , 'brightness')/255*100 < 90 %} 
          {{ (state_attr(lampe , 'brightness')/255*100) + 10 }}
        {% else %} 100 {% endif %}
      entity_id: "{{lampe}}"

“{{lampe}}” is the value which i get from Snips. It looks like inside the data_tamplate are no curly braces needed. Just lampe.

Wow thanks for the late reply.
In the meantime I kinda “solved” it with hard-coding that last part in the action which gives me still just one intent (instead of four).

  HeatingUpAndDown:
    action:
      - service: climate.set_temperature
        data_template:
          entity_id: climate.heizung_{{ deviceLocation | replace(" ","_") | replace ("-","_") }}
          temperature: >
            {% set heating_location = (deviceLocation) %}
            {% set temp_orientation = (tempUpDown) %}
            {% if heating_location == 'Wohnzimmer' and temp_orientation == 'hoch' %}
            {{ states.climate.heizung_wohnzimmer.attributes.temperature + 1 }}
            {% elif heating_location == 'Wohnzimmer' and temp_orientation == 'runter' %}
            {{ states.climate.heizung_wohnzimmer.attributes.temperature - 1 }}
            {% elif heating_location == 'Schlafzimmer' and temp_orientation == 'hoch' %}
            {{ states.climate.heizung_schlafzimmer.attributes.temperature + 1 }}
            {% elif heating_location == 'Schlafzimmer' and temp_orientation == 'runter' %}
            {{ states.climate.heizung_schlafzimmer.attributes.temperature - 1 }}
            {% endif %}

But I will definitely try the suggestions because my wall of code is ugly :sweat_smile: