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

[FEATURE REQUEST] Add Support for Shelly Click (shelly.click) events or Device trigger using HA #441

Closed
ashp8i opened this issue Mar 12, 2022 · 15 comments
Assignees
Labels
enhancement New feature or request

Comments

@ashp8i
Copy link

ashp8i commented Mar 12, 2022

Feature Request

In the current state of the project, how easy or hard would it be to implement support for shelly.click events either via event or Device Triggers.

Describe the solution / feature you'd like

Just like the lutron caseta and state integrations would it be possible to listen into HA for either events in general or shelly device triggers, which can then be mapped to dim/bright/toggle/on/off/colour and media etc

Describe alternatives you've considered

I have tried HA blueprints and Automations but they are not as easy to manipulate and flexible in their implementation as this project has been in terms of it's distinct purpose

Additional context

Xavi, as always appreciate you effort and support, really amazing project

@ashp8i ashp8i added the enhancement New feature or request label Mar 12, 2022
@xaviml
Copy link
Owner

xaviml commented Apr 13, 2022

Hi @ashp8i,

Sorry for coming late on this. ControllerX is flexible and extendible when it comes to adding new devices and integrations. In addition, it is agnostic on how the other ControllerX features work. In fact, I have been working on adding a homematic integration on this ticket: #421

For a new integration (based on event), I will need to understand how it works, so could you please answer the following:

  • Can you share an example of event data?
  • Do you have any specific controller/device to fit with this integration? Could you share the different events that fire (click, holds, etc).

Depending on the use case, I might build a generic integration for events.

Regards,
Xavi M.

@ashp8i
Copy link
Author

ashp8i commented Apr 13, 2022

yes, I will try and supply some details, the devices we are targeting in my case would be Shelly 2.5 and Shelly i4 for further support of other devices e.g. shelly i3 or shelly1 others may need to provide details.

please see event data for a shelly i4 from home assistant: -

this:
entity_id: automation.new_automation
state: 'on'
attributes:
last_triggered: '2022-04-12T18:56:42.605794+00:00'
mode: parallel
current: 0
max: 10
id: '1647025690449'
friendly_name: Ashish Wall Button 1
initial_state: true
last_changed: '2022-04-12T18:24:05.119722+00:00'
last_updated: '2022-04-12T18:56:42.663710+00:00'
context:
id: 655f0416ff854839a0d7ae35d3bd92d5
parent_id: ec51a8d803274799fd32945eedd72301
user_id: null
trigger:
id: ashish-button-a-1-single-push
idx: '0'
platform: device
event:
event_type: shelly.click
data:
device_id: 6e9c4105160ef89fc6300d9fea855a1b
device: shellyplusi4-083af200e3e8
channel: 1
click_type: single_push
generation: 2
origin: LOCAL
time_fired: '2022-04-12T18:56:42.902074+00:00'
context:
id: 72487ddeffee227b2be4c36e36f47846
parent_id: null
user_id: null
description: event 'shelly.click'

thats the data recorded from a home assistant automation

for click_type, the possibilities are single_push, double_push, long_push, btn_down and btn_up
channel is the button number: e.g. 1, 2, 3 or 4

see data below from

https://www.home-assistant.io/integrations/shelly/

{
"event_type": "shelly.click",
"data": {
"device_id": "e09c64a22553484d804353ef97f6fcd6",
"device": "shellybutton1-A4C12A45174",
"channel": 1,
"click_type": "single",
"generation": 1
},
"origin": "LOCAL",
"time_fired": "2021-04-28T08:53:12.755729+00:00",
"context": {
"id": "e0f379706563aaa0c2c1fda5174b5a0e",
"parent_id": null,
"user_id": null
}
}

hope this helps in capturing the correct data

Kind Regards,
Ashish

@ashp8i
Copy link
Author

ashp8i commented Apr 13, 2022

when you press a button on a shelly i4 you trigger two events one is a btn_down the other is either single_push or long_push, once you let go of a button the btn_up it triggered, pressing a button twice in quick succession issues a double_push and a couple of btn_down btn_up's I treat btn_up as a release and btn_down as a hold if that helps

@xaviml
Copy link
Owner

xaviml commented Apr 13, 2022

Hi @ashp8i,

What I understand is:

  • single_push: Treat as click
  • long_push: Treat as hold
  • btn_up: Treat as release
  • double_push: Treat as double click

I will add a default mapping, but it seems that these controllers are custom controllers and do not have default behaviors.

Regards,
Xavi M.

@ashp8i
Copy link
Author

ashp8i commented Apr 13, 2022

correct, I think that implementation should avoid any trip ups but I will definately test for you, beware at the moment we are implementing gen2 events which I can easily test for you the gen1 I will have to try to reconfigure my shelly 2.5 to get the output to the shelly.click event in home assistant

@Dougiebabe
Copy link

I would also love love this implementation. I was looking for a way of using ControllerX with Shelly devices late last year but never got around to making an issue for it so thank you to @ashp8i for starting one.

As each i3 in my case has 3 switches and each switch has 3 click types it would take 9 automations for each i3 I use which seemed excessive, I would assume in ControllerX it would be one entry for each device.

I personally use Shellyforhass (available in HACS) which has a different event and I haven't noticed a btn_up event but other than that I think most of it is the same. Not sure if this would mean a different controller would be needed or if there would be a way for ControllerX to listen to events that we could configure?

Here is what I see when using 1 switch in the HA events

Event 2 fired 22:22:
{
"event_type": "shellyforhass.click",
"data": {
"entity_id": "binary_sensor.shelly_shix3_1_e8db84d6c4ab_1_switch",
"click_type": "long"
},
"origin": "LOCAL",
"time_fired": "2022-04-24T21:22:19.509582+00:00",
"context": {
"id": "f3e35bd58235e895505a79888ca9a9b1",
"parent_id": null,
"user_id": null
}
}
Event 1 fired 22:22:
{
"event_type": "shellyforhass.click",
"data": {
"entity_id": "binary_sensor.shelly_shix3_1_e8db84d6c4ab_1_switch",
"click_type": "double"
},
"origin": "LOCAL",
"time_fired": "2022-04-24T21:22:15.769527+00:00",
"context": {
"id": "2a5efcc287581095c872b34280654b63",
"parent_id": null,
"user_id": null
}
}
Event 0 fired 22:22:
{
"event_type": "shellyforhass.click",
"data": {
"entity_id": "binary_sensor.shelly_shix3_1_e8db84d6c4ab_1_switch",
"click_type": "single"
},
"origin": "LOCAL",
"time_fired": "2022-04-24T21:22:07.434677+00:00",
"context": {
"id": "78709d199af1ba8cc7105070cec3e86b",
"parent_id": null,
"user_id": null
}
}

Let me know if you would prefer a different issue for the ShellyForHass integration or if you have to create a new controller and would prefer to not have to do that then I understand and would look to move back to the in-built integration.

Thanks again for your efforts with this project as well, it's great and I mention it to every I know who uses HA.

@xaviml
Copy link
Owner

xaviml commented Apr 25, 2022

Hi @Dougiebabe,

Thank you for your thoughts on this. I was, in fact, working on this integration and I was wondering about adding shellyforhass as well. However, the shellyforhass.click does not show which button was pressed (channel), does it?

Also, which shelly device do you have? There are 2 things to add here: an integration, and a device (or more than one).

Since event payload is different, I will go for a different integration. Although they will be very similar, and I will add them under this same ticket.

Regards,
Xavi M.

@Dougiebabe
Copy link

Hi @xaviml

I have a few shelly devices but not all of them are linked up to switches. I could provide events for the ones that are though.

The event above was for an i3 and was channel 1, shellyforhass doesn't list the channel number in the event data but it is contained in the entity_id

Event 28 fired 22:54:
{
"event_type": "shellyforhass.click",
"data": {
"entity_id": "binary_sensor.shelly_shix3_1_e8db84d6c4ab_2_switch",
"click_type": "single"
},
"origin": "LOCAL",
"time_fired": "2022-04-25T21:54:33.434369+00:00",
"context": {
"id": "94aacf1400d34f0cf71413a470f92abd",
"parent_id": null,
"user_id": null
}
}

^^^ This is for the same i3 device but channel 2.

Event 31 fired 22:58:
{
"event_type": "shellyforhass.click",
"data": {
"entity_id": "binary_sensor.shelly_shdm_2_40f52001529a_1_switch",
"click_type": "long"
},
"origin": "LOCAL",
"time_fired": "2022-04-25T21:58:52.256517+00:00",
"context": {
"id": "6bb76e0addcb1a2ca68ca3abe65671c1",
"parent_id": null,
"user_id": null
}
}
Event 30 fired 22:58:
{
"event_type": "shellyforhass.click",
"data": {
"entity_id": "binary_sensor.shelly_shdm_2_40f52001529a_2_switch",
"click_type": "long"
},
"origin": "LOCAL",
"time_fired": "2022-04-25T21:58:46.815885+00:00",
"context": {
"id": "4d949187c3d071b81cb5b4acc251bafa",
"parent_id": null,
"user_id": null
}
}

^^^ This is for a shelly dimmer 2, both channels long presses.

Event 33 fired 23:03:
{
"event_type": "shellyforhass.click",
"data": {
"entity_id": "binary_sensor.shelly_shdm_1_db3740_1_switch",
"click_type": "long"
},
"origin": "LOCAL",
"time_fired": "2022-04-25T22:03:47.390906+00:00",
"context": {
"id": "bb2efe8470ecd6cdb589038732ffa707",
"parent_id": null,
"user_id": null
}
}
Event 32 fired 23:03:
{
"event_type": "shellyforhass.click",
"data": {
"entity_id": "binary_sensor.shelly_shdm_1_db3740_2_switch",
"click_type": "long"
},
"origin": "LOCAL",
"time_fired": "2022-04-25T22:03:43.871691+00:00",
"context": {
"id": "a3fe0be19c505a87a919e05020ce8764",
"parent_id": null,
"user_id": null
}
}

^^^ This is for a shelly dimmer 1, both channels.

I have some Shelly 2.5s but they aren't currently hooked up as I haven't got the blinds for them, once I do I could provide the event details for them.

I have a Shelly1pm hooked up but I don't see an event for it, that is set to toggle switch and not momentary which might be the issue there.

What I have noticed is that the events seem to happen after the button press is released which could be why I'm not sering a button_up event.

Let me know if you need any more information or if I can help in any way.

@xaviml
Copy link
Owner

xaviml commented Apr 26, 2022

Hi @Dougiebabe ,

shellyforhass doesn't list the channel number in the event data but it is contained in the entity_id

As you said, I see the 2 entity_ids in the logs you provided. So you each channel has its own entity_id right? If this is the case, each channel will have its own configuration, instead of mixing them both.

What I have noticed is that the events seem to happen after the button press is released which could be why I'm not sering a button_up event.

For all of them? This will make things complicated for hold-release actions then.

I also have some shelly devices at my parent's with shellyforhass, so I will be checking the events (I've never used them).

Regards,

@xaviml
Copy link
Owner

xaviml commented May 13, 2022

Hi @ashp8i and @Dougiebabe ,

Sorry for the delay, I added the 2 integrations (shelly, shellyforhass) and 3 devices (shelly i3 (shellyforhass), shelly 2.5 (shelly) and shelly plus i4 (shelly)). PR is still open: #469

Integration documentation can be found here, and devices here:

Please, let me know if you have any suggestions. You can try this by downloading from the PR branch, otherwise, I will be releasing a beta release soon so you guys can try it out.

Regards,
Xavi M.

xaviml added a commit that referenced this issue May 13, 2022
@Dougiebabe
Copy link

Hi @xaviml

Sorry, we had a new addition to the family join us a couple of weeks ago so have been a bit pre occupied!

Thanks for your time on this.

I might try and spin up another Home Assistant instance when I get time and try out the in built shelly application to see if the btn_up event appears with the i3 or if it is just a limitation of the device itself. I'll also try and get test the integration above once it's released as a beta.

I wrote the below last week but never got round to hitting send so will include this now.

Cheers,

Doug

As far as I can tell the shelly devices send the 'single' event when the button is released. The dimmers seem to send a 'long' event before the button is released but the i3 devices only send it once released. I've seen no events for 'btn_up' or anything similar with any of the devices I have tried.

The event only firing on release with the i3 devices is a bit annoying but looks to be a limitation with the device, this will make it hard to use with dimming applications. I also understand without the btn_up event it will be hard to use for dimming outside of the light attached to the shelly as ControllerX will never know when the button has been released and stop dimming up/down.

Would I see the event anywhere else? I've just been looking in the Home Assistant developer tools - events tab.

@xaviml
Copy link
Owner

xaviml commented May 18, 2022

Hi @Dougiebabe ,

Thank you for coming back to me. Unfortunately, there is no much I can do for debugging the device since I do not have it. As far as I know the Developer Tools should show all the events (if it does not show up in there, it will not be picked up by ControllerX anyway). If there is no "release" action, it will be hard to use a "hold" action, so for now we will leave just click actions, but once you have it, you can play around with the mapping attribute and predefined actions.

Thanks,
Xavi M.

@xaviml
Copy link
Owner

xaviml commented May 18, 2022

I just released ControllerX v4.20.0b1 which contains the shelly devices. The beta documentation can be checked up here: https://controllerx.netlify.app/

Cheers,

@ashp8i
Copy link
Author

ashp8i commented May 18, 2022

I just released ControllerX v4.20.0b1 which contains the shelly devices. The beta documentation can be checked up here: https://controllerx.netlify.app/

Cheers,

Hi Xavi,

Thanks for extending support in ControllerX for shelly devices

I've downloaded the beta version and will test and reply with feedback if there are any issues found.

Kind Regards,
Ash

@xaviml
Copy link
Owner

xaviml commented May 29, 2022

Shelly integrations and devices have been added to ControllerX v4.20.0.

Cheers,

@xaviml xaviml closed this as completed May 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants