Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support zigbee2mqtt native button press counter for Phillips Hue dimmer switch #23

Open
lwfitzgerald opened this issue Mar 31, 2021 · 7 comments
Assignees
Labels
blueprint An issue related to a blueprint enhancement New feature or request

Comments

@lwfitzgerald
Copy link

Blueprint name: philips_324131092621

zigbee2mqtt natively includes a button press count in the state it sends to Home Assistant for the Phillips Hue dimmer switch (324131092621). This could be used for detecting double presses.

Here is an example Home Assistant event on a double press. Note the counter field.

{
    "event_type": "state_changed",
    "data": {
        "entity_id": "sensor.front_bedroom_switch_hue_action",
        "old_state": {
            "entity_id": "sensor.front_bedroom_switch_hue_action",
            "state": "",
            "attributes": {
                "action": "",
                "battery": 100,
                "brightness": 255,
                "counter": 1,
                "linkquality": 81,
                "update": {
                    "state": "available"
                },
                "update_available": true,
                "friendly_name": "front_bedroom_switch_hue_action",
                "icon": "mdi:gesture-double-tap"
            },
            "last_changed": "2021-03-31T19:23:27.559882+00:00",
            "last_updated": "2021-03-31T19:23:27.559882+00:00",
            "context": {
                "id": "4da0b7b4135ae48746b90d6c1854dfe5",
                "parent_id": null,
                "user_id": null
            }
        },
        "new_state": {
            "entity_id": "sensor.front_bedroom_switch_hue_action",
            "state": "",
            "attributes": {
                "action": "on-press",
                "battery": 100,
                "brightness": 255,
                "counter": 2,
                "duration": 0,
                "linkquality": 84,
                "update": {
                    "state": "available"
                },
                "update_available": true,
                "friendly_name": "front_bedroom_switch_hue_action",
                "icon": "mdi:gesture-double-tap"
            },
            "last_changed": "2021-03-31T19:23:27.559882+00:00",
            "last_updated": "2021-03-31T19:23:57.111797+00:00",
            "context": {
                "id": "1f5150192cead565b99d846442a213ab",
                "parent_id": null,
                "user_id": null
            }
        }
    },
    "origin": "LOCAL",
    "time_fired": "2021-03-31T19:23:57.111797+00:00",
    "context": {
        "id": "1f5150192cead565b99d846442a213ab",
        "parent_id": null,
        "user_id": null
    }
}
@lwfitzgerald lwfitzgerald added the bug Something isn't working label Mar 31, 2021
@EPMatt EPMatt added enhancement New feature or request and removed bug Something isn't working labels Mar 31, 2021
@EPMatt
Copy link
Owner

EPMatt commented Mar 31, 2021

Hi @lwfitzgerald, thank you for the suggestion. :)
Definitely a great idea, I'll look into this. Does the counter get updated for triple clicks as well?

@lwfitzgerald
Copy link
Author

Yep, and for four clicks.

Three click event:

{
    "event_type": "state_changed",
    "data": {
        "entity_id": "sensor.front_bedroom_switch_hue_action",
        "old_state": {
            "entity_id": "sensor.front_bedroom_switch_hue_action",
            "state": "",
            "attributes": {
                "action": "",
                "battery": 100,
                "brightness": 255,
                "counter": 1,
                "linkquality": 63,
                "update": {
                    "state": "available"
                },
                "update_available": true,
                "friendly_name": "front_bedroom_switch_hue_action",
                "icon": "mdi:gesture-double-tap"
            },
            "last_changed": "2021-03-31T20:06:11.474045+00:00",
            "last_updated": "2021-03-31T20:06:11.474045+00:00",
            "context": {
                "id": "374cbdcc734c501b7243f71c59283c48",
                "parent_id": null,
                "user_id": null
            }
        },
        "new_state": {
            "entity_id": "sensor.front_bedroom_switch_hue_action",
            "state": "",
            "attributes": {
                "action": "on-press",
                "battery": 100,
                "brightness": 255,
                "counter": 3,
                "duration": 0,
                "linkquality": 84,
                "update": {
                    "state": "available"
                },
                "update_available": true,
                "friendly_name": "front_bedroom_switch_hue_action",
                "icon": "mdi:gesture-double-tap"
            },
            "last_changed": "2021-03-31T20:06:11.474045+00:00",
            "last_updated": "2021-03-31T20:06:21.079485+00:00",
            "context": {
                "id": "b7e254717874b0b43f62209c3692d1d2",
                "parent_id": null,
                "user_id": null
            }
        }
    },
    "origin": "LOCAL",
    "time_fired": "2021-03-31T20:06:21.079485+00:00",
    "context": {
        "id": "b7e254717874b0b43f62209c3692d1d2",
        "parent_id": null,
        "user_id": null
    }
}

Four click event:

{
    "event_type": "state_changed",
    "data": {
        "entity_id": "sensor.front_bedroom_switch_hue_action",
        "old_state": {
            "entity_id": "sensor.front_bedroom_switch_hue_action",
            "state": "",
            "attributes": {
                "action": "",
                "battery": 100,
                "brightness": 255,
                "counter": 1,
                "linkquality": 70,
                "update": {
                    "state": "available"
                },
                "update_available": true,
                "friendly_name": "front_bedroom_switch_hue_action",
                "icon": "mdi:gesture-double-tap"
            },
            "last_changed": "2021-03-31T20:08:50.879375+00:00",
            "last_updated": "2021-03-31T20:08:50.879375+00:00",
            "context": {
                "id": "12f0cc018444de6d66894f132610092b",
                "parent_id": null,
                "user_id": null
            }
        },
        "new_state": {
            "entity_id": "sensor.front_bedroom_switch_hue_action",
            "state": "",
            "attributes": {
                "action": "on-press",
                "battery": 100,
                "brightness": 255,
                "counter": 4,
                "duration": 0,
                "linkquality": 73,
                "update": {
                    "state": "available"
                },
                "update_available": true,
                "friendly_name": "front_bedroom_switch_hue_action",
                "icon": "mdi:gesture-double-tap"
            },
            "last_changed": "2021-03-31T20:08:50.879375+00:00",
            "last_updated": "2021-03-31T20:09:00.466296+00:00",
            "context": {
                "id": "b1c77fd0cc644d2f4a54c64cf912c1e6",
                "parent_id": null,
                "user_id": null
            }
        }
    },
    "origin": "LOCAL",
    "time_fired": "2021-03-31T20:09:00.466296+00:00",
    "context": {
        "id": "b1c77fd0cc644d2f4a54c64cf912c1e6",
        "parent_id": null,
        "user_id": null
    }
}

@EPMatt
Copy link
Owner

EPMatt commented Mar 31, 2021

Hi @lwfitzgerald,

that's incredible. Does it work for all buttons, or only for the "on" one?

@lwfitzgerald
Copy link
Author

lwfitzgerald commented Apr 1, 2021

Does it work for all buttons, or only for the "on" one?

It works for all four buttons on the remote.

Brightness up 2 press event:

{
    "event_type": "state_changed",
    "data": {
        "entity_id": "sensor.front_bedroom_switch_hue_action",
        "old_state": {
            "entity_id": "sensor.front_bedroom_switch_hue_action",
            "state": "",
            "attributes": {
                "action": "",
                "battery": 100,
                "brightness": 255,
                "counter": 1,
                "linkquality": 65,
                "update": {
                    "state": "available"
                },
                "update_available": true,
                "friendly_name": "front_bedroom_switch_hue_action",
                "icon": "mdi:gesture-double-tap"
            },
            "last_changed": "2021-04-01T11:39:11.641006+00:00",
            "last_updated": "2021-04-01T11:39:11.641006+00:00",
            "context": {
                "id": "e3a1eed2c8cc1893b4120faeb9fe6576",
                "parent_id": null,
                "user_id": null
            }
        },
        "new_state": {
            "entity_id": "sensor.front_bedroom_switch_hue_action",
            "state": "",
            "attributes": {
                "action": "up-press",
                "battery": 100,
                "brightness": 255,
                "counter": 2,
                "duration": 0,
                "linkquality": 65,
                "update": {
                    "state": "available"
                },
                "update_available": true,
                "friendly_name": "front_bedroom_switch_hue_action",
                "icon": "mdi:gesture-double-tap"
            },
            "last_changed": "2021-04-01T11:39:11.641006+00:00",
            "last_updated": "2021-04-01T11:39:15.125600+00:00",
            "context": {
                "id": "ae24db4250606da7078a7f64e79192fe",
                "parent_id": null,
                "user_id": null
            }
        }
    },
    "origin": "LOCAL",
    "time_fired": "2021-04-01T11:39:15.125600+00:00",
    "context": {
        "id": "ae24db4250606da7078a7f64e79192fe",
        "parent_id": null,
        "user_id": null
    }
}

Brightness down 3 press event:

{
    "event_type": "state_changed",
    "data": {
        "entity_id": "sensor.front_bedroom_switch_hue_action",
        "old_state": {
            "entity_id": "sensor.front_bedroom_switch_hue_action",
            "state": "",
            "attributes": {
                "action": "",
                "battery": 100,
                "brightness": 1,
                "counter": 1,
                "linkquality": 73,
                "update": {
                    "state": "available"
                },
                "update_available": true,
                "friendly_name": "front_bedroom_switch_hue_action",
                "icon": "mdi:gesture-double-tap"
            },
            "last_changed": "2021-04-01T11:41:06.783080+00:00",
            "last_updated": "2021-04-01T11:41:06.783080+00:00",
            "context": {
                "id": "309d5df96ff3cf4ad8300fd1c045c743",
                "parent_id": null,
                "user_id": null
            }
        },
        "new_state": {
            "entity_id": "sensor.front_bedroom_switch_hue_action",
            "state": "",
            "attributes": {
                "action": "down-press",
                "battery": 100,
                "brightness": 1,
                "counter": 3,
                "duration": 0,
                "linkquality": 76,
                "update": {
                    "state": "available"
                },
                "update_available": true,
                "friendly_name": "front_bedroom_switch_hue_action",
                "icon": "mdi:gesture-double-tap"
            },
            "last_changed": "2021-04-01T11:41:06.783080+00:00",
            "last_updated": "2021-04-01T11:41:11.801248+00:00",
            "context": {
                "id": "01bb5b23b6f5bc56dc0470c1be659513",
                "parent_id": null,
                "user_id": null
            }
        }
    },
    "origin": "LOCAL",
    "time_fired": "2021-04-01T11:41:11.801248+00:00",
    "context": {
        "id": "01bb5b23b6f5bc56dc0470c1be659513",
        "parent_id": null,
        "user_id": null
    }
}

Off button 2 press event:

{
    "event_type": "state_changed",
    "data": {
        "entity_id": "sensor.front_bedroom_switch_hue_action",
        "old_state": {
            "entity_id": "sensor.front_bedroom_switch_hue_action",
            "state": "",
            "attributes": {
                "action": "",
                "battery": 100,
                "brightness": 1,
                "counter": 1,
                "linkquality": 73,
                "update": {
                    "state": "available"
                },
                "update_available": true,
                "friendly_name": "front_bedroom_switch_hue_action",
                "icon": "mdi:gesture-double-tap"
            },
            "last_changed": "2021-04-01T11:42:40.913069+00:00",
            "last_updated": "2021-04-01T11:42:40.913069+00:00",
            "context": {
                "id": "47e6203d07a8f8810643faa1945e30ea",
                "parent_id": null,
                "user_id": null
            }
        },
        "new_state": {
            "entity_id": "sensor.front_bedroom_switch_hue_action",
            "state": "",
            "attributes": {
                "action": "off-press",
                "battery": 100,
                "brightness": 1,
                "counter": 2,
                "duration": 0,
                "linkquality": 76,
                "update": {
                    "state": "available"
                },
                "update_available": true,
                "friendly_name": "front_bedroom_switch_hue_action",
                "icon": "mdi:gesture-double-tap"
            },
            "last_changed": "2021-04-01T11:42:40.913069+00:00",
            "last_updated": "2021-04-01T11:42:44.421738+00:00",
            "context": {
                "id": "0c40ca775d2308efdbbc4abfee1e6325",
                "parent_id": null,
                "user_id": null
            }
        }
    },
    "origin": "LOCAL",
    "time_fired": "2021-04-01T11:42:44.421738+00:00",
    "context": {
        "id": "0c40ca775d2308efdbbc4abfee1e6325",
        "parent_id": null,
        "user_id": null
    }
}

@EPMatt
Copy link
Owner

EPMatt commented Apr 2, 2021

Hi @lwfitzgerald,

that's really nice to know. I'll take a look at this useful feature, which will significantly simplify the handling of double press events, at least for Zigbee2MQTT. I'll let you know as soon as it gets implemented.

Thank you for the great suggestion! :)

@EPMatt EPMatt self-assigned this Apr 2, 2021
@EPMatt EPMatt changed the title [SUGGESTION] Support zigbee2mqtt native button press counter for Phillips Hue dimmer switch Support zigbee2mqtt native button press counter for Phillips Hue dimmer switch Apr 15, 2021
@EPMatt EPMatt added the blueprint An issue related to a blueprint label Apr 15, 2021
@Mar1usW3
Copy link

Mar1usW3 commented Apr 3, 2024

any update here?

@janholbrouck
Copy link

Also interested in this. Would be handy functionality to have.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blueprint An issue related to a blueprint enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants