Two buttons + one light = can't get it to work

Hi! I have two buttons/switches that works fine, one is a RfLink device (“matbord_brytare”), a 2-gang switch sending “ON” one way and “OFF” the other way. The second is a IKEA Tradfri E1810 (“tradfri_remote”), and I’m using action “brightness_up_click” or “brighness_down_click” to turn the lamp on or off. By themselves they works fine using an automation to turn on or off a light.

The configuration for the RfLink switch:

- platform: rflink
  device_defaults:
    fire_event: true
  signal_repetitions: 2
  devices:
    newkaku_0009db9a_2:
      name: matbord_brytare

The problem arises when I try to combine these two switches to control a single light (i.e. a lamp (“kokslampa_matbord”) in a room with with one switch in each end of the room) so I can control the light from any switch.

I tried the following automation (one for “on” and one for “off”):

- alias: "Matbordslampan on"
  trigger:
    - platform: state
      entity_id: switch.matbord_brytare
      to: "on"
    - platform: state
      entity_id: sensor.tradfri_remote_action
      to: "brightness_up_click"
  action:
    - service: light.turn_on
      entity_id: light.kokslampa_matbord
    - service: switch.turn_on
      entity_id: switch.matbord_brytare

- alias: "Matbordslampan off"
  trigger:
    - platform: state
      entity_id: switch.matbord_brytare
      to: "off"
    - platform: state
      entity_id: sensor.tradfri_remote_action
      to: "brightness_down_click"
  action:
    - service: light.turn_off
      entity_id: light.kokslampa_matbord
    - service: switch.turn_off
      entity_id: switch.matbord_brytare

The Tradfri seems to work most of the time (on and off), but not the RfLink. To be synchronized I try to reflect the state of the switches, so that when Tradfri turns on, it sets the state of the “matbord_brytare” to “on” as well. But however I try it will not work. Most of the time the Tradfri works ok, but if I turn on the lamp using it, I can’t change the state of the lamp using the RfLink switch. Sometimes it works when I turn the lamp off again using the Tradfri, but sometimes the RfLink doesn’t work at all.

I can see in the log that the message from the RfLink (“matbord_brytare turned on”) comes and that the automation (“Matbordslampan on”) is started, but checking the trace of the automation shows that the first service is called but the automation is still running (i.e. not executing the second service) and then the buttons are out of sync.

I’ve tried different approaches in the automation, but fail to get it working perfect (the best I can achieve (by having one set of automation for each switch) is that I sometimes have to press the RfLink on and off once or twice to get them in sync and it will work again).

Anyone have an idea what I do wrong or is missing? Any ideas for a better approach?
It seems simple enough, but apparently I have missed something …

Cheers,
Thomas

The RFLink switch is a wired one or wireless?
What I would try to do is forgetting the rflink switch status and control the light status with the rflink_event, the same way you do with the Ikea switch.

Hi @javicalle,

It is a wireless wall panel switch.
Do you know how I could fetch the action from rflink (see configuration of the switch in the original post)? I can’t see any in the log, just the state changes from the switch …

Cheers,
Thomas

RFLink will trigger a button_pressed event:

You have an automation example here:

The automation could be something like:

description: "Switch kokslampa_matbord from  matbord_brytare"
mode: single
trigger:
  - platform: event
    event_type: button_pressed
    event_data:
      entity_id: switch.matbord_brytare
      state: "off"
    id: brytare_off
  - platform: event
    event_type: button_pressed
    event_data:
      entity_id: switch.matbord_brytare
      state: "on"
    id: brytare_on
action:
  - choose:
      - conditions:
          - condition: trigger
            id: brytare_off
        sequence:
          - service: light.turn_off
            target:
              entity_id: light.kokslampa_matbord
      - conditions:
          - condition: trigger
            id: brytare_on
        sequence:
          - service: light.turn_on
            target:
              entity_id: light.kokslampa_matbord

Take care that your configuration have signal_repetitions: 2 so the switch will trigger 2 events.

Hi @javicalle,

Thanks for your suggestion! I used the event and combined the RfLink switch event with the Tradfri, and it works as a charm!

Now I can turn on and off with any combination (physical, Tradfri and the RfLink switch) without any problem! And simpler than before, no need to keep track of the state, just follow the button events!
I still kept two automations, one for the two “on” events, and one for the “off”.

Cheers,
Thomas

Glad to ear!

If you set an trigger id you can use the choice selector in your action and put all together in just one automation. But that’s a matter of taste :wink: