RF button press > Sonoff bridge> trigger an automation

I can’t find a topic that covers this. OK:

  • I have a 3-gang RF button
  • I have a Sonoff bridge
  • I can see the incoming button clicks for each button as a notification, for testing (thanks to this article)
  • These show up like this:

Sonoff RF Receive
Name: 3wayA1
Command: 0

…where 3wayA1 is the name of the button in eWeLink, and Command=0 is its unique ID
…and, for the other two buttons, 3wayA2 and 3wayA3, I get Command=1 and Command = 2

Good: HA sees each button individually.

My test automation - below - runs whenever any of the three buttons is clicked, so I must be nearly there! But I’ve fiddled and fiddled in trying to use the incoming parameters so that I can, obviously, have separate automations for each button.

Can someone tell me what I need to do? …and preferably without MQTT, which I haven’t learnt yet. Thanks!

alias: Test RF button
description: ‘’
trigger:

  • platform: event
    event_type: sonoff.remote
    condition: []
    action:
  • service: scene.turn_on
    target:
    entity_id: scene.dawn
    mode: single

You are not saying how exactly the actions should be different depending on the button pressed, but let’s suppose you want to turn on different scenes.
My understanding of the Sonoff bridge integration is that the “name” relates to the RF device and the “command” is just a number of the button in this case. The following condition checks for the device name, and the action calls different scenes. Something like the following should work:

condition: "{{ trigger.event.data.name == '3wayA1' }}"
action:
  - service: scene.turn_on
    target:
      entity_id: >
        {% if (trigger.event.data.command == '0') %}scene.myscene1{% elif
        (trigger.event.data.command == '1') %}scene.myscene2{% elif
        (trigger.event.data.command == '2') %}scene.myscene3{% endif %}

(edit: fixed the condition’s missing double-quotes, and simplified it)

Many thanks for looking at this. Yes I want different actions per button, but I can Call Service as needed. I can also work with either data.command = 0 or data.name = ‘3wayA1’, as either identifies the button involved.

I’m now stuck on your value_template syntax I’m afraid. I get:

Message malformed: template value should be a string for dictionary value @ data[‘condition’][0][‘value_template’]

…when I run the code below. NB I’ve stripped out your elseif/endifs for simplicity. Thanks in advance!

alias: Test RF button (with template)
description: ‘’
trigger:

  • platform: event
    event_type: sonoff.remote
    condition:
  • condition: template
    value_template: {{ trigger.event.data.command = ‘0’ }}
    action:
  • service: scene.turn_on
    target:
    entity_id: >
    scene.dawn
    mode: single

Sorry, I forgot to enclose the single-line template in double-quotes in my example (fixed above now). And this could even be simplified:

condition: "{{ trigger.event.data.name == '3wayA1' }}"

I am not using that particular Sonoff bridge integration myself, but it looks as only the name and the command together uniquely identify a button press. In other words, if you ever get a second RF button device then it would also send command values of 0, 1, etc. but the name should be different.

And, please format your YAML code using the </> button, otherwise it’s really hard for us to help you with the syntax of your configuration.

Works! I’m stupidly happy - Thank you! Other points noted. Hopefully your solution will help others too :slightly_smiling_face:.

1 Like

Im tring to do this as well what was the ending code you used that worked?

alias: test button
description: ''
trigger:
  - platform: event
    event_type: sonoff.remote
condition:
  - condition: template
    value_template: '{{ trigger.event.data.name == ''Off'' }}'
action:
  - service: scene.turn_on
    target:
      entity_id: >
        {% if (trigger.event.data.command == '0') %}scene.myscene1{% elif
        (trigger.event.data.command == '1') %}scene.ledoff{% elif
        (trigger.event.data.command == '2') %}scene.myscene3{% endif %}
mode: single

didnt work i just want the off button on the remote to trigger an automation…

Are you sure that the “name” in the event data is actually “Off”?
My understanding of the Sonoff bridge integration is that the “name” actually refers to the RF device and the “command” is a number refering to the button pressed.

As Jesterod says - check the name of the button in the ewelink app:

I figured it out its actually even easier

But yea i was using the wrong name i used what i named the button and its what the data.name shows

1 Like

And I’m just repeating my warning from above: This easier approach works as long as you only have a single device. As soon as you have multiple devices, they will all have a button that comes in as command: 1 and you will need to start distinguishing by name, too.

Probably right but i currently only have the one device tho the video i watched showed a guy useing 2 buttons and a motion sensor and it was. Command: 0,1,2

Yes it starts at 0. Still worth considering giving each button a name, though. These buttons are very cheap and I’m up to 9 or so.