Hi, I’m trying to call service - xiaomi_miot.call_action which requires aiid as part of the data parameter. If I set static values, the service call works. ex -
tap_action:
action: call-service
service: xiaomi_miot.call_action
service_data:
entity_id: vacuum.mimop
siid: 2
aiid: 3
But if try to make it dynamic with a script, the script doesnt works. I’ve tried multiple scripts:
aiid: >
{% if is_state(entity, 'docked') | is_state(entity, 'paused') | is_state(entity, 'idle') | is_state(entity, 'returning') %}
{% set mode = state_attr(entity, 'vacuum.mode') | int(default=0) %}
{% if mode == 0 %}
{% set id = 3 | int(default=2) %}
{% elif mode == 1 %}
{% set id = 5 | int(default=2) %}
{% elif mode == 2 %}
{% set id = 6 | int(default=2) %}
{% else %}
{% set id = 2 | int(default=2) %}
{% endif %}
{{id}}
{% else %}
{% set id = 2 | int(default=2) %}
{{id}}
{% endif %}
^ this gives an error ‘expected int for dictionary value @ data[‘aiid’]’
aiid: >
[[[
return `[[[
if(entity.state === 'docked' || entity.state === 'paused' || entity.state === 'idle' || entity.state === 'returning') {
if (entity.attributes.vaccum.mode) {
if (entity.attributes.vaccum.mode == 0)
return 3
else if (entity.attributes.vaccum.mode == 1)
return 5
else if (entity.attributes.vaccum.mode == 2)
return 6
else
return 2
} else {
return 2
}
} else {
return 2
}
]]]`
]]]
this doesnt work with error stating unknow parameter - mode.
Any help to correct the script would be appreciated.
Also, is there any way that i can use 2 entities in the script? Something like -
aiid: >
[[[
return `[[[
if(entity.state === 'docked' || entity.state === 'paused' || entity.state === 'idle' || entity.state === 'returning') {
if (select.mimop_mode === 'Sweep')
return 3
else if (select.mimop_mode === 'Mop')
return 6
else if (select.mimop_mode === 'Sweep And Mop')
return 5
else
return 2
} else {
return 2
}
]]]`
]]]
Update: Even this doesnt works:
aiid: >
[[[
return `[[[
if(states['vacuum.mimop'] === 'docked' || states['vacuum.mimop'] === 'paused' || states['vacuum.mimop'] === 'idle' || states['vacuum.mimop'] === 'returning') {
if (states['select.mimop_mode'] === 'Sweep')
return 3
else if (states['select.mimop_mode'] === 'Mop')
return 6
else if (states['select.mimop_mode'] === 'Sweep And Mop')
return 5
else
return 2
} else {
return 2
}
]]]`
]]]
7 posts - 2 participants