SOLVED: How do I create a switch or light with MQTT sending of RF codes through the RFBridge?

I have a RF controlled light, and I have no idea how to get a state from it, so I can’t do a ‘state-topic’ to see what the current light is.
My first idea was to use two automations, one for turning it on, and flip the input-boolean, and the other for turning it off.
But then I can’t expose it to my Google home, which is not optimal, and using it in other automations is also a hassle.
So I would like to create a switch.

Something like this:

  - platform: mqtt
    name: "Trappe"
    state_topic: ""
    command_topic: "cmnd/rfbridge/RfCode"
    qos: 1
    payload_on: "#B73F08"
    payload_off: "#B73F07"

But as I don’t have a state_topic, how do I make this work?

Just had an idea, that I could maybe use a switch with template platform.
So I did this:

    switches:
      trappe:
        friendly_name: "Trappe"
        value_template: "{{  is_state( 'input_boolean.stairs_light' , 'on' ) }}"
        turn_on:
          - service: mqtt.publish
            data:
              topic: "cmnd/rfbridge/RfCode"
              payload: "#B73F08"
              qos: 1
          - service: homeassistant.turn_on
            data:
              entity_id: input_boolean.stairs_light
        turn_off:
          - service: mqtt.publish
            data:
              topic: "cmnd/rfbridge/RfCode"
              payload: "#B73F07"
              qos: 1
          - service: homeassistant.turn_off
            data:
              entity_id: input_boolean.stairs_light

And that works perfectly :smiley:
I think this is the best way of doing this. After a boot the boolean value might be wrong, so the first time it might not react, but after that it will work.

Hi fribse,

this method seems not to work anymore since HA 2023.5.3 - did you fix it meanwhile to work with the most current version, please?

switch:                                                   
      - unique_id: kugellampe_1                           
        friendly_name: "Kugellampe"                       
        value_template: "{{  is_state( 'input_boolean.kugel_switch' , 'on' ) }}"
        turn_on:                                                                
          - service: mqtt.publish                                               
            data:                                                               
              topic: "cmnd/tasmota_rfbridge/RfCode"                             
              payload: "#501703"                                                
              qos: 1                                                            
          - service: homeassistant.turn_on                                      
            data:                                                               
              entity_id: input_boolean.kugel_switch                             
        turn_off:                                                               
          - service: mqtt.publish                                               
            data:                                                               
              topic: "cmnd/tasmota_rfbridge/RfCode"                             
              payload: "#50170C"                                                
              qos: 1                                                            
          - service: homeassistant.turn_off                                     
            data:                                                               
              entity_id: input_boolean.kugel_switch 

→ results always in: Invalid config for [switch]: required key not provided …

You are missing half of the definition

switch:
  - platform: template
    switches:
      kugellampe:                                                   
      - unique_id: kugellampe_1                           
        friendly_name: "Kugellampe"                       
        value_template: "{{  is_state( 'input_boolean.stairs_light' , 'on' ) }}"
        turn_on:                                                                
          - service: mqtt.publish                                               
            data:                                                               
              topic: "cmnd/tasmota_rfbridge/RfCode"                             
              payload: "#501703"                                                
              qos: 1                                                            
          - service: homeassistant.turn_on                                      
            data:                                                               
              entity_id: input_boolean.kugel_switch                             
        turn_off:                                                               
          - service: mqtt.publish                                               
            data:                                                               
              topic: "cmnd/tasmota_rfbridge/RfCode"                             
              payload: "#50170C"                                                
              qos: 1                                                            
          - service: homeassistant.turn_off                                     
            data:                                                               
              entity_id: input_boolean.kugel_switch

and don’t copy without understanding what you copy
you check

value_template: "{{  is_state( 'input_boolean.stairs_light' , 'on' ) }}"

but you set

input_boolean.kugel_switch 

I did not correct that above !

1 Like