Associate switch to Broadlink command

Hello everybody,
I have a Broadlink 3 RM PRO with some command to control my devices ( TV,ampli etc…)
Currently I’m using script to switch on or switch off my devices.
I want to know before I use the button if my devices are already up or down with a switch that corresponding my devices.
Do you have an idea about my question?
Thanks you for help.

- platform: broadlink
    mac: mac address of your broadlink (eg a043b05517ac)
      - name: device (eg television)
        command_off: JgBYAAABJJITEhMTExITEhMSExMTetcetcetc
        command_on: JgBQAAABJJITEhMTExITEhMSExMTetcetcetc

The codes your Broadlink has learned are stored in a folder called .storage in the config folder. You can’t edit them, but you can copy them with a text editor.

There’s a bit about creating custom switches in the Broadlink docs:

I think the following might be an example of what you are after. This script turns off some lights but also the TV after first checking whether it is already on:

  alias: Goodnight
  - service: light.turn_off
      entity_id: light.lounge_lamps
  - service: switch.turn_off
    entity_id: switch.lounge_candles
  - choose:
    - conditions:
      - condition: state
        entity_id: binary_sensor.samsung_smart_tv
        state: 'on'
      - service: remote.send_command
          device: lounge_tv
          command: power
          entity_id: remote.broadlink01
    default: []
  - delay:
      hours: 0
      minutes: 0
      seconds: 5
      milliseconds: 0
  - type: turn_off
    device_id: 5320c28c7c1e45c580aa9a5ad9bc4432
    entity_id: light.kitchen_leds1
    domain: light
  - type: turn_off
    device_id: 793e56970e0d467a9afca2bd780b0797
    entity_id: light.kitchen_leds2
    domain: light
    default: []
  mode: single

Thanks you for answer but with these codes can I have the current TV or ampli status.

I explain :

  • I want to switch on my TV but I don’t know if it was already ON. On my dashboard I want a button with the real TV status for example.
    The virtual switch must show me if it was already ON or not.

Thanks you.

You would need to create a sensor that can determine if the TV is on or off. Is this an integrated smart TV that reports its status to Home Assistant somehow? That would be ideal - because you could create an input bollean that automatically turns on and off based on the status it gets from that integration.

Then you would create a template switch to send the broadlink commands for on/off and also keep track of that status of the switch by linking the sensor in the value template.

If the TV doesn’t report status through an integration, another option might be to track whether it is on or off by using a smart plug that can monitor the power - above a certain power level detected means the TV is on, and turns the sensor on, below a certain power level means the TV is off, then turns off the sensor.

Thanks you for reply.
I will try this on my HA.

I can’t use the integration because I have also my ampli to monitor with the template switch.