You need to have an else, otherwise if none of the tests are met it’ll result in the error you’ve shown. You could make a dummy script that does nothing and use that as the else, or adapt your current logic to it by replacing the last test (Flur) with an else.
I can’t keep it straight though… is pos 1 0 indexed or 1 indexed? I’m used to seeing something like [data][0][entity_id]
You don’t need an else case if you have all the options of your input select covered by the if/elif statements.
You will have to fix the indentation, there is something wrong with editing it on this iPad.
Also there is no ‘state’ for the input select set option service. It is ‘option’:
// edit:
I changed added a “>” after the service_template. Otherwise the configuration check ended with an error.
But it is not working now. I get this error now:
Raum reinigen: Error executing script. Unexpected error for call_service at pos 1: Template rendered invalid service:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 87, in async_prepare_call_from_config
domain_service = cv.service(domain_service)
File "/usr/src/homeassistant/homeassistant/helpers/config_validation.py", line 411, in service
raise vol.Invalid(f"Service {value} does not match format <domain>.<name>")
voluptuous.error.Invalid: Service does not match format <domain>.<name>
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 154, in _async_step
self, f"_async_{cv.determine_script_action(self._action)}_step"
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 624, in _async_call_service_step
*self._prep_call_service_step(), blocking=True, context=self._context
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 253, in _prep_call_service_step
return async_prepare_call_from_config(self._hass, self._action, self._variables)
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 95, in async_prepare_call_from_config
) from ex
homeassistant.exceptions.HomeAssistantError: Template rendered invalid service:
trying to always use an ‘else’ clause, because the template might fail, how unexpected you might believe it to be, I mostly use the last option (elif in this case, or @123 's mapper) in the ‘else’ in my mappers:
action:
- service_template: >
{% set values = { 'Wohnzimmer': 'wohnzimmer', 'Schlafzimmer': 'schlafzimmer', 'Küche': 'kueche', 'Badezimmer': 'badezimmer', 'Büro': 'office', 'Eingangsbereich': 'eingangsbereich' } %}
{% set v = states('input_select.vacuum_room') %}
script.vacuum_{{ values[v] if v in values.keys() else 'flur' }}
serving 2 situations, either the true option for flur, or the guard (of course, you can’t determine if things went awol this way, but since you ‘know’ only these options will ever exist, you could have a go at it Cut a few extra lines creating an extra script ‘error’.
see this, I dont have any of the entities, and still flur is selected: