From 1f261ee8d2d97d9314ff21514da99a6487f6755d Mon Sep 17 00:00:00 2001 From: Claus Dethlefsen Date: Tue, 17 Mar 2026 16:22:35 +0100 Subject: [PATCH] Refactor Home Assistant Hue switch automations to use `hue_event` for improved reliability MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Replace multiple device-based automations with a single event-driven automation * Eliminate duplicate `unique_id` conflicts * Switch from device actions to service calls (`cover.open_cover`, `cover.close_cover`, `light.turn_on/off`) * Add support for: * Short press (button 1) → open garage * Long press (button 1) → close garage * Short press (button 4) → turn off all lights * Long press (button 4) → turn on all lights * Set `mode: restart` to improve responsiveness under rapid input * Simplify structure for easier maintenance and debugging Result: more stable and predictable Hue switch behavior --- include/automations/bryggerbutton.yaml | 125 ++++++++++++------------- 1 file changed, 59 insertions(+), 66 deletions(-) diff --git a/include/automations/bryggerbutton.yaml b/include/automations/bryggerbutton.yaml index afe04b9..db99029 100644 --- a/include/automations/bryggerbutton.yaml +++ b/include/automations/bryggerbutton.yaml @@ -1,68 +1,61 @@ -- id: '1691939802290' - alias: Åbn garage ved tryk på 1 - description: '' +- id: hue_switch_garage_and_lights + alias: Hue switch - garage og lys + mode: restart + trigger: - - device_id: 5f6b41e54f3226acd9c9ab54a3acb527 - domain: hue - platform: device - type: initial_press - subtype: 1 - unique_id: 4b8a056e-973f-48cf-8a19-3586f6b05dcf - condition: [] + - platform: event + event_type: hue_event + event_data: + id: 5f6b41e54f3226acd9c9ab54a3acb527 + action: - - device_id: 3bc3eab99b46dae3e469bfa4060ce0f5 - domain: cover - entity_id: 4bd9c13b7bb0cc3245e38211ded2be92 - type: open - mode: single -- id: '1691941083623' - alias: Sluk alt lys ved tryk på 0 - description: '' - trigger: - - device_id: 5f6b41e54f3226acd9c9ab54a3acb527 - domain: hue - platform: device - type: initial_press - subtype: 4 - unique_id: f97d54a1-2283-4fb0-8709-b873a310732b - condition: [] - action: - - service: light.turn_off - data: {} - target: - entity_id: light.alle_lys - mode: single -- id: '1691941222856' - alias: Tænd alt lyset ved langt tryk på 0 - description: '' - trigger: - - device_id: 5f6b41e54f3226acd9c9ab54a3acb527 - domain: hue - platform: device - type: long_press - subtype: 4 - unique_id: f97d54a1-2283-4fb0-8709-b873a310732b - condition: [] - action: - - service: light.turn_on - data: {} - target: - entity_id: light.alle_lys - mode: single -- id: '1692023138692' - alias: Luk garage ved langt tryk på '1' - description: '' - trigger: - - device_id: 5f6b41e54f3226acd9c9ab54a3acb527 - domain: hue - platform: device - type: long_press - subtype: 1 - unique_id: 4b8a056e-973f-48cf-8a19-3586f6b05dcf - condition: [] - action: - - device_id: 3bc3eab99b46dae3e469bfa4060ce0f5 - domain: cover - entity_id: 4bd9c13b7bb0cc3245e38211ded2be92 - type: close - mode: single + - choose: + + # --- GARAGE --- + + # Kort tryk på knap 1 → Åbn garage + - conditions: + - condition: template + value_template: > + {{ trigger.event.data.type == 'initial_press' + and trigger.event.data.subtype == 1 }} + sequence: + - service: cover.open_cover + target: + entity_id: cover.anne + + # Langt tryk på knap 1 → Luk garage + - conditions: + - condition: template + value_template: > + {{ trigger.event.data.type == 'long_press' + and trigger.event.data.subtype == 1 }} + sequence: + - service: cover.close_cover + target: + entity_id: cover.anne + + + # --- LYS --- + + # Kort tryk på knap 4 → Sluk alt lys + - conditions: + - condition: template + value_template: > + {{ trigger.event.data.type == 'initial_press' + and trigger.event.data.subtype == 4 }} + sequence: + - service: light.turn_off + target: + entity_id: light.alle_lys + + # Langt tryk på knap 4 → Tænd alt lys + - conditions: + - condition: template + value_template: > + {{ trigger.event.data.type == 'long_press' + and trigger.event.data.subtype == 4 }} + sequence: + - service: light.turn_on + target: + entity_id: light.alle_lys