Error in python script - why?

After I upgraded ha to latest version.

Broadlink stoped working.

I changed “boradlink.send” to “remote.send_command” and service is now working.

Now I get error in python script:

rf = { "FAN":"JgBQAAABK5IVNhUQFRAVEBUQFRAVEBU2FRAVNRU1FRAVEBU2FTUVEBU1FRAVERUQFRAVEBUQFTUVEBU2FTUVNRU1FTUWNRUQFQAFbQABLEcWAA0FAAAAAAAAAAA=",
       "LIGHT":"JgBIAAABLJETNxMTFBEUERQRFBEUERU1ExITOBI4ExITEhM3EzcTExI4ExITEhM3EzcTEhMTEjgTEhM3EzcTEhMSEzgSOBMSEwANBQ==",
       "UP":"JgBQAAABK5IUNxMSExITEhUQFBEUERQ2FBITNxQ2FBEUERQ3EzcTEhQ2FBEUNxMSExITEhMSFDYUERQ3ExITNxQ2FDYUNxMSEwAFbwABK0gUAA0FAAAAAAAAAAA=",
       "DOWN":"JgBIAAABKpMUNhMTExITEhMSFBEUERQ2FBISOBM3FBEUERM3FDcTEhMSEzcUERQ2FBITEhMSEzcUNhMSEzgTEhM3FDYUNhMTEwANBQ=="
     }

cmd = data.get('command')

if cmd is not None:
  cmd = int(cmd)
  if -5 <= cmd <= 7:
    if cmd == 0:
      loop = 1
      rfc = rf['FAN']
    elif cmd == 6:
      service_data = {'host':'192.168.2.2', 'packet':'{}'.format(rf['FAN'])}
      hass.services.call('remote', 'send_command', service_data, False)
      time.sleep(0.55)
      loop = 1
      rfc = rf['DOWN']
    elif cmd == 7:
      loop = 1
      rfc = rf['LIGHT']
    else:
      if cmd > 0:
        rfc = rf['DOWN']
      else:
        rfc = rf['UP']
      loop = abs(cmd)

    service_data = {'host':'192.168.2.2', 'packet':'{}'.format(rfc)}
    for i in range(loop):
      hass.services.call('remote', 'send_command', service_data, False)
      time.sleep(0.55)

ERROR: voluptuous.error.MultipleInvalid: extra keys not allowed @ data['host']

As the error says, host is not a valid field for a remote.send_command service call, see the docs here. You are also missing the entity_id of the remote from which the command should be sent in your service data.

I try to send ir command using developer tools - services

entity_id: remote.wifi2rf_kitchen
command: JgBIAAABLJETNxMTFBEUERQRFBEUERU1ExITOBI4ExITEhM3EzcTExI4ExITEhM3EzcTEhMTEjgTEhM3EzcTEhMSEzgSOBMSEwANBQ==

I get error: Failed to send 'JgBIAAABLJETNxMTFBEUERQRFBEUERU1ExITOBI4ExITEhM3EzcTExI4ExITEhM3EzcTEhMTEjgTEhM3EzcTEhMSEzgSOBMSEwANBQ==': 'You need to specify a device'

Yeah, because you’re missing the device that should be controlled, the error message says it right there!

entity_id: remote.wifi2rf_kitchen
device: television
command: "JgBIAAABLJETNxMTFBEUERQRFBEUERU1ExITOBI4ExITEhM3EzcTExI4ExITEhM3EzcTEhMTEjgTEhM3EzcTEhMSEzgSOBMSEwANBQ=="

you need to replace television with the name of the device you want to control.

Where I can find device name:

I try like this:

entity_id: remote.wifi2rf_kitchen
device: hood
command: JgBIAAABLJETNxMTFBEUERQRFBEUERU1ExITOBI4ExITEhM3EzcTExI4ExITEhM3EzcTEhMTEjgTEhM3EzcTEhMSEzgSOBMSEwANBQ==

I get error: Failed to send 'JgBIAAABLJETNxMTFBEUERQRFBEUERU1ExITOBI4ExITEhM3EzcTExI4ExITEhM3EzcTEhMTEjgTEhM3EzcTEhMSEzgSOBMSEwANBQ==': 'Command not found'

I don’t know, maybe under Configuration -> Integrations -> Broadlink

I’m confused, in your initial post you said it’s working with remote.send_command and you just have an issue with the python script, but now it sounds like the service doesn’t work.

I get it to work.

If I first learn command and then execute.

Where in HA I can edit learned commands?

I found location:

Learned codes storage location
The learned codes are stored in the /configuration/.storage folder in a file called broadlink_remote_xxxxxxxxxxx_codes.json. You can open this file with a text editor and copy the codes to set up a custom switch, but beware: the files in the .storage folder should never be edited manually.

Thanks for help @Burningstone :slight_smile:

1 Like