Hi all,
I’m running of of ideas how to achieve my goal , so asking out loud - PLEASE HELP ME!!!
I want to have a script for my Xiaomi Vacuum zoned cleanup. A zone is basically an array / a list of 4 integer values/coordinates defining a rectangular area.
The idea is that the zones to be cleaned up (the number of zones) should be dependent on input_boolean values. I defined a couple of input_boolean in my config and now depending on which one is ‘on’ I want to add a list of 4 ints to a service data payload e.g. [1,2,3,4]. So if input_boolean is ‘on’ then a zone is added as a list of 4 ints.
At the end the service has a parameter “zone” that needs a list of lists e.g. [[1,2,3,4]] or [[1,2,3,4], [5,6,7,8]]. Number of lists within the main list should depend on input_boolean.
Simplifying things (my real config is more complex and contains more zones):
- input_boolean.living_room corresponds to example coordinates [25500, 20000, 28000, 25500]
- input_boolean.kitchen corresponds to example coordinates [20000, 20000, 24000, 25500]
Script syntax:
vacuum_selected:
alias: Vacuum selected zones
sequence:
- data_template:
entity_id: vacuum.xiaomi
zone:
- >-
{% if is_state('input_boolean.living_room', 'on') -%}
{{[25500|int, 20000|int, 28000|int, 25500|int]}},
{%- endif %}
{% if is_state('input_boolean.kitchen', 'on') -%}
{{[20000|int, 20000|int, 24000|int, 25500|int]}}
{%- endif %}
repeats: 1
service: vacuum.xiaomi_clean_zone
This doesn’t work and gives the following result in logs:
File “/usr/local/lib/python3.7/site-packages/voluptuous/schema_builder.py”, line 427, in validate_mapping
raise er.MultipleInvalid(errors)
voluptuous.error.MultipleInvalid: None @ data[‘zone’][0]
I decided to try the ‘native’ list characters as using YAML syntax (the “-” character) for each potential list entry would result in empty list elements. So I think I can’t use the following syntax:
vacuum_selected:
alias: Vacuum selected zones
sequence:
- data_template:
entity_id: vacuum.xiaomi
zone:
- >-
{% if is_state('input_boolean.living_room', 'on') -%}
{{25500|int, 20000|int, 28000|int, 25500|int}},
{%- endif %}
>-
{% if is_state('input_boolean.kitchen', 'on') -%}
{{[20000|int, 20000|int, 24000|int, 25500|int]}}
{%- endif %}
repeats: 1
service: vacuum.xiaomi_clean_zone
Assuming that one of the input_boolean is ‘off’ the second syntax would rather result in an empty list element.
I’ve also tried the list
jinjia filter:
vacuum_selected:
alias: Vacuum selected zones
sequence:
- data_template:
entity_id: vacuum.xiaomi
zone:
- >-
{% if is_state('input_boolean.living_room', 'on') -%}
{{(25500|int, 20000|int, 28000|int, 25500|int)|list}},
{%- endif %}
{% if is_state('input_boolean.kitchen', 'on') -%}
{{[20000|int, 20000|int, 24000|int, 25500|int]}}
{%- endif %}
repeats: 1
service: vacuum.xiaomi_clean_zone
but no luck - the logs show the same output.
In all cases I’ve tried - the template editor shows the correct output after the jinjia template is rendered. So it doesn’t help much basically
I’ve got no clue why this doesn’t map to a list and why is the service complaining. BTW - HA does not deliver enough debugging information in the logs. I’d love to see variable values like the service payload defined in the ‘data_template’ section. This would greatly help getting cases like this resolved.
Hopefully there are some jinjia-ninjas out there in the community to help me get this resolved. Thanks!