Switching the device on and off with one RF code(RF Bridge)

Hi
I have one binary switch rf 433, it sends only one code. Is it possible to set the automation so that if the device is turned off and the button is pressed, the device is turned on, while if it is turned on and the button is pressed again, it is turned off?

 - platform: mqtt
    name: "RF switch"
    state_topic: "tasmotaRF/tele/RESULT"
    value_template: '{{value_json.RfReceived.Data}}'
    payload_on: "582AB8" ## only one code##
    device_class: plug
    qos: 1 

Do you mean the toggle service?

This is my automation, switch on its works, but switch off is not … :confused:

- alias: Office on
  trigger:
    - platform: state
      entity_id: binary_sensor.rf_switch
      to: 'on'
  action:
      service: homeassistant.turn_on
      data:
        entity_id: switch.office_2
  
- alias: Office off
  trigger:
    - platform: state
      entity_id: binary_sensor.rf_switch
      to: 'off'
  action:
      service: homeassistant.turn_off
      data:
        entity_id: switch.office_2   

Check out this topic :

If ‘on’ works, try this, and remove the second automation.

- alias: Office toggle
  trigger:
    - platform: state
      entity_id: binary_sensor.rf_switch
      to: 'on'
  action:
      service: switch.toggle
      data:
        entity_id: switch.office_2

@VDRainder works only “on” automation :confused:

 - platform: mqtt
    name: "RF switch"
    state_topic: "tasmotaRF/tele/RESULT"
    value_template: '{{value_json.RfReceived.Data}}'
    payload_on: "582AB8" ## only one code##
    device_class: plug
    qos: 1 
    off_delay: 20

in combination with switch.toggle

@francisp Francis many thanks, everything works beautifully :slight_smile:

Can you share the code that works for you ? I can’t understand how to implement switch.toggle.