jheling / freeathome

Free@Home component for Home Assistant
103 stars 37 forks source link

Fire on event for binary_sensor on every press #111

Closed rsegers closed 2 years ago

rsegers commented 2 years ago

Actuators that are exposed in Home Assistant as binary sensors (typically wall switches) fire an event when pressed. The event type is freeathome_event and contains the following actuator's information:

Key Type Example
name string Actuator Hallway
serialnumber string ABB700CE9999
unique_id string ABB700CE9999/ch0000
state bool true for on / false for off
command string "pressed" is the only option at this moment

The event fires regardless of the state of the binary sensory in Home Assistant and Free@Home. Each time the wall switch is pressed, the event fires.

These events can be used in automations. For example to turn on a light every time the actuator's "on" button is pressed:

trigger:
  - platform: event
    event_type: freeathome_event
    event_data:
      unique_id: ABB700CE9999/ch0000
      command: pressed
      state: true
action:
  - service: light.turn_on
    target:
      entity_id:
      - light.nice_lamp

Addresses issue #26

EnricoBilla commented 2 years ago

Hi, I looked at your helpful work and it works fine for me. I first had issues testing it because today my SysAP was randomly disconnecting while monitoring the XMPP communication and broke different times.

Thanks for implementing it! 😄

Edit: just to add, I've got ABB (not Busch-Jaeger) devices and this PR works with them too

jheling commented 2 years ago

Nice work, thank you

EnricoBilla commented 2 years ago

I'll add a note just in case anyone will have the same problem. Devices like 2CSYE1106, which includes a relay and a binary sensor controlling the relay, won't trigger the event added in this PR since the message is not sent by the SysAP. The workaround is to separate the relay and the binary sensor in the device configuration on the SysAP, then link them in the floorplan.

Hope this will help someone in the future