Physical Buttons for Home Assistant

Those RF devices look like a good idea. However I want to make a solution from scratch whilst learning a bit more about python and the power of the Raspberry pi, so probably not the route i’ll go with mine!

It’s absolutely overkill but I found myself in a similar situation – there’s just something nice about something that’s tactile and dedicated specifically to its own function! I actually made a HASS remote by hollowing out a block of nice-looking wood, then adding 4 through-hole buttons on the top. Inside is an ESP-12 flashed with ESPHome, and each button triggers a separate HA script that changes the button’s function based on what else is going on (e.g. if my alarm is going off, it turns it off, but otherwise it acts as a lightswitch for the room, setting a scene based on what time of day and who’s home). The enclosure has a battery, but right now it only lasts a few hours, the next step for me is to figure out a circuit that’ll wake up the module from deep sleep while still registering the right button push. I also have a few dash button lightswitches that other housemates like because they always do the same thing, every time. I expect this is pretty close to what you’re making with your pi!

Also: if you wanna practice your python, I highly recommend seeing what all you can write in AppDaemon. It’s much less popular than NodeRED but it’s great python practice for complex script/automation-writing since, well, it’s actually just python.

Can you use more than one of these buttons? Or are they all coded the same? EG buy 2 buttons, does the receiver know which button has been pressed?

J

I have 5 of these buttons, they have all unique rf codes. You can assign any action you want through automations.

Excellent, 4 on order. I wondered if I’d made an error and they were all the same code.

Can you set up automation’s for long clicks etc…?

Many thanks for taking time to respond!

J

There is no long click functionality, still produces the same rf code.
you still need an rf receiver to capture the rf feeds ie. Sonoff RF Bridge.

i’ll share the config later next week.

ps remind me otherwise :wink:

I don’t have these, but I imagine you could set up something to handle double, triple, etc. clicks. Some components apparently have built-in support for that. If not, I remember a discussion where someone was trying to do that with a switch.

Essentially, you use a counter to count the number of clicks then have an automation that fires when it hasn’t been clicked again in X seconds and acts based on the current value of the counter.

Interesting. I guess this would introduce a delay, for the automation to “wait” to see if another click is coming?

I assume the limitation is that these are 'single channel"?

J

Yes, there would be a delay for every single click in that case. I’m not sure how tight you could get it via this method. It would depend on all of the hardware involved and how fast HA can pick up and react to the button presses.

Hi,

I use a Wemos (with ESP8266) in alot of my physical buttons on my home, I has this configuration two years ago more or less, and i think it’s perfect!!

Somees devices with ESPEasy, anothers with Espurna (for the double pulse) and now I will try with ESPHome firmware.

Antoni.

I use little RF buttons. Details on my blog.

Per @ciotlosm input from 4 months back, zigbee2mqtt really is a great and cheap way to add buttons and sensors.
I just finished to migrate my devices from xiaomi hub to zigbee2mqtt (sadly prompted by a dataloss event :frowning: )

Thanks to zigbee2mqtt the Xiaomi buttons are as capable as the button itself will support.
Also the philips hue dimmer switch is awesome - its a 4 button device and each button supports click(s) with count of clicks, long click, long release etc and its very easily available at lowish cost.
MANY other sensors, switches and buttons are also supported and the list is growing.

Full list here:

I have finally received my buttons and set up opennqtt gateway… I had to change the pin on my nodemcu to get things working with the RF rx I bought.

My issue now is the RF buttons appear to give a different code each time they are clicked! I see this in my mqtt broker and the value that Homeassistant shows in the front end!

Here is a sample from my mqtt broker - this is pressing two buttons:

home/OpenMQTTGateway/433toMQTT {"value":14489825,"protocol":1,"length":24,"delay":277}
home/OpenMQTTGateway/433toMQTT {"value":4074129,"protocol":1,"length":24,"delay":293}
home/OpenMQTTGateway/433toMQTT {"value":4139665,"protocol":1,"length":24,"delay":293}
home/OpenMQTTGateway/433toMQTT {"value":6109217,"protocol":11,"length":23,"delay":428}
home/OpenMQTTGateway/433toMQTT {"value":6105313,"protocol":11,"length":23,"delay":425}
home/OpenMQTTGateway/433toMQTT {"value":4139665,"protocol":1,"length":24,"delay":299}
home/OpenMQTTGateway/433toMQTT {"value":4139153,"protocol":1,"length":24,"delay":293}
home/OpenMQTTGateway/433toMQTT {"value":14489825,"protocol":1,"length":24,"delay":278}
home/OpenMQTTGateway/433toMQTT {"value":4131473,"protocol":1,"length":24,"delay":292}
home/OpenMQTTGateway/433toMQTT {"value":4139153,"protocol":17,"length":24,"delay":395}
home/OpenMQTTGateway/433toMQTT {"value":14495969,"protocol":1,"length":24,"delay":272}
home/OpenMQTTGateway/433toMQTT {"value":6109217,"protocol":11,"length":23,"delay":426}
home/OpenMQTTGateway/433toMQTT {"value":14485729,"protocol":17,"length":24,"delay":368}
home/OpenMQTTGateway/433toMQTT {"value":4139665,"protocol":1,"length":24,"delay":299}
home/OpenMQTTGateway/433toMQTT {"value":4131473,"protocol":1,"length":24,"delay":293}
home/OpenMQTTGateway/433toMQTT {"value":4137617,"protocol":1,"length":24,"delay":293}
home/OpenMQTTGateway/433toMQTT {"value":14498017,"protocol":1,"length":24,"delay":273}
home/OpenMQTTGateway/433toMQTT {"value":14495969,"protocol":1,"length":24,"delay":273}
home/OpenMQTTGateway/433toMQTT {"value":4139665,"protocol":1,"length":24,"delay":298}

Any ideas?

John

Is it the same set of codes repeated over and over? Probably

Hi all

Any ideas what is simplest way get wireless buttons to HASS.io with minimal work. I have couple zwave wireless buttons and i hate that network and add system to zwave. Be so automatic, but newer find anything :slight_smile:

How about this Xiaomi buttons, need some gateway that too?
https://www.aliexpress.com/item/2018-Upgraded-Xiaomi-Aqara-Wireless-Switch-Single-Double-Button-Key-Smart-Light-Control-ZigBee-Version-for/32863511201.html

Happily take every tips/hints what is best and EASYEST way to get working simple wireless buttons. All other nodes working with mqtt, but they use wall sockets and need couple places wireless buttons without wires, that why need some easy and simple buttons.

Many thanks every answers.

I started this thread over 2 years ago! I use a Xiaomi smart hub with a couple of their buttons around the house. Buttons are simple (click, double click, long press) and can be bound to automations in minutes. I have had them in for nearly 2 years now and i haven’t had to change the batteries. I even use one of the buttons on my front door as my doorbell now (Xiaomi smart hub has a speaker in it which can play from a range of sounds or you can upload any mp3) and the automation also sends me a push notification via the alexa app and trips all the alexas in the house to say “There is someone at the door”. Love the Xiaomi kit, i have pick up some temp sensors and motion sensors also to go with the buttons. Super cheap platform too. 11 out of 10 :wink:

~Mick

This is an example of the kjt that I have, but you can buy all the parts seperately if you don’t want the full kit. Search for Xiaomi Mijia.

@Mick_Kerrigan Can you please share one or two of your simplest automations using the Xiaomi smart switches? I’m just getting these setup this evening, and an example would be MOST helpful. Thank you!

I can help if you like. Now this may seem far from simple, however if you mainly just look at the first automation section where I distinguish between the 3 types of clicks and what to do based on each type, you will see how capable these little switches are

I use packages so all this is in a package called ‘kitchen_light.yaml’

#  All code relating to the functioning of the kitchen light

input_number:
  kitchen_light_auto_off_time:
    name: Off after
    min: 1
    max: 9
    step: 1
    icon: mdi:camera-timer
    unit_of_measurement: min

  kitchen_min_lux:
    name: On below
    min: 0
    max: 30
    step: 1
    icon: mdi:brightness-6
    unit_of_measurement: lux


automation:
  - alias: 'Kitchen Remote Button 1'
    initial_state: 'on'
    trigger:
      - platform: event
        event_type: xiaomi_aqara.click
        event_data:
          entity_id: binary_sensor.switch_158d0002241b37
          click_type: single
      - platform: event
        event_type: xiaomi_aqara.click
        event_data:
          entity_id: binary_sensor.switch_158d0002241b37
          click_type: double
      - platform: event
        event_type: xiaomi_aqara.click
        event_data:
          entity_id: binary_sensor.switch_158d0002241b37
          click_type: long_click_press
    action:
      - service_template: >
          {% if trigger.event.data.click_type == 'single' %}
            script.kitchen_button_single_click
          {% elif trigger.event.data.click_type == 'double' %}
            script.kitchen_button_double_click
          {% elif trigger.event.data.click_type == 'long_click_press' %}
            script.kitchen_button_long_press
          {% endif %}
          

  - alias: 'Kitchen light auto ON motion'
    initial_state: 'on'
    trigger:
      - platform: state
        entity_id: binary_sensor.kitchen_multi_sensor_sensor
        to: 'on'
    condition:      # look at changing this to use room light level only
      condition: or
      conditions:
#      - condition: sun
#        after: sunset
#        after_offset: '-00:15:00'
#      - condition: sun
#        before: sunrise
#        before_offset: '-01:00:00'
      - condition: template
        value_template: "{{ states('sensor.kitchen_multi_sensor_luminance') | int < states('input_number.kitchen_min_lux') | int }}"
      - condition: state
        entity_id: light.kitchen_light_level
        state: 'on'
    action:
      - service: script.turn_off
        entity_id: script.kitchen_light_auto_off_timer
      - service_template: >
          {% set t = now().strftime('%T') %}
          switch.turn_o{{ 'n' if t > '20:00:00' or t < '06:30:00' else 'ff' }}
        entity_id: 
          - switch.circadian_lighting_kitchen_circadian_lighting
      - service: light.turn_on
        data:
          entity_id: light.kitchen_light_level
      - condition: and
        conditions: 
          - condition: time
            before: '20:00:00'
          - condition: time
            after: '06:30:00'
      - service: light.turn_on
        data:
          entity_id: light.kitchen_light_level
          brightness: 255

  - alias: 'Kitchen light auto off'
    initial_state: 'on'
    trigger:
      - platform: state
        entity_id: binary_sensor.kitchen_multi_sensor_sensor
        to: 'off'
    action:
      - service: script.turn_off
        entity_id: script.kitchen_light_auto_off_timer
      - service: script.turn_on
        entity_id: script.kitchen_light_auto_off_timer


script:
  kitchen_button_single_click:
    alias: Kitchen button single click
    sequence:
    - service: automation.turn_off
      data:
        entity_id: 
          - automation.kitchen_light_auto_on_motion
          - automation.kitchen_light_auto_off
    - service: script.turn_off
      entity_id: script.kitchen_light_auto_off_timer
    - service: switch.turn_off
      data:
        entity_id: switch.circadian_lighting_kitchen_circadian_lighting
    - service: light.turn_on
      data:
        entity_id: light.kitchen_light_level
        brightness: 255

  kitchen_button_double_click:
    alias: Kitchen button double click
    sequence:
    - service: automation.turn_off
      data:
        entity_id: 
          - automation.kitchen_light_auto_on_motion
          - automation.kitchen_light_auto_off
    - service: light.turn_off
      data: 
        entity_id: light.kitchen_light_level

  kitchen_button_long_press:
    alias: Kitchen button long press
    sequence:
    - service: automation.turn_on
      data:
        entity_id: 
          - automation.kitchen_light_auto_on_motion
          - automation.kitchen_light_auto_off

  kitchen_light_auto_off_timer:
    alias: Kitchen light off after preset time
    sequence:
    - delay: '00:0{{ states.input_number.kitchen_light_auto_off_time.state | int }}:00'
    - service: homeassistant.turn_on
      data:
        entity_id: light.kitchen_light_level
        brightness: 60
    - delay: '00:00:03'
    - service: homeassistant.turn_on
      data:
        entity_id: light.kitchen_light_level
        brightness: 30
    - delay: '00:00:02'
    - service: homeassistant.turn_off
      data:
        entity_id: light.kitchen_light_level

MUCH appreciated, just a quick look showed me a few things I can change/try. THANK YOU!! :smiley:

Most specifically, the fully-qualified event name xiaomi_aqara.click was the key item. It allowed me to listen for the events of each switch I’ve added to the new gateway and confirm the proper entity_id for each one. The automations I started with are now working, after only a very few minor changes. THANKS!! :smiley: