Philips Hue, Friends of Hue switch 4 buttons for Hue Integration

Same answer as in post 53, however you need a conbee blueprint.

Oh great! even better, I connected the FoH directly to the Hue bridge and it worked immediately using the blueprint in #32.

I cannot understand the “repeat” when is it trigger, is that for the multiple press? cause I cannot make it work…

If you hold a button for more than 1 second, then “repeat” trigger app every ½ second. It will be followed by a “long press” when you release the button again. This might make it hard to see the “repeat” on the screen. Use “trace” on the automation, and it will show the “repeat” actions just before the “long release”

I do not use “repeat”, however in post #46 and post #50 a small discussion on how to use this for dimming.

1 Like

Regarding the double (multiple tap) logically should be:

if initial_press is followed by short_release and another short_release within 1 second from the same button than is a double tap

and change the short_release in a was so that:

if initial_press is followed by short_release and the time of 1 second expires than is a single tap

Would this be correct? Is this something that can be implemented directly in the blueprint or should should further development?

Your idea is right, however I’m not sure how to implement it easily in the blueprint. Might need a helper or alike.

I might look into this later, however not before November/december. Will message you for help with some testing, if needed.

I tried to implement myself, could not figure it out how to integrate into the blue print but this is what done:
I created a helper counter to count how many times the button B3 is press: foh_b3_double_tap_counter and I wrote the script below which should be called every time there is a short_release.
When the script executes, increments the counter, if counter is 1, it waits 5 seconds and turns off the light. If the counter is 2 it turns on the light. The idea is that if there is a second press within 5 sec, the script will be killed mode: restart a new instance starts increases the counter to 2 etc.

I call the script on short_release from button 3 in my example:

    button_3_short_release:
      - service: script.turn_on
        target:
          entity_id: script.foh_b3_single_double_tap
        data: {}

Script to detect single/double tap of button 3

alias: FoH B3 Single/Double Tap
sequence:
  - service: counter.increment
    data: {}
    target:
      entity_id: counter.foh_b3_double_tap_counter
  - if:
      - condition: state
        entity_id: counter.foh_b3_double_tap_counter
        state: "1"
    then:
      - delay:
          hours: 0
          minutes: 0
          seconds: 5
          milliseconds: 0
      - type: turn_off
        device_id: 71aa43dc88b7d750f08d35cb70b3a496
        entity_id: 82f9bc14d2fcbcc625802ba129f70ec8
        domain: light
      - service: counter.reset
        data: {}
        target:
          entity_id: counter.foh_b3_double_tap_counter
    else:
      - if:
          - condition: state
            entity_id: counter.foh_b3_double_tap_counter
            state: "2"
        then:
          - type: turn_on
            device_id: 71aa43dc88b7d750f08d35cb70b3a496
            entity_id: 82f9bc14d2fcbcc625802ba129f70ec8
            domain: light
            brightness_pct: 100
      - service: counter.reset
        data: {}
        target:
          entity_id: counter.foh_b3_double_tap_counter
mode: restart
icon: mdi:light-switch-off

Im not home, so this from my iPad, hence no nice cut/paste and no testing.

Your idea is good and should work. That it is not working, I believe it is due to the script being initiated from the automation. The automation is in “queue” mode, hence will initiate new scripts. Not sure this works as intended with “restart”.

What you have build should work if you do it directly in the automation (using the blueprint). Only one small change to the blueprint, you should change the “mode” from queue to “restart”, app 1/2 down in the blueprint, just change the text and remove the queue length line, right below. Remember to reload automations, or restart HA to load the change in the blueprint.

Actually it works very well with the last edit I did in my post #58

I wanted to create a separate blueprint as complement for the one you wrote, to make the script faster to implement, but was able to do only the first part with user input the action part cannot understand how to make it work … below my try. If I will succeed will edit this post and correct it.

blueprint:
  name: Single/Double Tap
  description: Perform actions based on single or double tap (based on counter
  domain: script
  input:
    counter_entity:
      name: Counter Entity
      description: The entity_id of the counter.
      selector:
        entity:
          domain: counter
    single_tap_delay:
      name: Single Tap Delay (milliseconds)
      description: Delay in milliseconds after a single tap.
      default: 400
      selector:
        number:
          min: 0
          max: 1000
          unit_of_measurement: milliseconds
    single_tap_action:
      name: Single Tap Action
      description: Action to perform on a single tap.
      selector:
        action:
    double_tap_action:
      name: Double Tap Action
      description: Action to perform on a double tap.
      selector:
        action:

mode: restart
max_exceeded: silent

---NOT WORKING---
script:
  alias: Single/Double Tap
  sequence:
    - service: counter.increment
      target:
        entity_id: !input counter_entity
    - if:
        - condition: state
          entity_id: !input counter_entity
          state: "1"
      then:
        - delay:
            milliseconds: !input single_tap_delay
        - sequence: !input single_tap_action
        - service: counter.reset
          target:
            entity_id: !input counter_entity
      else:
        - if:
            - condition: state
              entity_id: !input counter_entity
              state: "2"
          then:
        - sequence: !input double_tap_action
        - service: counter.reset
          target:
            entity_id: !input counter_entity

Hi,

I read some people suggested the Switch 1+3 and 2+4 simultaneously pressing function. What I can’t find out.
Is it working now? At the moment I’m using this feature with the hueessentials Android app, but I would like to Switch the logic into homeassistant

Unfortunately the 1+3 button is not relayed by the hue integration into HA, so there is never an event. Hence, it will not be possible.

thanks for your reply.

Do you plan to add your blue print as blue print addable via git?

Hi Stephan, Not sure how to do this and I do not use github for anything else.

You are very welcome to create it, making it easier for everybody else. I will not object at all.

I will continue to update the blueprint if changes are needed due to HA changes, and post new versions in this thread.

Maybe another developer can help you?
I think this have to be done by the creator of the blueprint.
It’s this with the Add to Homeassistant button here in the blueprint section.
Sadly I have no experience in creating such things

Hi
I created a Blueprint link, it’s a direct copy of post #32, let me know if you want credits or licenses added
Friends Of Hue switch, 4 button, all functions Blueprint

Perfekt, making it easier for everybody else.

Hi,
I developed an enhancement based on the blueprint post#32 with the goal to provide support for multiple (currently 4) button taps in a sequence with dedicated actions for short release and long release.

See the blueprint on GitHub Gist:
Home Assistant - Blueprint: Hue, Friends Of Hue switch, 4 button, supports up to 4 taps in a sequence with dedicated actions to short and long release

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

All assigned actions will be performed for each tap in a sequence except for “initial press” which will be performed at the first tap in a sequence only. This follows the original Philips Hue FoH execution logic.

Thus you can setup for each button and separately for “short release” and “long release” up to 4 actions assigned to respective “taps” in a button press / release sequence. Although the blueprint can easily be extend to more than 4 taps this is not recommended as the usability deteriorates and the probability for sync errors increases.

Unfortunately the Hue API event sequence is quite complex which requires for this blueprint 3 counter helpers to be created. For the specification see the comments in the blueprint code header.

Testing showed that synchronization for the parallel running instances, which are triggered by each event a button press and release causes, is sensitive to the required delay before executing the actions. The default value of 1,500 ms should work for most situations, but depending on your hardware, software or button press frequency it may need to be adjusted on the UI config page or right away in the automation code.

Please note - that the actions are performed exactly in order as they happen on the FoH switch. Therefore a sequence of:
( Tap 1) initial press - short release / (Tap 2) initial press - repeat - repeat (- short release) - long release / (Tap 3) initial press - short release

will perform the following:
(Tap 1) initial press action and subsequently short release action tor Tap 1
(Tap 2) repeat action, repeat action and long release action for Tap 2
(Tap 3) short release action for Tap 3

Takeaways:

  • the initial action is performed for Tap 1 only
  • short release actions are performed for Tap 1 and Tap 3
  • long release action is performed for Tap 2 only
  • for a long button hold and release the Hue API may generate (not always !) an additional short release event which is omitted and the long release action is carried out only

Home Assistant can respond to FoH switch (button press/release) events in addition to the Hue Bridge itself. Thus there may be running automations on HA and Hue bridge in parallel. This may be helpful to fill functionality gaps of the Hue bridge, e. g. it can be used to carry out actions regarded to several Hue bridges as turn off all lights in the house on various Hue bridges and switch off AV and TV etc.
Unfortunately the Hue bridge timing to distinguish between short and long release is different (shorter) than for the Hue API. Thus there are button press - release timings which are seen by the Hue bridge already as a “long release” whereas the Hue API shows a “short release” only. Therefore it is not possible to synchronize short and long releases of the Hue bridge and in HA correctly.

For code reviews please note

  • there are rare cases in which for a de facto long pressed button just a single repeat and following short release event is shown without corresponding long release event - this is handled appropriate as well
  • for very long pressed buttons (e. g. with more than 15 repeats) the Hue API does not show a short release event anymore but just the final long release event. All this situations are managed by the blueprint.

Regarding code of post #32 let me know if you want credits or licenses added

1 Like

Hi, have changed the text in post one. Do you know how to make a “import blueprint” blue button. If you know, I will include one in the initial post, pointing to your github, making it much easier for others.

I have created an automation that uses this blueprint. However, when I press a button on the switch nothing happens. I see in the log file that the button is pressed. what am I doing wrong?

The intention is

Press button 3 once, lamp on
Press button 4 once, lamp off

Keep button 3 pressed to make the lamp brighter
Press and hold button 4 to dim the lamp

the lamp is an idea lamp called “storage tmp”

alias: Schakelaar berging buitendeur
description: ""
use_blueprint:
  path: Anybody4u/foh_mutiple_tap_v2.yaml
  input:
    hue-switch-button1:
      - event.friends_of_hue_switch_1_button_1
    hue-switch-button2:
      - event.friends_of_hue_switch_1_button_2
    hue-switch-button3:
      - event.friends_of_hue_switch_1_button_3
    hue-switch-button4:
      - event.friends_of_hue_switch_1_button_4
    button_press_B1: []
    button_press_B2: []
    button_press_B3:
      - service: light.turn_on
        metadata: {}
        data:
          brightness_pct: 100
        target:
          device_id: a32403ed3f14e0d129bbc8e63b973476
          entity_id: light.lightbulb
    button_press_B4:
      - service: light.turn_off
        target:
          entity_id: light.lightbulb
        data: {}
    button_short_release_B1-3: []
    button_long_release_B1-3: []

Which version of the blueprint are you using.

Be aware that the press is initial press, hence will trigger even if you hold the button pressed.

The lastone whit the blue button from post 68

alias: Hue, Friends Of Hue switch, 4 button, multi tap v2

blueprint:
  name: Hue, Friends Of Hue switch, 4 button, multi tap v2
  description: >
    HA version 2023.08 or newer.
    Works with all Hue API functions and 
    supports up to 4 taps in a sequence with dedicated actions to short and long release
    Correct the problem of "short release" triggered on the same time as "long release"
    If multiple switches needing the same functionality, select multiple switches per button.
#===============================================================================
#=====  This blueprint requires the following 3 helper-counters
#=====    name:          foh_run_counter
#=====                   foh_initial_press_counter
#=====                   foh_long_release_counter
#=====  all with the following configuration
#=====    minimum vlaue: 0
#=====    initial value: 0
#=====    step size    : 1 
#=====    Restore the last known value when Home Assistant starts: OFF
#=====  
#=====  To create helpers go to: Settings -> Devices&Services -> Tab: Helpers
#=====  Press button [Create Helper] -> choose "Counter" -> Set config -> Save
#===============================================================================
#=====  Based on
#=====  https://community.home-assistant.io/t/philips-hue-friends-of-hue-switch-4-buttons-for-hue-integration/499450/32
#===============================================================================

i get this error in the logfile:

Logger: homeassistant.components.automation.schakelaar_berging_kantoordeur
Bron: components/automation/__init__.py:687
integratie: Automatisering (documentation, issues)
First occurred: 00:37:55 (2 gebeurtenissen)
Laatst gelogd: 00:37:56

Error while executing automation automation.schakelaar_berging_kantoordeur: ValueError: Template error: int got invalid input 'unknown' when rendering template '{{ int(states('counter.foh_run_counter'))|d(1) }}' but no default was specified