Shelly 2PM with Philips Hue Lights (or other smart bulb)

Hi,

I’m trying to configure a Shelly 2PM to work with a Hue bulb (This is to allow some rooms house to have hue bulbs for colour etc, while maintaining the same wall switches as my current shellys used which are mainly dimmer 2’s).

My current setup is using a 3 way momentary switch.

The functionality I want is:

  1. Press up → Turn Light(s) on (turning on the relay if needed)
  2. Press Down → Turn Light(s) off
  3. Long Press Up → Increase brightness (and turn on if needed)
  4. Long Press → Decrease brightness.

I’m using pyscript to do this, and I’ve managed to achieve the first two objectives, but struggling to work out a good way to achieve the last two.

I found this topic which I thought would provide a solution, however the problem I’ve run into is given this setup I can’t check the state of the button (there is no binary sensor exposed for the input channel states), from this issue `Home Assistant doesn’t allow creating binary sensors for momentary input events.

Is there any good way to work around this issue? The only other way I can see to tackle this is to change the inputs to switches, and then calculate is it’s a long press / short press based on the binary sensor state change which is achievable, just a pain to have to reimplement and maintain functionality that’s already available in the Shelly integration, also things like double press will require some thought.

I have a Shelly 1PM and as far as I am aware, you have change the behaviour within the shelly device from switch to button. Can’t see from your first post if this was done already.

From the API documentation then the button long press is exposed as well. they are simply not implemented in the HA integration by design.

Just thinking out loud. Maybe a webhook request from the device itself to a HA to increase and decrease the % of the light (or group).
Agreeing that requires some maintaining, but if you build something specific, it can break easily.
The HA Webhooks and the Shelly devices are prerty continious.

I actually found a way around this by using the events and @task_unique, such that I would continue changing the brightness until the task was killed by the btn_up event.

Hi @kingamajick,

Thank you for sharing your thoughts. This is exactly what I want to do as well.

Is there a way you could share your final script with „@task_unique“?

Have you considered adapting a shelly script (like this one: https://github.com/shelly-tools/shelly-script-examples/blob/main/hue_button_multipush.js) directly to your purpose?