Help wanted with binary sensor component automations

Hi guys.

I just build a ESP8266 with 4 buttons and 2 LED’s and got it working in Hassio.

First automation:
I wanna make two of the switches toggle (first press sends “ON”, second press sends “OFF”). Do any of you have an example of this i can look at?

Second automation:
The two other switches i wanna use as multiple funktions, so if i use on_click it sends “first-value” to Hassio, when i use on_double_click it sends “second-value” and lastly when i press and hold the switch i want to send “third-value” until i release it.

The second automation is for light;

  • One single press should turn on/off the light at last brightness.
  • Two presses should turn the auto-light-off-by-pir automation on/off.
  • When i hold the button down the light should rise in brightness until it reaches max, then fall in brightness until it reaches minimum brightness, then repeat.

The binary_sensors are as follows:

- platform: gpio
  pin:
    number: D3
    mode: INPUT_PULLUP
    inverted: True
  name: "Wall Kitchen TL"

Any examples or guidance will be of great value to me as I’m struggling to take the first steps.

A picture of the platform, using Danish LK Fuga electrical equipment.

Thank you in advance!

Here’s an example automation using a Xiaomi button, it will give you an idea about the toggle service that you can use for switches:

  - alias: Long Click to toggle Stereo & Circle Square Lights
      trigger:
        platform: event
        event_type: click
        event_data:
          entity_id: binary_sensor.switch_158d0001f9bd86
          click_type: long_click_press
      action:
        - service: light.toggle
          entity_id:
            - light.light_strip
        - service: switch.toggle
          entity_id:
            - switch.square_circle_lights
            - switch.wooden_stereo_lights

The click_type I think is special to that Xiaomi button so I don’t think it will translate to yours automatically.

You’ll, of course, have to make switch entries that the automation can toggle - here’s an example for mine that uses curl - though I guess how you’ll call the switch changes will differ, and the command_state.

- platform: command_line
  switches:
    wooden_stereo_lights:
      command_on: curl -s http://192.168.1.xxx:5000/mote/api/v1.0/larsonloop/1200/0/ee7600/0.1/1/1
      command_off: curl -s http://192.168.1.xxx:5000/mote/api/v1.0/larsonloop/1200/1/000000/0.11/1/1
      command_state: "curl -s http://192.168.1.xxx:5000/mote/api/v1.0/led_lit | grep on"
      friendly_name: Stereo Cabinet

Not sure how you’d code the second part you want, if you post what code you’re using so far to turn them on/off, change brightness, read the pir etc. I imagine someone will have done something similar and can give you pointers.

Hi Bit-River.

I’m actually trying to accomplish this in esphomeyaml and not so much in Hassio, yet. I tried the below, but no succes, throws validation error in esphomeyaml.

EDIT: My indentation was wrong… Going to test it when I’m home…

binary_sensor:
  - platform: gpio
    name: "Wall Kitchen TL"
    on_press:
      then:
        - mqtt.publish:
            topic: wall_kitchen/binary_sensor/wall_kitchen_tl/value
            payload: "Button Pressed"
    on_click:
      min_length: 50ms
      max_length: 350ms
      then:
        - mqtt.publish:
            topic: wall_kitchen/binary_sensor/wall_kitchen_tl/value
            payload: "Button Clicked Once"
    on_double_click:
      min_length: 50ms
      max_length: 350ms
      then:
        - mqtt.publish:
            topic: wall_kitchen/binary_sensor/wall_kitchen_tl/value
            payload: "Button Clicked Twice"
    pin:
      number: D3
      mode: INPUT_PULLUP
      inverted: True

Hi @skeptizzle
did you get it to work? do you need to use MQTT to get the press over in home assistant?
im sitting right now with and LK low powered 4 button that i want to use long press and double press/multi press.

i got it working with a simple binary sensor press, and toggle light on/off.

mvh
Martin

Hi Martin.

Nope, did not get it working, I didn’t have the time to spend figuring it out. Ended up using MQTT for sensors and outputs (relays) and ZigBee (on a ConBee stick) for buttons.
Have a look at a Danish Facebook group called “Philips Hue Erfaringer” and search for “svagstrøms tryk”.
The only downside is that it’s not possible to drive the LEDs, other than that it works great.
Xiaomi are making some nice, small, round buttons.

yeah, i see that you can do some cool stuff with philips hue switches, but in my case i dont have any philips, mostly yeelight and ikea trådfri and ofcourse Xiaomi, that have that feature, properly i can use one of the Xiaomi on a IHC lowpowered switch, that fit inside LK, but i will been in lack of 4 push switches :frowning:

my first plan was to use a esp-01 behind the wall switch, but misses the long press and multi press :confused: