Help with configuration intent_script: variables, quotes, brackets... {{ }} ""() over MQTT to HA

Hi guys,

I am struggling again with the syntax. And I cannot explain to myself why one config is working and the other’s not. Can you give me a hint please why its working the one way, but the other it’s not?

  1. This is the working one
intent_script:
  VacuumRoom:
    action:
      service: script.roborock_sauge_{{ room.replace("ü", "ue") }}

Basically rhasspy will send the “room” to HA and fills the variable with that. Then again via MQTT and a script the vacuum cleaner will be controlled to clean a specific room

  1. This one does not work
intent_script:
  VacuumRoom:
    action:
      data_template:
        entity_id: >
           script.{{ ("roborock_sauge_" + room.replace("ü", "ue")) }}
      service_template: >
          script.turn_on
  1. Ive tried it also this way, but this either did not work
intent_script:
  VacuumRoom:
    action:
      service: script.turn_on
      target:
        entity_id: {{ ("script." + "roborock_sauge_" + room.replace("ü", "ue")) }}

Am I thinking in the wrong direction? With #1 I just use the script as a service itself. With #2-3 my guess was that I can enable the script this way. Or is this the mistake? If so, does it mean my syntax with the variables would be right?

Kind regards

fb

AFAIK, there is no such service as script.turn_on

Yes, there is. See below.

There most certainly is, and it has an effect on how the script is executed:

1 Like

The issue is that you are missing quotes around your single line template. Try this:

intent_script:
  VacuumRoom:
    action:
      service: script.turn_on
      target:
        entity_id: '{{ ("script." + "roborock_sauge_" + room.replace("ü", "ue")) }}'

Hi

@koying There is. You can check yourself unter dev tools which are there. You will find even your own scripts at that place. There are really a damn lot :slight_smile:
@tom_l Awesome! That’s it. How can I know that the ‘’ are missing there? I’ve tried it even with #3, but here it’s not working. Can you explain me please why? Also especially why I don’t need to set the ‘’ in my working example?

Guess when I have it running in a better way I’ll share the configs. I can imagine there are other peeps out there who wan’t to controll their robot via cloudless voice commands :slight_smile:

Thanks you! :slight_smile:

cheers

fb

That I can’t explain. It really should be:

intent_script:
  VacuumRoom:
    action:
      service: 'script.roborock_sauge_{{ room.replace("ü", "ue") }}'

Read the templating docs, specifically this bit: https://www.home-assistant.io/docs/configuration/templating/#important-template-rules

@tom_l Sorry, my fault. Your code is working like a charm.

I meant this example (#2)

intent_script:
  VacuumRoom:
    action:
      data_template:
        entity_id: >
           script.{{ ("roborock_sauge_" + room.replace("ü", "ue")) }}
      service_template: >
          script.turn_on

I tried it here as well with the ‘’ like

script.’{{ (“roborock_sauge_” + room.replace(“ü”, “ue”)) }}’
and even with
‘{{ (“script.” + “roborock_sauge_” + room.replace(“ü”, “ue”)) }}’
or
‘{{ (“script.roborock_sauge_” + room.replace(“ü”, “ue”)) }}’

Multi line templates should not be quoted and the use of data_template and service_template were depreciated in v0.115. Also you do not have a service template. And the extra brackets in your templates will mess up the entity ids. So that reduces your config to:

intent_script:
  VacuumRoom:
    action:
      service: script.turn_on
      data:
        entity_id: >
           script.{{ "roborock_sauge_" + room.replace("ü", "ue") }}

Which is more correctly now done using target for the entity id.

intent_script:
  VacuumRoom:
    action:
      service: script.turn_on
      target:
        entity_id: >
           script.{{ "roborock_sauge_" + room.replace("ü", "ue") }}

With the extra brackets you would have ended up with:

script.(roborock_sauge_someroom)

Which is not a valid script entity id.

Thank you for clarification! :+1: