Mimic light or switch with a broadlink-controlled fan light?

Hi, I’m not even really sure what to ask, but here goes :slight_smile:

I’ve got a Broadlink RM4 pro set up to control my ceiling fan, but the fan remote doesn’t have discrete light on/light off buttons, but rather just one button to toggle the light on/off.

Is there a way for me to set the toggle to keep track of the state (from a defined known state) and make it work more like a switch? (like, if I call switch.turn_on, and it’s already on, to not send the command)?

Thanks,
-jamie

The problem is that the Broadlink has no way of knowing whether the light is on or off - all it does is blast out the codes.

You might try using an input_boolean to mirror the state of the light. The input_boolean would be your on/off switch, with an automation to send the toggle command each time it was changed.

I think that I’ve got it.

  • I created an input_boolean.office_fan_light in the helpers
  • I created a script (toggle_office_fan_light) to call the broadlink command to toggle the light
  • I created two scripts, one for on and one for off, that look like this:
turn_on_office_fan_light:
  alias: Turn On Office Fan Light
  sequence:
  - if:
    - condition: state
      entity_id: input_boolean.office_fan_light
      state: 'off'
    then:
    - service: script.toggle_office_fan_light
      metadata: {}                                                                                                                  
      data: {}                                                                                                                      
    - service: input_boolean.turn_on
      metadata: {}                                                                                                                  
      data: {}                                                                                                                      
      target:
        entity_id: input_boolean.office_fan_light
    - service: system_log.write
      data:
        level: warning
        message: Executed Turn On Office Fan Light
  description: ''
  icon: mdi:ceiling-fan-light
  • And I added a template switch to my configuration.yaml to tie them together:
switch:
  - platform: template
    switches:
      office_ceiling_fan_light:
        value_template: "{{ is_state('input_boolean.office_fan_light', 'on') }}"
        turn_on:
          service: script.turn_on
          entity_id: script.turn_on_office_fan_light
        turn_off:
          service: script.turn_on
          entity_id: script.turn_off_office_fan_light

Now I can use the switch.office_ceiling_fan_light as intended (well, at least it seems to work :smiley: )