RFXtrx / Coco switch button_pressed events in 0.113

With the changes to the RFXtrx integration in 0.113, I’m having problems with getting my coco (klik-aan-klik-uit) wall switches to work. Using automatic_add I’m able to add the switches to HA and from there I can make automations triggered by state changes. This is my config:

rfxtrx:
  device: /dev/ttyUSB0
  automatic_add: true
  devices:
    #keuken
    0710012c42010170:
      fire_event: true
    #wc
    0b110014019ea6aa0a000070:
      fire_event: true

However, I’m using these wall switches for lighting scenes that are also changed by other automations, so I want to trigger an automation if a wall switch is pressed, regardless of the state of the switch. In previous versions the switches generated button_pressed events, but this is not the case now.

I tried the instructions at https://www.home-assistant.io/integrations/rfxtrx/#events and went through the logs. When a switch is added, an entry in the log is visible, but it doesn’t contain packet_type , sub_type and id_string, which I need for an event according to the instructions:

2020-08-09 12:48:34 INFO (MainThread) [homeassistant.components.rfxtrx.switch] Added switch (Device ID: a1 Class: LightingDevice Sub: 1, Event: 0710012241010160)
2020-08-09 12:48:34 INFO (MainThread) [homeassistant.components.rfxtrx.binary_sensor] Added binary sensor (Device ID: a1 Class: LightingDevice Sub: 1 Event: 0710012241010160)
2020-08-09 12:48:34 INFO (MainThread) [homeassistant.components.rfxtrx.sensor] Added sensor (Device ID: a1 Class: LightingDevice Sub: 1, Event: 0710012241010160)
2020-08-09 12:48:34 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new switch.rfxtrx entity: switch.arc_a1
2020-08-09 12:48:34 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new binary_sensor.rfxtrx entity: binary_sensor.arc_a1
2020-08-09 12:48:34 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new sensor.rfxtrx entity: sensor.arc_a1_rssi_numeric

I read a couple of other posts on rfxtrx changes, but couldn’t find the answer, or maybe I just didn’t get it. What is the best way now to get button_pressed events from the coc switches?

In my setup I am using other switches but these are also integrated through RFXtrx and I had the same problem after upgrading to 0.113. Finally I found out there is a new event type “rfxtrx_event”. You should try using this. Hope this helps!

Try using the state of binary_sensor.arc_a1 to trigger your automation instead of the button_pressed event

Thanks for your response MarkBorr and Jim. I was hoping to try your suggestions this evening but my rfxtrx integration stopped working altogether. No matter what I put in the configurtion yaml for a device address, I keep getting “Error setting up entry RFXTRX for rfxtrx”.

Put quotes around your devices like this:

rfxtrx:
  device: /dev/ttyUSB0
  automatic_add: true
  devices:
    #keuken
    "0710012c42010170":
      fire_event: true
    #wc
    "0b110014019ea6aa0a000070":
      fire_event: true

Same issue here. Since 0.113 it does not work anymore despite all changes I had to make. It looks as if the event is not triggered.

rfxtrx:
  device: /dev/ttyUSB0
  debug: True
  automatic_add: True
  devices:
    "0b11007100949e5202010f70":
#      name: Leeslamp
      device_class: light
    "0b11007500949e5204010f70":
#      name: Dressoir
      device_class: light
    "0b11000201f62f4a01040f70":
#      name: Deurbel
      fire_event: true

(tried it with and without quotes around the devices.

In automations.yaml:

- id: '1597080279509'
  alias: DingDong
  description: ''
  trigger:
  - device_id: 3fffb2d311914ef686b103607b864f15
    domain: switch
    entity_id: switch.ac_1f62f4a_1
    platform: device
    type: turned_off
  condition: []
  action:
  - data:
      message: Er staat iemand bij de voordeur
    service: notify.mobile_app_nokia_7_2
  mode: single
- alias: Deurbel gaat
  trigger:
  - platform: event
    event_type: button_pressed
    event_data:
      entity_id: switch.ac_1f62f4a_1
  action:
  - data:
      message: Er staat iemand bij de voordeur
      title: Deurbel gaat!
    service: notify.notify_ronald
  mode: single

None of the above automations are triggered. If I fire them by hand, I get the messages on my telephone.

Is this a bug? Is there something wrong in the config? Lights etc work, doorbell works (KAKU ACDB-7000AC), but no trigger. I worked < 0.113.
Any clues someone?

My bad, quotes around the device IDs is necessary when the device ID consists of only numbers. It’s not the case here or with @Hapeter

Try this:

- id: '1597080279509'
  alias: DingDong
  description: ''
  trigger:
  - platform: state
    entity_id: switch.ac_1f62f4a_1
    to: 'off'
  condition: []
  action:
  - data:
      message: Er staat iemand bij de voordeur
    service: notify.mobile_app_nokia_7_2
  mode: single

- alias: Deurbel gaat
  trigger:
  - platform: state
    entity_id: switch.ac_1f62f4a_1
  action:
  - data:
      message: Er staat iemand bij de voordeur
      title: Deurbel gaat!
    service: notify.notify_ronald
  mode: single

If it still doesn’t work, try to replace switch.ac_1f62f4a_1 with binary_sensor.ac_1f62f4a_1

This part worked. Thanks!

The quotes were the problem, there was an entry further down that I didn’t copy here that had only numbers in it. Thanks @l_o_k_i!
The rfx_trx event works as a trigger, but without further conditions it triggers the automation regardless of pushing the on or off on the wall switch. That’s something for tomorrow…

With the configuration sorted out, I was able to find a solution.

The binary sensor and the switch seem to behave the same, both don’t trigger an automation if its state is unchanged, so that was a dead end for me.

The rfxtrx_event works as a trigger very well, but it doesn’t distinguish between an on or an off event. I didn’t find out how to obtain packet_type, sub_type and id_string for a switch. So, I’m still unable to specify a separate trigger for on and off on the same wall switch.

But, I achieved almost the same with a condition. So this automation works for me:

- id: '1542973354517'
  alias: Licht keuken aan
  trigger:
  - event_data:
      entity_id: switch.arc_b1
    event_type: rfxtrx_event
    platform: event
  condition:
  - condition: state
    entity_id: switch.arc_b1
    state: 'on'
  action:
  - data: {}
    service: script.1584477242921
  mode: single

Thanks @l_o_k_i and @MarkBorr!

Are you using this together with 0.113?

From 0.113 onwards, the binary sensor should fire an event, no matter whether state changed or not.

Yes, I’m using 0.113.3.
This test automation only runs if I first make the binary sensor go to its off state:

- id: '1597520769225'
  alias: Licht keuken aan test
  description: based on sensor state
  trigger:
  - entity_id: binary_sensor.arc_b1
    platform: state
    to: 'on'
  condition: []
  action:
  - device_id: a11915a5f6024ccb916a4ec2569d6b48
    domain: light
    entity_id: light.schouw
    type: toggle
  mode: single

@Hapeter To be honest, I don’t quite understand exactly what you’re trying to do. So let me show you an example of what I do:

  - id: tel433_dio_pompe_piscine
    alias: Télécommande - DIO pompe piscine
    trigger:
      - platform: state
        entity_id: binary_sensor.ac_1af57be_1
    action:
      - service_template: >
          {% if is_state ('switch.ac_1af57be_1' ,'on') %} switch.turn_on
          {% elif is_state ('switch.ac_1af57be_1' ,'off') %} switch.turn_off
          {% endif %}
        entity_id: switch.pompe_piscine

In this example I use a remote like this one to start and stop a wemo switch (switch.pompe_piscine). Everything works fine

1 Like

I’m a bit surprised you say you are using 0.113, because in this version two things changed:

  • The rfxtrx_event has been moved from entity to device level, so the entity id is not part of event data anymore.
  • The binary sensor and sensor have changed behavior that they always fired state events even when state didn’t change

Given that info, your state based automation should work and the rfx event automation shouldn’t work, but it’s exactly the other way around, which makes no sense to me…

1 Like

@RobBie1221, you’re absolutely right about the rfxtrx_event, it fires for each event that happens on the RFXtrx, it doesn’t do anything with the entity_id that I specified. It only worked as long as I had a single switch connected to the RFXtrx.

You’re also right about the state events. The automation that I posted yesterday doesn’t work because of the to: 'on' in the state trigger. I needed this because I had separate automations for on and off, but the template in the example of @l_o_k_i is much more elegant.

So, now I have this automation and it works like a charm:

- id: '1553289645598'
  alias: Kaku switch keuken
  description: Handle wall mounted switch based on binary sensor state
  trigger:
    - platform: state
      entity_id: binary_sensor.arc_b1
  action:
    - service_template: >
        {% if is_state ('binary_sensor.arc_b1' ,'on') %} light.turn_on
        {% elif is_state ('binary_sensor.arc_b1' ,'off') %} light.turn_off
        {% endif %}
      entity_id: light.milight_keukenkastjes, light.milight_keuken
  mode: single

Thanks guys, this has really helped me a lot!

I would say if the to state is on and the from field is empty, from on to on should still trigger, but apparently it doesn’t…

Perhaps there are good reasons not to have that trigger an automation, or it is a bug.

For anyone who stumbles on this topic, there’s a neat way to do this without a template. It was introduced in 0.113 as well.
With the choose functionality you can have the automation choose an action from a list of condition/ sequence pairs. So it’s no longer needed to use a template and you can build such an automation entirely in the front-end UI.
My automation now looks like this:

- id: '1598905378879'
  alias: Kaku switch keuken
  description: Handle wall mounted switch based on binary sensor state
  trigger:
  - entity_id: binary_sensor.arc_b1
    platform: state
  condition: []
  action:
  - choose:
    - conditions:
      - condition: state
        entity_id: binary_sensor.arc_b1
        state: 'on'
      sequence:
      - data: {}
        entity_id: light.milight_keukenkastjes, light.milight_keuken
        service: light.turn_on
    - conditions:
      - condition: state
        entity_id: binary_sensor.arc_b1
        state: 'off'
      sequence:
      - data: {}
        entity_id: light.milight_keukenkastjes, light.milight_keuken
        service: light.turn_off
    default: []
  mode: single
1 Like

An question about setting the brightness for the lights?
Is that possible. When I set the brightness in the data at light turn_on I get an error that it’s an invalid option.

How did you format your sequence? I suspect that you have a formatting problem.

Well I have the following in the sequence:

        sequence:
        - data: {}
          entity_id: light.hue_white_lamp_3, light.hue_filament_bulb_1
          brightness_pct: 30
          service: light.turn_on

With this I get the error about invalid option.