Xiaomi hold implementatioN

hI @rave,

I have you component running, and i am pretty happy with the xiaomi system i have at the moment.

I am currently playing with different click types, namely “Hold”. I remember the old MQTT script would have two events for a hold

  1. Long Press (Immediately when it detected it was a long press)
  2. Button Release (Immediately after the button was released)

Now i think this opens up a whole bunch of different uses (setting volume, moving roller blinds up/down, then stopping when the button is released). Is this going to be implemented? or is it already?

thanks,

PS thanks for putting this together!

It is already implemented. Check out the the docs for the component. Here is how I use it to control the lights https://github.com/Danielhiversen/home-assistant_config/blob/64ed49f1d9c1ee10c630de20af6586e7ff5400b3/automation/soverom.yaml#L318

where are the component docs?

and what custom_component are you using?

I have this one: https://github.com/lazcad/homeassistant

which doesnt mention the “long_click_press”

I am using the same component.
The docs is at the link you posted.

well - used your example (thanks) but i couldnt find that click event type in the docs.

You’re correct. The docs mention only “Available click types are ‘single’, ‘double’ and ‘hold’.”
But in the binary sensor code you can see:

   if value == 'long_click_press':
        self._is_down = True
        click_type = 'long_click_press'
    elif value == 'long_click_release':
        self._is_down = False
        click_type = 'hold'
    elif value == 'click':
        click_type = 'single'
    elif value == 'double_click':
        click_type = 'double'
1 Like

How would you use that?

After the press you always have a button release, unless you keep the button presses in your hands forever

I use it to control the lights. Press the button and hold, the light intensity increases until I release the button.

4 Likes

that’s a cool way.

Where is your code for that?

1 Like

entity_id: script.brightness_soverom
?

2 Likes

I have our evening 5-min warning, which is when lieing in bed reading or using our phones, one says “5 minutes”, which means lights out in 5. typically we both get distracted and another 10, 20 or 30 mins goes past, before saying “that was a long 5 minutes…”

so our bedroom lamp turns on/off with a button, now i have a script which turns off after 5 mins, but there was no feedback when it worked, and it used the “hold” event (which i dont think should have been renamed from long_click_release). there were a few times the long press didnt register, and 10 minutes later we were saying “that was a long 5 minutes…”

now i have it so that as soon as the long_click is registered, the lamp turns off for 1s, then back on, indicating that our 5 mins has started, and we can go to bed on time!

Thanks…!

Thanks for the examples, @Danielhiversen.
Also thanks for sharing your configs on GH - very useful examples. Thanks!