python-broadlink icon indicating copy to clipboard operation
python-broadlink copied to clipboard

How do you save the command (e.g., ir_packet) for use in a script?

Open pruppert opened this issue 8 years ago • 8 comments

Could you flesh out the readme a little more describe how to later use the learned command? Do you have to write/read from a file or something? Could you provide some example? Thanks.

pruppert avatar Nov 19 '16 05:11 pruppert

The examples posted here work fine (both ir and rf)

keptenkurk avatar Nov 19 '16 09:11 keptenkurk

Thanks. I'll try that.

rupino avatar Nov 19 '16 14:11 rupino

Oops posted from different account. Thanks. I will try.

pruppert avatar Nov 19 '16 14:11 pruppert

Is it possible to load config from the "share to other phones in WLAN" from broadlink's E-control app? It will made setup much easier.

illxi avatar Nov 20 '16 03:11 illxi

Another approach is to dump the packet to YAML:

import broadlink
from IPython import embed
import time
import yaml


devices = broadlink.discover(timeout=5)
device = devices[0]
device.auth()
device.enter_learning()

packet = None

print("Learning", end="", flush=True)
while packet is None:
    print(".", end="", flush=True)
    time.sleep(5)
    packet = device.check_data()
print()

print(yaml.dump(packet))

I'm taking that snippet, and putting into a YAML like:

christmas_lights:
  on: !!binary |
    sgD8AAYSEgYGEgYTBRMRBwUTEQcFEwUTBhISBxEGEgcFExEHBRMFEwUTBRMGEgYSEgYSBwW7BhIS
    BgYTBRMFExEHBRMRBwUTBhIGEhIHEQcRBwUTEQcGEgYSBhIGEgYSBhMRBxEHBbsGEhIGBhMFEwUT
    EQcFExIGBRMGEwUTEQYSBxEHBRMRBwUTBRMGEgYSBhIGExEHEQcFuwYTEQcFEwUTBRMRBwUTEQcG
    EgUTBhISBxEHEQcFExEHBRMFEwYSBRMGEgYTEQcRBwW7BhISBwUTBRMFExEHBRMRBwUTBRMFExIG
    EgcRBwUTEQcFEwUTBRMFEwUTBRMGEgYTBQAF3AAAAAAAAAAAAAAAAA==
  off: !!binary |
    sggyAAcTEgcGEwYTBhMSBwYTEgcGEwYTBhMSBxIHEgcHExIHBhMGEwYTBhMSBxMHBhMGEwa8AAAA
    AAAA

And then sending like:

import broadlink
import yaml
with open('codes.yaml', 'r') as file:
    data = yaml.load(file)
packet = data['christmas_lights'][True]  # YAML treats on as True
devices = broadlink.discover(timeout=5)
device = devices[0]
device.auth()
device.send_data(packet)

technicalpickles avatar Dec 05 '16 15:12 technicalpickles

Hi there. This looks like an excellent integration. I've just placed an order for the RM2 but I can't work out how to install the library for use in Python. I have cloned the folders and run the setup but i get no module error when trying to import Broadlink Can anyone help me please - apologies if I'm being dumb :-)

upstairs-at-erics avatar Jan 06 '17 10:01 upstairs-at-erics

@keptenkurk

The examples posted here work fine (both ir and rf)

From the link it looks as tho it only works for IR. How does it need to be modified to work with RF?

And can the HEX codes that are read into the text file be used in other applications?

I've been trying to figure out the codes including protocol, pulse length etc for use in a MQTT gateway using RCSwitch. But RCSwitch doesn't read my remote but the RM Pro has.

finity69x2 avatar Feb 03 '18 05:02 finity69x2

Another approach is to dump the packet to YAML:

import broadlink
from IPython import embed
import time
import yaml


devices = broadlink.discover(timeout=5)
device = devices[0]
device.auth()
device.enter_learning()

packet = None

print("Learning", end="", flush=True)
while packet is None:
    print(".", end="", flush=True)
    time.sleep(5)
    packet = device.check_data()
print()

print(yaml.dump(packet))

I'm taking that snippet, and putting into a YAML like:

christmas_lights:
  on: !!binary |
    sgD8AAYSEgYGEgYTBRMRBwUTEQcFEwUTBhISBxEGEgcFExEHBRMFEwUTBRMGEgYSEgYSBwW7BhIS
    BgYTBRMFExEHBRMRBwUTBhIGEhIHEQcRBwUTEQcGEgYSBhIGEgYSBhMRBxEHBbsGEhIGBhMFEwUT
    EQcFExIGBRMGEwUTEQYSBxEHBRMRBwUTBRMGEgYSBhIGExEHEQcFuwYTEQcFEwUTBRMRBwUTEQcG
    EgUTBhISBxEHEQcFExEHBRMFEwYSBRMGEgYTEQcRBwW7BhISBwUTBRMFExEHBRMRBwUTBRMFExIG
    EgcRBwUTEQcFEwUTBRMFEwUTBRMGEgYTBQAF3AAAAAAAAAAAAAAAAA==
  off: !!binary |
    sggyAAcTEgcGEwYTBhMSBwYTEgcGEwYTBhMSBxIHEgcHExIHBhMGEwYTBhMSBxMHBhMGEwa8AAAA
    AAAA

And then sending like:

import broadlink
import yaml
with open('codes.yaml', 'r') as file:
    data = yaml.load(file)
packet = data['christmas_lights'][True]  # YAML treats on as True
devices = broadlink.discover(timeout=5)
device = devices[0]
device.auth()
device.send_data(packet)

Nice answer. We should use YAML in the CLI imo.

felipediel avatar Oct 18 '21 18:10 felipediel