Using RF button to toggle light switch

Hi

I want to use an RF switch (intercepted by my Sonoff RF Bridge) to toggle a light switch. The RF switch is a simple push button. It does not send “payload_off” data. I push the switch, I get “442122”. I release it and I get nothing. Upon restarting HA or reloading Manually Configured MQTT Entries, I am able to use the automation once. I push the switch and the light comes on. However, subsequent pushes don’t do anything. I’m guessing there’s something wrong with the payload_on and off logic but I can’t seem to make it out.

Thank you

Configuration

 #RF Switches   
    - name: "Bathroom RF Light Switch"
      unique_id: "RFSwitch03"
      state_topic: "tele/rf-bridge/RESULT"
      payload_on: "442122"
      payload_off: "xxx"
      qos: 1
      value_template: "{{ value_json.RfReceived.Data }}"

Automation:

- id: '12345'
  alias: Bathroom-RF Switch Toggles Light
  description: ''
  trigger:
  - platform: state
    entity_id:
    - binary_sensor.bathroom_rf_light_switch_2
    from: 'off'
    to: 'on'
  - platform: state
    entity_id:
    - binary_sensor.bathroom_rf_light_switch_2
    from: unknown
    to: 'on'
  - platform: state
    entity_id:
    - binary_sensor.bathroom_rf_light_switch_2
    from: unavailable
    to: 'on'
  condition: []
  action:
  - type: toggle
    device_id: d5114a764e9a2efd19a87aa2c6e9ba3e
    entity_id: switch.pendant_8
    domain: switch
  mode: restart

Below is one of my automations doing the same thing.

alias: RF_Button_2 toggles Lohas Bulb6 tasmota BEDROOM Lamp
description: ""
trigger:
  - platform: state
    entity_id: binary_sensor.rf_button_2
    to: "on"
    from: "off"
condition: []
action:
  - type: toggle
    device_id: 7aae303b751e62b65f3e267213ce534d
    entity_id: light.lohas_bulb_6
    domain: light
mode: single

Thanks, can i see the config for the entity?

I managed to fix it by having my Action send a subsequent (at the end) payload for the OFF condition, thereby duping HA into thinking the RF switch has sent it, but I’m not happy about it. Seems like a lot of work for a small thing. I also had to include a small delay to get it working reliably.

Automation (look for the _off below):

alias: Bathroom-RF Switch Toggles Light
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.bathroom_rf_light_switch_2
    from: "off"
    to: "on"
  - platform: state
    entity_id:
      - binary_sensor.bathroom_rf_light_switch_2
    from: unknown
    to: "on"
  - platform: state
    entity_id:
      - binary_sensor.bathroom_rf_light_switch_2
    from: unavailable
    to: "on"
condition: []
action:
  - type: toggle
    device_id: d5114a764e9a2efd19a87aa2c6e9ba3e
    entity_id: switch.pendant_8
    domain: switch
  - delay:
      hours: 0
      minutes: 0
      seconds: 2
      milliseconds: 0
  - service: mqtt.publish
    data:
      topic: tele/rf-bridge/RESULT
      payload: >-
        {"Time":"2022-12-05T16:44:53","RfReceived":{"Sync":20434,"Low":682,"High":1940,"Data":"442122_off","RfKey":"None"}}
mode: restart

Configuration:

 - name: "Bathroom RF Light Switch"
      unique_id: "RFSwitch03"
      state_topic: "tele/rf-bridge/RESULT"
      payload_on: "442122"
      payload_off: "442122_off"
      qos: 1
      value_template: "{{ value_json.RfReceived.Data }}"

Looks like I also use the “_off” like you did. I am not a pro by any means. I recall struggling while trying to do this and searching the forums for what I needed to get it to work at that time.

I have since added a few more RF buttons and they all follow this format.

I see my device_class is motion, which is how I set it up as a newbie a few years ago…

Configuration:

  - platform: mqtt
    name: "RF_Button_2" #WHITE ROUND PUSH BUTTON
    state_topic: "tele/tasmota_rfbridge/RESULT"
    value_template: '{{value_json.RfReceived.Data}}'
    payload_on: "489521"
    payload_off: "489521_off"
    device_class: motion
    off_delay: 1
    qos: 1
    #payload_on: "489521" # this is what it is when RF_bridge is not in RAW```
1 Like

Thanks, that was indeed the solution!