Open Drealine opened 1 year ago
You must know that the HA service has no return value (maybe the official is trying to support it). So this component uses events to publish the result of the service:
description: Example of obtaining miot action result
mode: queued
max: 10
trigger:
- platform: state
entity_id:
- input_button.action
id: miot_action
alias: When button been pressed
- platform: event
event_type: xiaomi_miot.call_miot_action
event_data:
# filter this event
entity_id: sensor.your_miot_entity_id
siid: 2
aiid: 1
id: miot_event
alias: When the action event is fired
condition: []
action:
- choose:
- conditions:
- condition: trigger
id: miot_action
sequence:
- service: xiaomi_miot.call_action
data:
entity_id: sensor.your_miot_entity_id
siid: 2
aiid: 1
params: []
throw: false
- conditions:
- condition: trigger
id: miot_event
sequence:
- service: system_log.write
data:
level: warning
message: "{{ trigger.event.data }}"
Tk @al-one! So if I understand correctly, this automation use the id set by user in the automation. So if I've another automations, it's possible that the automation get a false result of miot_action_result ? For example, I use three times automation to set program of my petfeeder which has the same siid and aiid.
No possible to filter event with params set in call_service ?
The action params are not currently fired to the event data, maybe you can use did
, it can be customized to any string.
description: Example of obtaining miot action result
mode: queued
max: 10
trigger:
- platform: state
entity_id:
- input_button.action
id: miot_action
alias: When button been pressed
- platform: event
event_type: xiaomi_miot.call_miot_action
event_data:
# filter this event
did: my-action-1
id: miot_event
alias: When the action event is fired
condition: []
action:
- choose:
- conditions:
- condition: trigger
id: miot_action
sequence:
- service: xiaomi_miot.call_action
data:
entity_id: sensor.your_miot_entity_id
did: my-action-1
siid: 2
aiid: 1
params: []
throw: false
- conditions:
- condition: trigger
id: miot_event
sequence:
- service: system_log.write
data:
level: warning
message: "{{ trigger.event.data }}"
Tk. Using did not be good because I want to have all results from same siid and aiid with the same device. It's possible to implement fire event with params on the code ?
The idea is for example:
Fire event from an automation which get siid, aiid and params (ex : set 10 grams at 6'oclock) to have the result if the command is ok or not and turn on/off a virtual boolean. So add fire event from params coupled to siid and aiid should be great :)
params
has been added to the event data.
Tk a lot! I appreciate :)
When event fired, params return like this :
params: []
No list return so can't filtering event.
Hi Using this :
Didn't work :
Hi, How can I get the value from miot_action_result in automation after call service and throw result ? I can use the attribute entity of the parent but if some automations are called at the same time, it give me some false results when read the attribute. Tk a lot!