[solved] HA switch that sends a brief "1" just on tap/hold and goes back to "0"?

Hi all

Searched the docs & forum but couldn’t find an answer.
I need a switch in HA which by tapping just sends a short pulse to a KNX actuator, so not hold the state.
Is this possible?

Thanks a lot in advance!
Nick

This snippet is from the automation trigger docs (requires using time:):

automation:
  trigger:
    platform: template
    value_template: "{{ (states.sensor.time.last_changed - states.YOUR.ENTITY.last_changed).total_seconds() > 300 }}"

You could modify this automation to fire Xsec after your HA switch goes ‘on’… the automation could then turn the switch ‘off’. The output could then be simply follow the switch (using a simple “if switch on/then relay on” type automation).

Not sure if this would work for “sub seconds” (might require float seconds, which I doubt time: can do).

You could use a template switch in combination with the Knx.send service if you only need a “1” Telegram on press and no “0” following.

Hi guys, I explained it bad… (guess used the wrong words)
On press I need a “1” and on release a “0”, so just a ?pulse?.

Have added some info to be more clear.
Anybody?

I believe you can do it the same way as you would with a cover template for momentary actuation? I have to do this for my motorized curtains, as I have an ESPHome nodemcu wired into the wired remote port on the motor. It expects a simple button press and release, however by default, the cover open command stays depressed. So I used a template… here’s how I did it. I’ll try to put it into your use case

Nevermind, I did all that through ESPHome. If you’re using a nodemcu or any esp8266/esp32 based chip for what you’re doing, I highly recommend it. The control it gives is phenomenal, and it’s just yaml script. I did make a concept idea for you that might help with what you’re doing. I can try to help more if you think this is going in the right direction. unfortunately, i’m still new to HA and all this, so I’m learning as I go.

So what I did was create 2 helpers via the configuration control panel. both are boolean toggles. one named trigger, one named action. then i created an automation. the automation will toggle “action” switch anytime the state of “trigger” changes from OFF to ON. but no change occurs when it changes back to OFF from ON. You could use any entity or device here in place of action, if you’re wanting to actually turn a light on, for example. You can also stack multiple actions, which can include a delay as one of those actions. So, for example, you could, when the state of “trigger” changes from OFF to ON, trigger a sequence of actions that set an entity’s state to 1, for example, delay 1 second, then change the state back to 0. It’s not the cleanest way probably, but it’s the only way i know of directly through HA. In ESPHome, you can define actions that trigger based on a more detailed state change, such as defining a switch and then defining on_press: and a sequence, like I do for my curtains. When the pin on my nodemcu (that’s defined for opening the curtain) goes HIGH (on a normally open circuit, which the default state would be LOW), the switch i defined that pin as will trigger the on_press: action sequence which sends an output signal on another pin, bringing that pin HIGH, delay’s 100ms, then sets that pin back to LOW. I guess that is essentially what HA automation is doing too, just that the device or entity’s state that you’re changing, has to be defined already, entirely separate from the automation. Whereas in ESPHome, the automation is defined as part of the switch itself.

Maybe this all will help you find some direction. Sorry if i confused you or wasn’t much help.

1 Like

what about a simple state automation? This would do 1 second:

automation:
  trigger:
    platform: state
    entity_id: switch.YOUR_SWITCH
    to: "on"
    # If given, will trigger when state has been the to state for X time.
    for: "00:00:01"
  action:
    - service: switch.turn_off
      entity_id: switch.YOUR_SWITCH
1 Like

With HA 0.113 you can even use millisecond precision on these times, I think.

Hi guys, thanks for your help!

I did search/read quite a lot and because I was almost convinced that such a control should exist since I thought that it’s used in automations.
Apparently not…

@kalethis: thanks for taking the effort on your detailed write-up!
I don’t use anything esp* (yet).

@farmio: I came up with something similar and also tried your suggestion but it doesn’t function.
This is what I did:

- id: '1595204725982'
  alias: test
  description: ''
  trigger: []
  condition: []
  action:
  - data: {}
    entity_id: switch.kitchen_light
    service: switch.turn_on
  - delay: 00:00:01
  - data: {}
    entity_id: switch.kitchen_light
    service: switch.turn_off
  mode: single
1 Like