Send JSON with variable as Key value

Hi Guys,

Im trying to send a Json value as a key value in a service, If I try to send it manually everything is working.

service: xiaomi_miot.call_action
data:
  entity_id: vacuum.dreame_p2187_51af_robot_cleaner
  siid: 4
  aiid: 1
  params:
    - piid: 1
      value: 18
    - piid: 10
      value: '{"selects":[[6,1,0,2,1], [3,1,0,2,1]]}'
  force_params: true

But if I ty to input the value as a variable like:

  service: xiaomi_miot.call_action
data:
  entity_id: vacuum.dreame_p2187_51af_robot_cleaner
  siid: 4
  aiid: 1
  params:
    - piid: 1
      value: 18
    - piid: 10
      value: '{"selects":{{variable}}}'
  force_params: true

in the debugger it is sending:

    service: xiaomi_miot.call_action
data:
  entity_id: vacuum.dreame_p2187_51af_robot_cleaner
  siid: 4
  aiid: 1
  params:
    - piid: 1
      value: 18
    - piid: 10
      value:
        selects:
            -   -6
                -1
                -0
                -2
                -1
            -   -3
                -1
                -0
                -2
                -1
  force_params: true

How can I avoid this formatting?

Thanks!

It’s just that, a formatting. It’s the interpreation of json in yaml.
If you have an issue, it lies somewhere else.

The documentation says

  params:
    - 18 # piid: 1 - work-mode
    - '{"selects":[[7,1,0,2,1]]}' # piid: 10 - clean-extend-data

Thanks Chris,

But why isn’t it working then, if I run it with the variable I’m getting:

Executed: February 9, 2022, 13:06:44
Result:
params:
  domain: xiaomi_miot
  service: call_action
  service_data:
    entity_id: vacuum.dreame_p2187_51af_robot_cleaner
    siid: 4
    aiid: 1
    params:
      - piid: 1
        value: 18
      - piid: 10
        value:
          selects:
            - - 1
              - 2
              - 2
              - 2
              - 1
            - - 2
              - 2
              - 2
              - 2
              - 2
            - - 3
              - 2
              - 2
              - 2
              - 3
            - - 4
              - 2
              - 2
              - 2
              - 4
    force_params: true
  target: {}
running_script: false
limit: 10

If I hardcode the value in it shows up JSON formated.
Thanks!

Ah, yeah. As it’s a template, the json will be interpreted as an object rather than a string.
You should open an issue on the custom component side, I don’t see a workaround purely from HA.