Without input pullup there was a steady stream of reaction coming, so I had to use that. But I haven’t seen antyhing about that being a problem for on_click. So can somebody please tell me why I get “1kort” with payload “kort” (short in Norwegian) both when I click between 50 and 750 ms and when I click 2000 to 4000 ms?
Thanks! That removed the short press being interpreted as a long press, but the long press still doesn’t come through. I tried doubling both to 20ms too, but still no go. Is there anything else I can try in addtion to that? I’m getting both the on and the off on MQTT when I let go of the switch after around trhee seconds, so it does interpret the press, and I don’t get any extra presses or releases in the built-in binary_sensor/1/state MQTT message.
It’s the switches… Short circuiting the cables gives me the expected results. Annoying as heck, because I ordered those switches since the application is an open fishing boat, and I have to use something that’s completely waterproof. Are there any tricks I can use as a workaround? I tried with a 50 ms delayed on and off, but it still more often than not say “short” on long presses, even if the on and off through the built-in MQTT message doesn’t come until the long press is released.
Unfortunately I can’t see the Ali express link (I’m on a ship sharing an internet connection with 140 other people, also it might be blocked). Can you post a cropped and minimised screenshot of the switch type?
It’s this one. Another thing: Is it possible to make it send the “ON” and “OFF” from the built-in MQTT status sending while the button is pressed, not both ON and OFF after I release? That way I could do the calculation in Node-RED or Hass.
I have a sneaking suspicion that they do not operate like normal push buttons that simply short contacts together while pushed. I think the mechanical force of pressing the switch will generate a short voltage pulse and when the switch is released another short voltage pulse of the opposite polarity will be sent (piezoelectric effect).
Damn, they take a month or two to arrive… Here are the specs, if they tell you anything:
Product Specification
Mounting Hole: 16MM 19MM 22MM 25MM
Material: Aluminum anodized or stainless steel
Working Temperature: -40-70℃
Storage Temperature: -40-70℃
Working humidity: 10%-99%
Input Voltage: 3-24V/DC
Input Current: ≤2A
Contact Resistance: <5mΩ
Pulse Time: <50MS
Working Pressure: 3-8N
Protection Garde: IP68 IEC529
The Type Of Connection: 0.22 quare wire
This piezoe switches is heavy duty, non-spark, non-magnetic, corrosion resistant, lighting resistant, damage resistant and designed for indoor and outdoor use in inclement weather.
USES solid-state piezoelectric switch technology and has a dry contact NO pulse sensor that reacts when touched by the finger. No physically moving parts.
It has a very long life, can be used more than 200,000 times
The piezo button switches has been tested and the waterproof rating is IP68.
Can be used in severe weather conditions from -40°C to 70°C (-40°F to 158°F).
Pretend you’re talking to an electronic idiot…OK, you are talking to an electronic idiot! Does that mean that I can’t get it to do long presses reliably no matter what I do? As I say, they work sometimes, maybe 50 % of the time.
Correct. It is the wrong sort of switch. The only thing that will change the output pulse length is how hard you press it. The harder and faster you press the piezo crystal behind the switch the more voltage it generates, keeping the FET switch on longer (always less than 50ms for this switch though). Have a read of this:
Thanks, but that seems illogical to me. Because when I set it to have a short press from 50 to 500 and long press from 501-1500 ms, it does obey and shows “long” around 50 % of the time. If it was always doing less then 50ms, that would never work. Or is there something else going on that I don’t understand either? That would be no surprise, of course…
Hard to say without an oscilloscope to observe the switch output. The fact that it works reliably when you short the wires together is the biggest giveaway.
OK, thanks. So there is no signal what so ever coming when I press, only when I release? Which is why I can’t get it to send the “ON” when I press and then the “OFF” when I release. Maybe I can work on multiple presses of the short one, so one press is this, two presses is that and three presses is a third thing. I’ll try something like this when I get the time:
on_multi_click:
- timing:
- ON for at most 1s
- OFF for at least 3s
then:
- logger.log: "1 click"
- timing:
- ON for at most 1s
- OFF for at most 1s
- ON for at most 1s
- OFF for at least 3s
then:
- logger.log: "2 clicks"
- timing:
- ON for at most 1s
- OFF for at most 1s
- ON for at most 1s
- OFF for at least 0.2s
- ON for at most 1s
- OFF for at least 3s
then:
- logger.log: "3 clicks"
Great, thanks! I can probably live with that just as well as I could with different lengths. It may even be better, especially since it’s a bit difficult to hold the finger steady in a 24 aluminum crawfish boat in a bit of waves…
Yep, that’s reliable. Thanks again, @tom_l! As long as I hit the button with normal accuracy this code gives me three alternatives from one button:
binary_sensor:
- platform: gpio
pin:
number: 14 #usable pins 14, 16, 17, 18, 19, 21, 22, 23
mode: INPUT_PULLUP
inverted: True
name: "1"
filters:
- delayed_on: 10ms
- delayed_off: 10ms
on_multi_click:
- timing:
- ON for at most 1s
- OFF for at least 1s
then:
- mqtt.publish:
topic: madmax/madmaxfrontknapper/knapp/1
payload: "1"
- timing:
- ON for at most 1s
- OFF for at most 1s
- ON for at most 1s
- OFF for at least 1s
then:
- mqtt.publish:
topic: madmax/madmaxfrontknapper/knapp/1
payload: "2"
- timing:
- ON for at most 1s
- OFF for at most 1s
- ON for at most 1s
- OFF for at most 1s
- ON for at most 1s
- OFF for at least 1s
then:
- mqtt.publish:
topic: madmax/madmaxfrontknapper/knapp/1
payload: "3"
invalid_cooldown: 1001ms