Short and long press

Hi,

I have an automation called Light toggle (Dad office) that is listening to:
When: switch goes from off to on
Then: call service light toggle

I would like to use the same switch to have the press of the button for less than 1 second wil toggle the light and between 1 second and 2 seconds will change the light to low intensity.

How can I achieve this?

Thanks a lot,

John.

use
tap_action
action: toggle
hold_action:
action: cal.service

1 Like

What kind of button do you have? Not all buttons support long press tracking.

It is a switch that can stay pressed and if I keep it pressed, I see in home assistant that it stays on and goes to off when I release the switch.

1 Like

Ok, what @boheme61 posted is correct. You are looking for the the hold_action event.

But I am not talking about holding the button in the interface but more holding the physical button so I need an automation for that…

Right. In your automation, you just need to trigger on the hold_action event. However, it will vary depending on what kind of physical switch you have and how you have it connected to HA (ZHA, Zigbee, Tuya, etc.

What kind of physical switch is it? How is it connected to HA? Have you looked at the events to see what actions the switch supports?

Hi,

I have a physical switch (not in lovelace) on my wall that is from IHC but is fully recognised by home assistant.

As I said, I want to control a short and long press of this switch in the wall to toggle 2 different lights from the same switch in the wall.

I insist on the fact in the wall because I tried to look how to do it and the hold_action seems from the documentation to be used in the lovelace button.

But what I want to do is do it for my switch in the wall, not in lovelace. I have at the moment the following code:

alias: Light Press (Bureau Papa) Plafond
description: “”
trigger:

  • platform: state
    entity_id:
    • switch.1er_chambre_g
      from: “off”
      to: “on”
      condition:
      action:
  • service: light.toggle
    data: {}
    target:
    entity_id: light.hue_surimu_panel_1
    mode: single

Right. I get that. But it depends on if the wall switch supports long presses. If it does, depending on how you have it connected to HA, you should be able to see if it supports a hold action. Not all wall switches do. Do you know what model it is?

Where can I see if it supports that?

My switches are imported in Home Assistant from IHC

Honestly, I’m not sure. I’ve never heard of this brand. But, it looks like the switches are simply Boolean on and off. There’s no hold actions that I can see. :pensive:

Ok, thank you, I will try to find it another way :wink:

Anyway, thanks a lot for your patience, really nice to get help at that speed :smiley:

1 Like

Happy to help! Hopefully you can find a way to make it work.

What you can do, is go to /Developer-Tools#States find the switch, and check the current State
Then press 1 second, see if it change state, and to what !, And same if you hold the switch/button pressed
Some buttons is either mend for i.e trigger/toggle( Direct or through a relay ), or as i.e a “start-motor” button " hold it in untill engine runs, release it" … This is basically “same signal”
When you click it fast power runs through it, until you release, if you hold it longer power runs through it untill you release
So if it works like this, it should go from off to on, when you press it, then go back to off, when you release it. Hold it for 5 seconds and see if it’s the same “pattern”
Then you can use this in a Condition. I.e If on for 3 seconds, do something else

Perhaps what your looking for is a blueprint to use in an automation. I used this blueprint. If I pressed for less than 1 second on a physical switch which was seen in HA it turned a light on and if I held it for more than 2 seconds it turned the TV on.
Short, long or double click