I think the only mistake there is the >
left over from copy-paste. Without it, that seems like a valid dictionary.
I’ll test it in a script to confirm (you may be right about the ç
).
I think the only mistake there is the >
left over from copy-paste. Without it, that seems like a valid dictionary.
I’ll test it in a script to confirm (you may be right about the ç
).
The biggest concern with that way is the special characters. If that does work the next hurdle would be the automatic typing which might turn corredor into a list of numbers.
I tested this script by passing gonçalo
to it and it reported 8
. Seems to have had no problem with the accented characters.
aspirar:
fields:
divisao:
description: "Divisão a aspirar"
sequence:
- variables:
rooms:
corredor: '1, 11'
pais: '3'
sala: '6'
meninos: '7'
gonçalo: '8'
cozinha: '9'
escritório: '12'
- service: notify.persistent_notification
data:
message: "{{ rooms.get(divisao, '') }}"
The master bedroom?
if that’s the case mixing the 2…
aspirar:
fields:
divisao:
description: "Divisão a aspirar"
sequence:
- variables:
rooms:
corredor: 1, 11
pais: 3
sala: 6
meninos: 7
gonçalo: 8
cozinha: 9
escritório: 12
div:
{% set which = divisao if divisao is iterable and divisao is not string else [ divisao ] %}
{% set ns = namespace(ret=[]) %}
{% for x in rooms.items() | list | selectattr('0', 'in', which) | map(attribute='1') | list %}
{% set v = [ x ] if x is is_number else x %}
{% set ns.ret = ns.ret + v %}
{% endfor %}
{{ ns.ret }}
- service: xiaomi_miot.call_action
target:
entity_id: vacuum.viomi_v18_e271_robot_cleaner
data:
siid: 4
aiid: 13
params: [0, 1, "{{ div | join(', ') }}"]
Funnily enough, when I had asked my question about passing multiple room names, I had already whipped up something to handle it. However, your version is more bulletproof because it validates the received data whereas mine assumes it arrives in the correct format (ergo “whipped up”).
aspirar:
fields:
divisao:
description: "Divisão a aspirar"
sequence:
- variables:
rooms:
corredor: '1, 11'
pais: '3'
sala: '6'
meninos: '7'
gonçalo: '8'
cozinha: '9'
escritório: '12'
div: >
{% set ns = namespace(d=[]) %}
{% for d in divisao.split(', ') %}
{% set ns.d = ns.d + [rooms.get(d, '0')] %}
{% endfor %}
{{ ns.d | join(', ') }}
- service: xiaomi_miot.call_action
target:
entity_id: vacuum.viomi_v18_e271_robot_cleaner
data:
siid: 4
aiid: 13
params: [0, 1, "{{ div }}"]
Yah, I’ve learned to never assume when it comes to the resolver. I.e. I always assume wrong
Love you guys Used this solution:
aspirar:
fields:
divisao:
description: "Divisão a aspirar"
sequence:
- variables:
rooms:
corredor: "1,11"
pais: "3"
sala: "6"
meninos: "7"
gonçalo: "8"
cozinha: "9"
escritório: "12"
- service: xiaomi_miot.call_action
data:
entity_id: vacuum.viomi_v18_e271_robot_cleaner
siid: 4
aiid: 13
params: [0, 1, "{{ rooms.get(divisao, '') }}"]
@petro the “battle room” is wherever the wife wants it to be
Now, the only problem I have is with “corredor” since it passes 2 room ids.
While testing the service call, this works:
service: xiaomi_miot.call_action
data:
entity_id: vacuum.viomi_v18_e271_robot_cleaner
siid: 4
aiid: 13
params: [0,1,"1,11"]
But for some reason, when using the script above, it doesn’t.
This shows up on the logs:
Viomi S9(viomi.vacuum.v18): Call miot action {'did': '329449566', 'siid': 4, 'aiid': 13, 'in': [{'piid': 36, 'value': 0}, {'piid': 37, 'value': 1}, {'piid': 38, 'value': (1, 11)}]} failed: {'code': -9999, 'message': 'user ack timeout'}
are you 100% sure that the 3rd param is a string of separated numbers?
well… it works on the service call directly just not via script
can you show what you use as a service call?
^^ this one
can you give this script a try then
I would have said that Home Assistant native typing converted the string "1,11"
into a tuple (1, 11)
. However, I hesitate to say that because I can’t explain why it only happens when the script executes the service call versus when the service call is executed from Developer Tools > Services.
I see it now.
The direct service call uses this:
params: [0,1,"1,11"]
whereas the script uses this:
params: [0, 1, "{{ rooms.get(divisao, '') }}"]
The result of the template within the list is this string '1,11'
and to native typing that looks like a tuple and so it gets converted to a tuple.
That would explain the appearance of the tuple in the error message:
{'piid': 38, 'value': (1, 11)}]}
^^^^^^^
Yeah, it was my first thought too, but since I’m a n00b on this I wanted to be sure here.
@petro
The metioned script is missing a “>” after div:
right? (otherwise it just has a ton of errors)
Anyway, with the “>” I have this error when it executes:
aspirar: Error executing script. Error rendering template for variables at pos 1: TypeError: can only concatenate list (not "str") to list
that’s possible
that’s not possible, there are no string + [] concatenations. Are you using the one I linked or a previous one
ah ok, then use this config instead. Apparently it does not type corredor
aspirar:
fields:
divisao:
description: "Divisão a aspirar"
sequence:
- variables:
rooms:
corredor: [1, 11]
pais: 3
sala: 6
meninos: 7
gonçalo: 8
cozinha: 9
escritório: 12
div:
{% set which = divisao if divisao is iterable and divisao is not string else [ divisao ] %}
{% set ns = namespace(ret=[]) %}
{% for x in rooms.items() | list | selectattr('0', 'in', which) | map(attribute='1') | list %}
{% set v = [ x ] if x is is_number else x %}
{% set ns.ret = ns.ret + v %}
{% endfor %}
{{ ns.ret }}
- service: xiaomi_miot.call_action
target:
entity_id: vacuum.viomi_v18_e271_robot_cleaner
data:
siid: 4
aiid: 13
params: [0, 1, "{{ div | join(', ') }}"]