Hi,
I am using an Aquara mini switch to toggle the lights on/off with an automation.
While the automation works fine, it randomly triggers without anyone pressing the button. It doesn’t seem to trigger when the lights have been turned off via their own application (philips hue) in the first place.
If you look at the trace from when the automation ran, it will give you all the details. I’m going to guess that the switch briefly went unavailable, so it’s state changed and triggered the automation.
Assuming that’s it, do some searching on the forum; there’s multiple ways to handle this.
Looking at the automation, any state change on the sensor will fire the action. So not just going from unavailable to available, but possibly also attribute changes if there are any (or will be added in the future). Depending on how the button is implemented, you need to look at a specific event that you are interested in (single click, long press,… ). I know too little about the particular switch to know what event you should look for.
Look in the Z2M device page (assuming this one).
You will have the names the action will take when the button is triggered (or in case of keyfobs, to identify multiple buttons).
This way you can identify and react to each action
trigger:
- platform: state
entity_id:
- sensor.switch_office_yan_action
to: single
id: SINGLE
- platform: state
entity_id:
- sensor.switch_office_yan_action
to: double
id: DOUBLE
- platform: state
entity_id:
- sensor.switch_office_yan_action
to: hold
id: HOLD
- platform: state
entity_id:
- sensor.switch_office_yan_action
to: release
id: RELEASE
action:
- choose:
- conditions:
- condition: trigger
id:
- SINGLE
sequence: []
- conditions:
- condition: trigger
id:
- DOUBLE
sequence: []
- conditions:
- condition: trigger
id:
- HOLD
sequence: []
- conditions:
- condition: trigger
id:
- RELEASE
sequence: []
If you want a simple on/off switch without caring how (single, double, hold), for that button you can probably use release only, which should trigger in all cases the same.
alias: Toggle Light Office Yan
description: ""
trigger:
- platform: state
entity_id:
- sensor.switch_office_yan_action
to: release
condition: []
action:
- service: light.toggle
data: {}
target:
area_id: office
mode: single
The “release” action needed me to hold the button for a second before the release got detected. I changed it to “Single” and it seems to work great so far!
Always a quirk with these buttons, you just have to find it!
Since release doesn’t work as I expected, be careful with only single as trigger, if, by mistake, you were to double-press (not sure how sensitive it is), it won’t trigger, unless you add it.
- platform: state
entity_id:
- sensor.switch_office_yan_action
to:
- single
- double
This will trigger if single-pressed OR double-pressed.