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:
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!
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”.
(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
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:
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
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…
@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
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
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.