Hi all, I’m looking for a device that’s just a simple button that triggers an event. So the event should just be something that signifies “button was pressed”. Not a sustained state. Just a trigger.
Anyone know if this kind of thing exists and if there’s a commercial product I can find? Wifi or Zigbee are both fine.
@brandont, I have the Sonoff version of this device which also provides the same set of actions, but only works on the sonoff app. In Home Assistant, it gets states which are sustained:
Single Press = Off
Double Press = On
Long Press = Off
So in HA, once it’s On, then you can’t use Double Press again as the state is already On and won’t change and won’t trigger another event. You have to Single Press to change the state to Off, then Double Press will work again.
I’m afraid of these other devices having the same behavior. Have you actually the Samsung one and confirmed it actually works as expected? Or is there a different event I should be monitoring in HA?
@Cheesenwine the button events are stateless. When the button is pressed, you’ll receive one of three zha events: button_single, button_double, or button_hold.
I use both Node Red and the native HA Automations to capture and respond to presses (or double press, holds) directly.
Once you pair the button with Zigbee, you get the device_ieee from the Events part of Developer Tools (just press the button and you’ll capture it from the zha_events). Here is what I used as a guide:
I fixed it by setting the state back to ‘none’ one second after it goes to ‘single’ or ‘double’:
- alias: LC Reset Aqara Click State
trigger:
- platform: state
entity_id: sensor.aqara_click
to: 'single'
- platform: state
entity_id: sensor.aqara_click
to: 'double'
action:
- delay: '00:00:01'
- service: python_script.set_state
data_template:
entity_id: sensor.aqara_click
state: none
it uses a python script to actually do the work:
#==================================================================================================
# python_scripts/set_statev2.py
#==================================================================================================
#--------------------------------------------------------------------------------------------------
# Set the state or other attributes for the entity specified in the Automation Action
#--------------------------------------------------------------------------------------------------
# service:
# python_script.set_statev2
# {"entity_id": "light.keukeneiland","state":"on","icon":"mdi:door","friendly_name":"test"}
inputEntity = data.get('entity_id')
if inputEntity is None:
logger.warning("===== entity_id is required if you want to set something.")
else:
inputStateObject = hass.states.get(inputEntity)
inputState = inputStateObject.state
inputAttributesObject = inputStateObject.attributes.copy()
for item in data:
newAttribute = data.get(item)
logger.debug("===== item = {0}; value = {1}".format(item,newAttribute))
if item == 'entity_id':
continue # already handled
elif item == 'state':
inputState = newAttribute
else:
inputAttributesObject[item] = newAttribute
hass.states.set(inputEntity, inputState, inputAttributesObject)
I don’t remember where I got the script but it wasn’t my invention.
Have you considered NFC tags I have several but have not integrated yet but seems like an alternative and the benefit of no need for power as they are passive and cheap to boot