ZHA - Xiaomi Mijia Round Wireless Switch (WXKG01LM) - lumi.sensor_switch

Hello @migetzu !

quote=“migetzu, post:40, topic:258472”]
I have used this blueprint and wireless switches, and they have worked fine. Untill now, “Hold” feature doesn’t work anymore. One click, two click etc. work well.
[/quote]

So, just to clear things: you were using the “Hold” feature, and it stopped working, or has it never worked for you?

This Blueprint had an issue regarding that, in the past. If you have imported this Blueprint a long time ago, try re-importing it again, in order to “update” it, and check if the issue is fixed!

Thanks!

Hey!

I changed hold time to 0.6 sec, import blueprint again and reload automations. Now everything work fine.

Thanks :smile:

1 Like

Good news! Glad I could help! :wink:

Hi,

Thank you for the great work.
Same thing happend as @migetzu .
Everything works before upgrading core.
After upgrade, everything other than long press works.

here’s the log when I remove and reapplied the blueprint and error occurred right after import.
Not sure if it is the gateway v3 causing it.

#1 Error Log

Invalid config for [automation]: Failed to load blueprint: Unable to find jodur/zha-xiaomi-mijia-round-wireless-switch-wxkg01lm-with-hold-lumi-sensor-switch.yaml (See /config/configuration.yaml, line 285).
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/blueprint/models.py", line 209, in _load_blueprint
    blueprint_data = yaml.load_yaml(self.blueprint_folder / blueprint_path)
  File "/usr/src/homeassistant/homeassistant/util/yaml/loader.py", line 112, in load_yaml
    with open(fname, encoding="utf-8") as conf_file:
FileNotFoundError: [Errno 2] No such file or directory: '/config/blueprints/automation/jodur/zha-xiaomi-mijia-round-wireless-switch-wxkg01lm-with-hold-lumi-sensor-switch.yaml'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/automation/config.py", line 104, in _try_async_validate_config_item
    config = await async_validate_config_item(hass, config, full_config)
  File "/usr/src/homeassistant/homeassistant/components/automation/config.py", line 68, in async_validate_config_item
    return await blueprints.async_inputs_from_config(config)
  File "/usr/src/homeassistant/homeassistant/components/blueprint/models.py", line 298, in async_inputs_from_config
    blueprint = await self.async_get_blueprint(bp_conf[CONF_PATH])
  File "/usr/src/homeassistant/homeassistant/components/blueprint/models.py", line 276, in async_get_blueprint
    blueprint = await self.hass.async_add_executor_job(
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/blueprint/models.py", line 211, in _load_blueprint
    raise FailedToLoad(
homeassistant.components.blueprint.errors.FailedToLoad: Failed to load blueprint: Unable to find jodur/zha-xiaomi-mijia-round-wireless-switch-wxkg01lm-with-hold-lumi-sensor-switch.yaml

#2 Error Log

Invalid config for [automation]: Failed to load blueprint: Unable to find jodur/zha-xiaomi-mijia-round-wireless-switch-wxkg01lm-with-hold-lumi-sensor-switch.yaml (See /config/configuration.yaml, line 285).
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/automation/config.py", line 104, in _try_async_validate_config_item
    config = await async_validate_config_item(hass, config, full_config)
  File "/usr/src/homeassistant/homeassistant/components/automation/config.py", line 68, in async_validate_config_item
    return await blueprints.async_inputs_from_config(config)
  File "/usr/src/homeassistant/homeassistant/components/blueprint/models.py", line 298, in async_inputs_from_config
    blueprint = await self.async_get_blueprint(bp_conf[CONF_PATH])
  File "/usr/src/homeassistant/homeassistant/components/blueprint/models.py", line 273, in async_get_blueprint
    return load_from_cache()
  File "/usr/src/homeassistant/homeassistant/components/blueprint/models.py", line 260, in load_from_cache
    raise FailedToLoad(
homeassistant.components.blueprint.errors.FailedToLoad: Failed to load blueprint: Unable to find jodur/zha-xiaomi-mijia-round-wireless-switch-wxkg01lm-with-hold-lumi-sensor-switch.yaml

#3 Error Log

Invalid config for [automation]: Integration 'xiaomi_gateway3' does not support device automation triggers (See /config/configuration.yaml, line 285).
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/device_automation/__init__.py", line 85, in async_get_device_automation_platform
    platform = integration.get_platform(platform_name)
  File "/usr/src/homeassistant/homeassistant/loader.py", line 498, in get_platform
    cache[full_name] = self._import_platform(platform_name)
  File "/usr/src/homeassistant/homeassistant/loader.py", line 503, in _import_platform
    return importlib.import_module(f"{self.pkg_path}.{platform_name}")
  File "/usr/local/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 855, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/config/custom_components/xiaomi_gateway3/device_trigger.py", line 2, in <module>
    from homeassistant.components.device_automation import TRIGGER_BASE_SCHEMA
ImportError: cannot import name 'TRIGGER_BASE_SCHEMA' from 'homeassistant.components.device_automation' (/usr/src/homeassistant/homeassistant/components/device_automation/__init__.py)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/automation/config.py", line 104, in _try_async_validate_config_item
    config = await async_validate_config_item(hass, config, full_config)
  File "/usr/src/homeassistant/homeassistant/components/automation/config.py", line 72, in async_validate_config_item
    config[CONF_TRIGGER] = await async_validate_trigger_config(
  File "/usr/src/homeassistant/homeassistant/helpers/trigger.py", line 49, in async_validate_trigger_config
    conf = await platform.async_validate_trigger_config(hass, conf)
  File "/usr/src/homeassistant/homeassistant/components/device_automation/trigger.py", line 17, in async_validate_trigger_config
    platform = await async_get_device_automation_platform(
  File "/usr/src/homeassistant/homeassistant/components/device_automation/__init__.py", line 91, in async_get_device_automation_platform
    raise InvalidDeviceAutomationConfig(
homeassistant.components.device_automation.exceptions.InvalidDeviceAutomationConfig: Integration 'xiaomi_gateway3' does not support device automation triggers

Hello @g91720 !

Looks like the Blueprint causing you issues is this one: ZHA - Xiaomi Mijia Round Wireless Switch (WXKG01LM) with HOLD - lumi.sensor_switch

At least from the logs! :slight_smile:
Look into that.

After the last update of the home assistant (core-2021.9.4 ) a single press after a short pause started a hold press, maybe someone can tell me what’s the matter?


Logger: homeassistant.helpers.template
Source: helpers/template.py:1485 
First occurred: 10:07:28 (32 occurrences) 
Last logged: 10:19:14

Template variable warning: 'dict object' has no attribute 'click_type' when rendering '{{ trigger.event.data.args.click_type }}'
Template variable warning: 'dict object' has no attribute 'attribute_name' when rendering '{{ trigger.event.data.args.attribute_name }}'
Template variable warning: 'dict object' has no attribute 'value' when rendering '{{ trigger.event.data.args.value }}'

Hello @Hari_Hari !

Please further explain the issue, so I can try and replicate it. I didn’t quite understand the use-case you are describing!

Thanks for the question.

When I press the button (single press), the button responds like a hold press with a long delay (5-10 sec).
However, everything was in order before. As it seems to me, as long as I changed the reaction time of hold from 0.6 to 1 second. Core was also updated to the latest version.
But for some reason, another exactly the same button also stopped responding correctly to a single press. Although I did not change the pressing time there. I’ve tried reinstalling blueprint. I also returned the time to its original state by 0.6. Unfortunately, the error remained.
Please tell me how, in your opinion, can I find the cause of the malfunction?

Summary

Logger: homeassistant.helpers.template
Source: helpers/template.py:1485 
First occurred: 21:55:12 (20 occurrences) 
Last logged: 21:58:42

Template variable warning: 'dict object' has no attribute 'click_type' when rendering '{{ trigger.event.data.args.click_type }}'
Template variable warning: 'dict object' has no attribute 'attribute_name' when rendering '{{ trigger.event.data.args.attribute_name }}'
Template variable warning: 'dict object' has no attribute 'value' when rendering '{{ trigger.event.data.args.value }}'


And also:


Logger: homeassistant.components.automation
Source: components/automation/__init__.py:632 
Integration: Автоматизация (documentation, issues) 
First occurred: 10:04:44 (1 occurrences) 
Last logged: 10:04:44

Blueprint ZHA - Mijia Wireless Remote Switch (WXKG01LM) generated invalid automation with inputs OrderedDict([('mijia_round_switch', '050f9238b5f01412c6bdcb4be5a75d45'), ('remote_button_short_press', [OrderedDict([('type', 'toggle'), ('device_id', '7696dd5e1852ad75ffe28d9096b2a237'),
 ('entity_id', 'light.684263012cf432d557b8'), ('domain', 'light')])]), ('remote_button_double_press', [OrderedDict([('type', 'toggle'), ('device_id', '2f5ff51df69808f6ca425a75b8b645fc'), 
('entity_id', 'light.ewelight_zb_cl01_edcd4c23_level_light_color_on_off'), ('domain', 'light')])]), ('remote_button_triple_press', [OrderedDict([('device_id', '04a380294417d17c1ad0d93ddcde831d'), ('domain', 'vacuum'), ('entity_id', 'vacuum.roborock_s5_max_ru'), ('type', 'clean')])]), ('remote_button_quadruple_press', [OrderedDict([('device_id', '04a380294417d17c1ad0d93ddcde831d'), ('domain', 'vacuum'), ('entity_id', 'vacuum.roborock_s5_max_ru'), ('type', 'dock')])]), ('remote_button_hold_press', 
[OrderedDict([('service', 'tts.google_translate_say'), ('data', OrderedDict([('entity_id', 'media_player.livingroom'),
 ('cache', True), ('language', 'ru'), ('message', 'Праваславное')]))]), OrderedDict([('delay', OrderedDict([('hours', 0), 
('minutes', 0), ('seconds', 3), ('milliseconds', 0)]))]), OrderedDict([('service', 'automation.turn_on'), ('target', OrderedDict([('entity_id', 'automation.kn_gost_svet_dublirovat')]))]), OrderedDict([('delay', OrderedDict([('hours', 0), ('minutes', 0), ('seconds', 2), ('milliseconds', 0)]))]), OrderedDict([('service', 'automation.turn_off'), ('target', OrderedDict([('entity_id', 
['automation.zha_mijia_wireless_remote_switch_wxkg01lm', 'automation.kn_gost_vaishnavskoe', 'automation.kn_gost_chetvertyi_1_2_3_4on_5off'])])), ('data', OrderedDict())])]), ('remote_button_multiple_press', [None])]): expected dictionary @ data['action'][1]['choose'][1]['sequence'][0]['choose'][3]['sequence'][0]. Got None



There was a solution to my problem.
Maybe someone will help. Who would have thought, but the update of the Raspberry pi 4 kernel version to 5.10.60 was to blame for everything.
After a subsequent update to the current version 5.10.63 using the

sudo rpi-update

command, the problem disappeared. And with this command you can check the kernel version.

uname -a

1 Like

Since last three updates of HA, I’ve started getting this error when starting HA - what’s strange the automation still works.

Logger: homeassistant.components.automation
Source: components/automation/__init__.py:646
Integration: Automatyzacja (documentation, issues)
First occurred: 20:17:27 (1 occurrences)
Last logged: 20:17:27

Blueprint ZHA - Mijia Wireless Remote Switch (WXKG01LM) generated invalid automation with inputs 
OrderedDict([('remote_button_short_press', [OrderedDict([('service', 'switch.toggle'), ('target', 
OrderedDict([('entity_id', 'switch.kitchen_ambient_light')]))])]), ('remote_button_double_press', 
[OrderedDict([('service', 'switch.toggle'), ('target', OrderedDict([('entity_id', 'switch.aqua_switch')]))])]), 
('remote_button_triple_press', [OrderedDict([('service', 'switch.turn_off'), ('target', 
OrderedDict([('entity_id', 'switch.kitchen_ambient_light')]))]), OrderedDict([('service', 'switch.turn_off'), 
('target', OrderedDict([('entity_id', 'switch.aqua_switch')]))])]), ('remote_button_quadruple_press', 
[OrderedDict([('service', '')])]), ('mijia_round_switch', 'befbdd5eefe955d872a094fc91f6c22b')]): Service 
does not match format <domain>.<name> for dictionary value @ data['action'][1]['choose'][1]
['sequence'][0]['choose'][2]['sequence'][0]['service']. Got None

I’ve deleted and reinstalled the blueprint and the automation - no luck. Can’t get rid of the error. From time to time the automation does not work - can’t find a reason for that - and then out of the blue it works again.

Hi, thanks a lot for the BluePrint!

I’ve installed it and create an automation but i cann’t make it work… :frowning:

When i pressed the button there’s no log so i tried to click “Run Actions” from the automation but it throws this error

""" Executed: November 19, 2021, 3:10:05 AM

Error: UndefinedError: 'dict object' has no attribute 'event'   """

The Step config is

"" variables:
  click_type: '{{ trigger.event.data.args.click_type }}'
  attrname: '{{ trigger.event.data.args.attribute_name }}'
  value: '{{ trigger.event.data.args.value }}'
  command: '{{ trigger.event.data.command }}' """

I’ve got no idea why it’s not working

Thanks!

I can’t seem to add my Aqara round switches with this blueprint. The model is listed as “lumi.sensor_switch” but under devices it says “No matching devices found”. These were added through Deconz.

Can anyone tell me what i’m missing? Or do i need to do something to get it picking up the devices?

This blueprint is for ZHA only

1 Like

Hi, all!
Recently I noticed few warnings in home assistant log and wanted to get them fixed.

Template variable warning: 'dict object' has no attribute 'attribute_name' when rendering '{{ trigger.event.data.args.attribute_name }}'
Template variable warning: 'dict object' has no attribute 'value' when rendering '{{ trigger.event.data.args.value }}'
Template variable warning: 'dict object' has no attribute 'click_type' when rendering '{{ trigger.event.data.args.click_type }}'

I came across release notes about Warnings for undefined variables in Templates, so the fix was quite easy - adding | default to action variables.

I also replaced action: {} with action: to stop my VSCode addon complaining about incorrect type.

Here’s the whole fixed blueprint:

blueprint:
  name: ZHA - Mijia Wireless Remote Switch (WXKG01LM)
  description: Automate your Xiaomi Mijia Wireless Round Remote Switch using ZHA events.
  domain: automation
  input:
    mijia_round_switch:
      name: Mijia Wireless Round Switch
      description: Mijia Wireless Round Switch to use
      selector:
        device:
          integration: zha
          manufacturer: LUMI
          model: lumi.sensor_switch
    remote_button_short_press:
      name: Single Press
      description: Action to run on single press
      default: []
      selector:
        action:
    remote_button_hold_press:
      name: Hold
      description: Action to run on hold
      default: []
      selector:
        action:
    holdtime:
      name: Time interval for hold detection, in seconds
      description: Time to wait until hold_press is activated
      default: 0.60
      selector:
        number:
          min: 0.15
          max: 2.5
          unit_of_measurement: seconds
          step: 0.05
          mode: slider
    remote_button_double_press:
      name: Double Press
      description: Action to run on double press
      default: []
      selector:
        action:
    remote_button_triple_press:
      name: Triple Press
      description: Action to run on triple press
      default: []
      selector:
        action:
    remote_button_quadruple_press:
      name: Quadruple Press
      description: Action to run on quadruple press
      default: []
      selector:
        action:
    remote_button_multiple_press:
      name: Multiple Press
      description: Action to run on multiple press
      default: []
      selector:
        action:
mode: parallel
max_exceeded: silent
trigger:
  - platform: event
    event_type: zha_event
    event_data:
      device_id: !input "mijia_round_switch"
action:
  - variables:
      click_type: "{{ trigger.event.data.args.click_type | default }}"
      attrname: "{{ trigger.event.data.args.attribute_name | default }}"
      value: "{{ trigger.event.data.args.value | default }}"
      command: "{{ trigger.event.data.command }}"
  - choose:
      - conditions:
          - "{{ attrname == 'on_off' }}"
          - "{{ value == true }}"
        sequence:
          - wait_for_trigger:
              - platform: event
                event_type: zha_event
                event_data:
                  device_id: !input "mijia_round_switch"
                  command: "attribute_updated"
                  args:
                    attribute_id: 0
                    attribute_name: on_off
                    value: false
            continue_on_timeout: true
            timeout: !input "holdtime"
          - choose:
              - conditions:
                  - condition: template
                    value_template: "{{ not wait.trigger }}"
                sequence: !input "remote_button_hold_press"
            default: !input "remote_button_short_press"
      - conditions:
          - condition: template
            value_template: "{{ command == 'click' }}"
        sequence:
          - choose:
              - conditions: "{{ click_type == 'double' }}"
                sequence: !input remote_button_double_press
              - conditions: "{{ click_type == 'triple' }}"
                sequence: !input remote_button_triple_press
              - conditions: "{{ click_type == 'quadruple' }}"
                sequence: !input remote_button_quadruple_press
              - conditions: "{{ click_type == 'furious' }}"
                sequence: !input remote_button_multiple_press

Even with the changes from @marek, this isn’t working anymore, stopped working sometime since May. It always thinks you’re holding the button even when you’re not, so single clicks don’t register half the time. I’m looking at the zha_event events, and sometimes it sends a “release” command, then an “on_off: true” command, then an “on_off: false” command, and then a “hold” command. It’s like it’s getting out of sync. Very strange

Hi, I would suggest to add also the ability to set an action for the “release” event (when you stop holding the button), here’s a nice way to do it:

First thing, we need a new input:

    remote_button_hold_release:
      name: Hold release
      description: Action to run on button release (when holded)
      default: []
      selector:
        action: {}

Then, we can add a new condition at the very end of the file:

      - conditions:
          - condition: template
            value_template: "{{ command == 'release' }}"
        sequence: !input "remote_button_hold_release"

I’ve just started trying to use this blueprint and noticed a couple of issues:

  1. I cannot get single click actions to work
  2. Having multiple actions seems to create problems where some don’t get executed.

I’ve had to simply not use single click for now and instead of having multiple actions I call a script and have all my actions in the script.

Not ideal but it works

Hello @mtrista , your issues might be caused by some issues on your ZigBee network, or even the switch, rather than the Blueprint/Automations. At least the automation is still working fine on several of my devices, running the latest HA version!

Hello @notherealmarco , I will consider your sugestion, if i have some time i will add the “release” event! Thanks!

Hello @sparkydave,
Have you used the Developer Tools, listening to the zha_events, to check if your issue is not related to the ZigBee network or your devices? I use these devices mostly with single click actions, and they have been working flawless for more than 1 year, always running the latest HA version!

Olá Carlos, esta blueprint está a dar-me imenso jeito a simplificar as minhas automações, muito obrigado!

Now in english, so everyone can understand.
I can confirm that the fix @marek suggested, removed the warnings that appeared on my log.

I have this exact issue. I used this blueprint on a previous setup with no issues, but I’ve just moved house and re-setup my HA from scratch and now all of my button single press actions trigger the hold action 9/10 times. Weirdly I’ve found hitting the button really hard seems to make the single press action trigger most of the time, but pressing it normally triggers the hold action.

A little baffled to be honest, all the multi press actions seem to work as expected. Running the latest version of HA (2022.12.9)