Blackymas / NSPanel_HA_Blueprint

This allows you to configure your complete NSPanel via Blueprint with UI and without changing anything in the code
1.38k stars 253 forks source link

Double Click Physical Buttons - New Feature #1301

Open rudgej opened 10 months ago

rudgej commented 10 months ago

The buttons currently support press and long press.

I uses these for scene section ( Off / Room Low/ Room Mid / Room Hi) across all panels and rarely use the actual display.

Could this be expended to allow for double click, and whilst you are at it triple click?

Double click for me would be blinds open / close and triple click would be air con on/off.

The displays are great but for most actions standard button presses across all panels is simpler for everyone in the house.

deejaybeam commented 10 months ago

https://github.com/Blackymas/NSPanel_HA_Blueprint/issues/259

rudgej commented 10 months ago

Ok thank you - so the answer is no but there is a work around if I can figure it out!

edwardtfn commented 10 months ago

As you can see in the discussion pointed by @deejaybeam, it's a bit hard to find the one solution which fits all on this, but you probably can achieve this as a customization to your system without big effort.

One example to send a command to toggle a blind with a double click on left button will be like this:

binary_sensor:
  - id: !extend left_button
    on_multi_click:
      #Double Click
      - timing:
          - ON for at most 0.5s
          - OFF for at most 0.3s
          - ON for at most 0.5s
          - OFF for at least 0.2s
        then:
          - script.execute:
              id: ha_call_service
              service: "cover.toggle"
              entity: "cover.the_cover_to_toggle"
              key: ""
              value: ""

I haven't tested, but please let me know if you have issues implementing this and I probably can help a bit.

edwardtfn commented 9 months ago

@rudgej, have you had a chance to try the customization I've proposed?

Should we close this?

rudgej commented 9 months ago

I am so sorry for my slow reply. I just did this and it worked - thank you.

I assume to customise for a light I could do

service: "cover.toggle"

service: "light.toggle"

service: "Light.off"

Etc

rudgej commented 9 months ago

I tried to add another one for the right button but I got a duplicate error

The code and reply is below

How do I allow a second action please?

INFO ESPHome 2023.11.6 INFO Reading configuration /config/esphome/topstairsfirst.yaml... ERROR Error while reading config: Invalid YAML syntax:

Duplicate key "binary_sensor" in "/config/esphome/topstairsfirst.yaml", line 48, column 1: binary_sensor: ^ NOTE: Previous declaration here: in "/config/esphome/topstairsfirst.yaml", line 31, column 1: binary_sensor: ^

binary_sensor:

binary_sensor:

edwardtfn commented 9 months ago

Do you wanna have two actions executed when you double click?

edwardtfn commented 9 months ago

Please try this:

binary_sensor:
  - id: !extend left_button
    on_multi_click:
      #Double Click
      - timing:
          - ON for at most 0.5s
          - OFF for at most 0.3s
          - ON for at most 0.5s
          - OFF for at least 0.2s
        then:
          - script.execute:
              id: ha_call_service
              service: "cover.toggle"
              entity: "cover.landing_dimout"
              key: ""
              value: ""
          - script.execute:
              id: ha_call_service
              service: "cover.toggle"
              entity: "cover.landing_blackout"
              key: ""
              value: ""
edwardtfn commented 9 months ago

I assume to customise for a light I could do service: "cover.toggle" service: "light.toggle" service: "Light.off" Etc

Yes! Is should work in most of those services.0, however, that is using an implementation of a service call used by this Blueprint (which will be executing it).

Maybe you should use the native service call:


binary_sensor:
  - id: !extend left_button
    on_multi_click:
      #Double Click
      - timing:
          - ON for at most 0.5s
          - OFF for at most 0.3s
          - ON for at most 0.5s
          - OFF for at least 0.2s
        then:
          - homeassistant.service:
              service: cover.toggle
              data:
                entity_id: cover.landing_dimout
          - homeassistant.service:
              service: cover.toggle
              data:
                entity_id: cover.landing_blackout

It's probably less resources dependant and easier to read the code. 😉

rudgej commented 9 months ago

Thank you - the aim was to have a function for the right hand button also - hence I assumed I could just duplicate it and change left to right. Clearly not!

edwardtfn commented 9 months ago

Try this:

binary_sensor:
  - id: !extend left_button
    on_multi_click:
      #Double Click
      - timing: &hw_btn_double_click
          - ON for at most 0.5s
          - OFF for at most 0.3s
          - ON for at most 0.5s
          - OFF for at least 0.2s
        then:
          - homeassistant.service:
              service: cover.toggle
              data:
                entity_id: cover.landing_blackout

  - id: !extend right_button
    on_multi_click:
      #Double Click
      - timing: *hw_btn_double_click
        then:
          - homeassistant.service:
              service: cover.toggle
              data:
                entity_id: cover.landing_dimout
rudgej commented 9 months ago

Thank you.

The double function works as intended but the unintended consequence is is is also recognising a single click at the sure

The left click on my system is Lights OFF - so I suspect when I last tested it they were indeed off so the issue was not highlighted.

To stop this then I assume a single click would need to be edited so that it was more than 0.5s in which case this script would win.

Is there are way of changing the single click time in the script please?

Thank you

edwardtfn commented 9 months ago

Is there are way of changing the single click time in the script please?

That is probably a bit harder, and will also come with consequences... As mentioned in #259, this will require the one click function to wait longer and make sure a second click didn't come, driving to a less responsive system.

edwardtfn commented 9 months ago

You can, however, don't assign anything to your button, then control the clicks in your own automatiin on Home Assistant. You have the button ststus as a sensor, so it's all you need. 😉 If you wanna keep the blue bar indicating status on Home Assistant, assign a helper to that, so you also control that helper from Home Assistant side.