Cannot trigger an automation with an RFXTRX switch

I’m struggling with my first attempt at doing some automation that is to be triggered by an RFXTRX switch. Using an RF remote as an example, when I press a button, I get the following in the log:

16-09-16 00:20:45 homeassistant.components.rfxtrx: Receive RFXCOM event from (Device_id: 1579b1 Class: LightingDevice Sub: 0)
16-09-16 00:20:45 homeassistant.core: Bus:Handling <Event button_pressed[L]: entity_id=switch.remote, state=unknown command (0x1579b1)>

The remote is configured as:

switch remote:
  platform: rfxtrx
  devices:
    091300001579b1022570:
      name: Remote
      fire_event: True

Then I tried to do a simple automation saying that a certain light should turn off, if the button was pressed:

automation:
  - alias: 'Test automation'
    trigger:
      platform: state
      entity_id: switch.remote
      state: 'off'
    condition: use_trigger_values
    action:
      service: light.turn_off
      entity_id: light.diningtable_left

It seems it doesn’t trigger no matter what I do. I tried different things with the “state” line, such as replacing ‘off’ with ‘unknown’ and leaving out the line entirely to no avail. I also tried to leave out the condition line.

I don’t know how to debug this. Can anyone help? :confused:

I found the solution. In case someone else needs it:

As per the log file, the remote causes a “button_pressed” event, so the automation code should be:

automation:
  - alias: 'Test automation'
    trigger:
      - platform: event
        event_type: button_pressed
        event_data: {"entity_id": "switch.remote"}
    action:
      service: light.turn_off
      entity_id: light.diningtable_left
1 Like

Thank you for this tip. Helps me to.

I’m trying to figure out how to add event data to this automation. For example; I only want to execute this automation when I press ‘on’. I want to trigger an other automation when pressed ‘off’.

Any suggestions?

My automation:

  • alias: Woonkamer scene aanzetten
    trigger:
    platform: event
    event_type: button_pressed
    event_data: {“entity_id”: “switch.multipulse”}
    action:
    service: scene.turn_on
    entity_id: scene.woonkamer_verlichting

Switch log entries:
Oct 30 10:38:49 raspberrypi hass[24929]: INFO:homeassistant.core:Bus:Handling <Event button_pressed[L]: state=off, entity_id=switch.multipulse>
Oct 30 10:38:23 raspberrypi hass[24929]: INFO:homeassistant.core:Bus:Handling <Event button_pressed[L]: state=on, entity_id=switch.multipulse>

Did you ever figure this one out? I’m in the exact same spot as you, not being able to trigger a specific automation on specific state.

you have to add fire_event: true like this:

0b11000600f5f11e02010f50:
  name: scene1
  fire_event: True

and in your automation you can use something like this:

- alias: "Alles aan"
  trigger:
    - platform: event
      event_type: button_pressed
      event_data: {"entity_id": "switch.scene1", "state": "on"}
  action:
    - service: scene.turn_on
      entity_id: scene.alles_aan

- alias: "Alles uit"
  trigger:
    - platform: event
      event_type: button_pressed
      event_data: {"entity_id": "switch.scene1", "state": "off"}
  action:
    - service: scene.turn_on
      entity_id: scene.alles_uit

@Sennevds does this mean that Homeassistant does some kind of conditional testing in the background?

If you have a switch that either can send state: “on” or state: off? So if I pass as you describe, “state”: “on” with event_data, HA check so that INFO:homeassistant.core:Bus:Handling <Event button_pressed[L]: state=on, entity_id=switch.multipulse> state is really “on” in the event?