Blueprint | Issues with boolean variables handling

Hello!

I am currently trying to create a Blueprint for a Zigbee Xiaomi remote button, using ZHA events.
I managed to the the double, triple, quadruple and multiple button presses working, but the apparently most simple one, the “single” press, wasn’t working!

This is the important part of the Blueprint:

action:
- variables:
    args_attr_id: '{{ trigger.event.data.args.attribute_id }}'
    args_attr_name: '{{ trigger.event.data.args.attribute_name }}'
    args_val: '{{ trigger.event.data.args.value }}'
- choose:
  - conditions:
    - '{{ args_attr_id == 0 }}'
    - '{{ args_attr_name == ''on_off'' }}'
    - '{{ args_attr_name == 0}}'
    sequence: !input 'remote_button_short_press'
  - conditions:
    - '{{ args_attr_id == 32768 }}'
    - '{{ args_attr_name == ''Unknown'' }}'
    - '{{ args_val == 2 }}'
    sequence: !input 'remote_button_double_press'
  - conditions:
    - '{{ args_attr_id == 32768 }}'
    - '{{ args_attr_name == ''Unknown'' }}'
    - '{{ args_val == 3 }}'
    sequence: !input 'remote_button_triple_press'
  - conditions:
    - '{{ args_attr_id == 32768 }}'
    - '{{ args_attr_name == ''Unknown'' }}'
    - '{{ args_val == 4 }}'
    sequence: !input 'remote_button_quadruple_press'
  - conditions:
    - '{{ args_attr_id == 5 }}'
    - '{{ args_attr_name == ''model'' }}'
    - '{{ args_val == ''lumi.sensor_switch.aq2'' }}'
    sequence: !input 'remote_button_multiple_press'

Basically, all the conditions are working, except for the first one:

  - conditions:
    - '{{ args_attr_id == 0 }}'
    - '{{ args_attr_name == ''on_off'' }}'
    - '{{ args_attr_name == 0}}'
    sequence: !input 'remote_button_short_press'

After some debugging, I found out that the variable args_attr_name is being parsed into a Bool variable (by logging it’s value, i get either Bool.true or Bool.false), and that is causing the conditions not to be met.

I have tried stuff like:

    - '{{ args_attr_name == false}}'
    - '{{ args_attr_name == "false"}}'
    - '{{ args_attr_name == Bool.false}}'

But none of these work. Someone got a clue on how to compare bool variables?

Note: That variable being parsed into a boolean is weird behaviour, because there are other JSON fields that have the same value (0 as an example), and get parsed into integer fields, and are easily compared using the == operator!

Thanks in advance! :slight_smile:

Which integration you using ?

I am using ZHA. These are the zha_event event structures:

Single Press:

{
    "event_type": "zha_event",
    "data": {
        "device_ieee": "00:15:8d:00:02:04:15:fc",
        "unique_id": "00:15:8d:00:02:04:15:fc:1:0x0006",
        "device_id": "939484e5b4843ec3d741125a24c39dc6",
        "endpoint_id": 1,
        "cluster_id": 6,
        "command": "attribute_updated",
        "args": {
            "attribute_id": 0,
            "attribute_name": "on_off",
            "value": 0
        }
    },
    "origin": "LOCAL",
    "time_fired": "2020-12-23T12:28:45.727228+00:00",
    "context": {
        "id": "293c8fa7dc4a72c1e55cd19b6d26bdcf",
        "parent_id": null,
        "user_id": null
    }
}

Double Press:

{
    "event_type": "zha_event",
    "data": {
        "device_ieee": "00:15:8d:00:02:04:15:fc",
        "unique_id": "00:15:8d:00:02:04:15:fc:1:0x0006",
        "device_id": "939484e5b4843ec3d741125a24c39dc6",
        "endpoint_id": 1,
        "cluster_id": 6,
        "command": "attribute_updated",
        "args": {
            "attribute_id": 32768,
            "attribute_name": "Unknown",
            "value": 2
        }
    },
    "origin": "LOCAL",
    "time_fired": "2020-12-23T12:28:47.457940+00:00",
    "context": {
        "id": "974539afdd5c6ecdce77ce42055c734f",
        "parent_id": null,
        "user_id": null
    }
}

For the double press, the JSON parameter data.args.value is 2, and is parsed as an integer; for the single press, that same parameter (in this case the value is 0) gets parsed as a boolean.

Hello!
I have managed to get this working, but in order to do so, i had to stop using the variable args_val to perform the comparison:

action:
- variables:
    args_val: '{{ trigger.event.data.args.value }}'
- choose:
  - conditions:
    - "{{ trigger.event.data.args.value == 0 }}"
    sequence: !input 'remote_button_short_press'

I think this has something to do with the way the variables are handled that I just don’t understand! For now, I got this working, but if someone has the knowledge to enlighten me a bit more about this, i would be very much grateful :slight_smile:

In your conditions, it looks like you have a typo. I see args_attr_name twice for your single press.