AlexanderBabel / homebridge-broadlink-rm

[This fork supports TV accessories] Broadlink RM Mini and Pro plugin for homebridge: https://github.com/nfarina/homebridge
Apache License 2.0
46 stars 11 forks source link

how to control volume on tv and amps? #40

Closed platini76 closed 4 years ago

platini76 commented 4 years ago

hello, is there a way to control volume on tvs and amps?

my config:

                {
                    "name": "McIntosh",
                    "type": "tv",
                    "data": {
                        "on": "26006801000127921511103A111513371214101512391237143614121337111511391312153514121139143614121436141210151139131412130F16103A1214133712381015123A1200050E000125961213123A12121436151115101437103A103A1115113A121214361313103A1115133712381015113A121314121238141111151115123912121337103A1115113912000511000128921510133710161139111512131239113914370F16113A10151338131214370E16113912391118153515112A1212371213101611141338131213371337101611391300050F000126941115113911151238141214111535153515361412103911151238131412370F16113A103A1213123913121412123810151214131215361213143614361511133710000513000127931511103A1115123813130F16103A133813361412153515111436161014361016113911391314133614120F161139111515111411103A1115113A12381312103A11000D05",
                        "off": "2600B00100012693151116341511143613121214163416341536121313371710163415111237121415351634153513381337151016341610141213121511160F16101437121212381600050C0001279511131634161015351313131215351634153712121238161016341512123712131535163515351337133715111634160F141213121214160F16101437121312381A00050A00012992160F1536131213371511160F163414371337160F16341412123816101634151112381337153516341535131313371511160F16101411131315101634161014361300050F0001299113131337151016341412131215361634163414111338121316341610133713121536163416341437123712141634160F1512121216111213170F1536121313371300050E0001299213131238160F1634151212121238173416341511133715101634151113371313153516341634143712371214163416101511121312131610160F1536121313371500050D000127931313153516101535131213131238163416341412133712131634161015361213133715351634153513381213163416101412121312131610160F15351512123712000D050000000000000000",
                        "volume": {
                            "up": "2600900000012694131312381313113912131313123813371337131312381213133812131337131312131337131313131213131312381213133713131337133713371239121313371300050F000127941213133713131337131312141237133812381213133713131337131312381312131312381313111413131213133713131337131312381238133712381313133713000D050000000000000000",
                            "down": "2600900000012794121313381213123813131213133811391238121312391213123813131238121412381238121312141312131312381313111413131139123812381337131313371300050F000127941213133713131238131312131337133812381213133812131337121411391313123812381213131313121313123813131213131312381238133614381114133713000D050000000000000000"
                        }
                    }
                }
kiwi-cam commented 4 years ago

Could you give more detail on what you're trying to achieve? The config you've shown looks fine and will send the up or down hex codes. These could be for a TV of an Amp.

platini76 commented 4 years ago

IMG_0007 IMG_AF87931EAFBA-1 as you see there are no volume control and when I try to press "visualize tv settings" nothing happens

kiwi-cam commented 4 years ago

This is just Apple's (poor IMO) implementation of the volume controls. It's not obvious. If you open the remote app via Control Centre and select the TV at the top, the volume buttons on your device will send the commands.

platini76 commented 4 years ago

IMG_45795F8CDCAE-1

also here there are not volume buttons

kiwi-cam commented 4 years ago

That's right, you need to use the volume buttons on the side of your phone.

platini76 commented 4 years ago

really!! they works.. so it is a poor apple!!! ahahah last question... is there a way to recognize it as amp or tv is the only way?

kiwi-cam commented 4 years ago

TV is the way to go, for now at least. I've just done some digging and the HAP-NodeJS Project doesn't support the Receiver type yet.

platini76 commented 4 years ago

I found many codes for my amp directly from Mc Intosh, but codes are in hex format like: 0000 006c 0000 0022 0157 00ab 0016 0015 0015 0040 0016 0015 0015 0040 0016 0015 0015 0015 0016 0040 0015 0040 0016 0040 0016 0015 0016 0040 0016 0015 0016 0040 0016 0015 0016 0040 0016 0015 0016 0015 0015 0040 0016 0015 0015 0015 0016 0015 0016 0015 0015 0040 0016 0015 0015 0040 0016 0015 0015 0040 0016 0040 0016 0040 0015 0040 0016 0015 0015 0040 0016 05ee

my right and working rawdata command is: 2600900000012694131312381313113912131313123813371337131312381213133812131337131312131337131313131213131312381213133713131337133713371239121313371300050F000127941213133713131337131312141237133812381213133713131337131312381312131312381313111413131213133713131337131312381238133712381313133713000D050000000000000000

do you know if there is a converter?

kiwi-cam commented 4 years ago

I've been doing some poking around... and fallen down a rabbit hole. Here's a solution for you (assuming you have python installed).

Create file pronto2broadlink.py and insert this into that file:

import binascii
import struct
import base64

def pronto2lirc(pronto):
    codes = [long(binascii.hexlify(pronto[i:i+2]), 16) for i in xrange(0, len(pronto), 2)]

    if codes[0]:
        raise ValueError('Pronto code should start with 0000')
    if len(codes) != 4 + 2 * (codes[2] + codes[3]):
        raise ValueError('Number of pulse widths does not match the preamble')

    frequency = 1 / (codes[1] * 0.241246)
    return [int(round(code / frequency)) for code in codes[4:]]

def lirc2broadlink(pulses):
    array = bytearray()

    for pulse in pulses:
        pulse = pulse * 269 / 8192  # 32.84ms units

        if pulse < 256:
            array += bytearray(struct.pack('>B', pulse))  # big endian (1-byte)
        else:
            array += bytearray([0x00])  # indicate next number is 2-bytes
            array += bytearray(struct.pack('>H', pulse))  # big endian (2-bytes)

    packet = bytearray([0x26, 0x00])  # 0x26 = IR, 0x00 = no repeats
    packet += bytearray(struct.pack('<H', len(array)))  # little endian byte count
    packet += array
    packet += bytearray([0x0d, 0x05])  # IR terminator

    # Add 0s to make ultimate packet size a multiple of 16 for 128-bit AES encryption.
    remainder = (len(packet) + 4) % 16  # rm.send_data() adds 4-byte header (02 00 00 00)
    if remainder:
        packet += bytearray(16 - remainder)

    return packet

if __name__ == '__main__':
    import sys

    for code in sys.argv[1:]:
        pronto = bytearray.fromhex(code)
        pulses = pronto2lirc(pronto)
        packet = lirc2broadlink(pulses)

        print
        print binascii.hexlify(packet)

        print
        print base64.b64encode(packet)

You'll then be able to run python2 pronto2broadlink.py "your prontocode" e.g.

python2 pronto2broadlink.py "0000 006C 0022 0003 00AD 00AD 0016 0041 0016 0016 0016 0041 0016 0041 0016 0016 0016 0041 0016 0016 0016 0016 0016 0041 0016 0016 0016 0041 0016 0041 0016 0016 0016 0041 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0041 0016 0041 0016 0016 0016 0016 0016 0041 0016 0041 0016 0041 0016 0041 0016 0016 0016 0016 0016 0041 0016 0041 0016 06A4 00AD 00AD 0016 0041 0016 0E6C"

26004e00939312371212123712371212123712121212123712121237123712121237121212121212121212121212123712371212121212371237123712371212121212371237120005ae9393123712000c560d050000000000000000

JgBOAJOTEjcSEhI3EjcSEhI3EhISEhI3EhISNxI3EhISNxISEhISEhISEhISEhI3EjcSEhISEjcSNxI3EjcSEhISEjcSNxIABa6TkxI3EgAMVg0FAAAAAAAAAAA=

That's the Broadlink hexcode (Starting with 2600) and the same code base64 encoded.

People also seem to recommend IrScrutinizer from: https://github.com/bengtmartensson/harctoolboxbundle/releases/latest

kiwi-cam commented 4 years ago

Just looking at this again. The example code you've given starts with 0000 so appears to be a pronto code. This platform should detect and convert pronto codes as required. I suspect the code you found online isn't the correct code as it doesn't match the working one you've given either.

platini76 commented 4 years ago

ok I found the right codes... but volume wont have a command on homekit... it is right?

my config:

  {
                    "name": "McIntosh",
                    "type": "tv",
                    "data": {
                        "on": "26006801000127921511103A111513371214101512391237143614121337111511391312153514121139143614121436141210151139131412130F16103A1214133712381015123A1200050E000125961213123A12121436151115101437103A103A1115113A121214361313103A1115133712381015113A121314121238141111151115123912121337103A1115113912000511000128921510133710161139111512131239113914370F16113A10151338131214370E16113912391118153515112A1212371213101611141338131213371337101611391300050F000126941115113911151238141214111535153515361412103911151238131412370F16113A103A1213123913121412123810151214131215361213143614361511133710000513000127931511103A1115123813130F16103A133813361412153515111436161014361016113911391314133614120F161139111515111411103A1115113A12381312103A11000D05",
                        "off": "2600B00100012693151116341511143613121214163416341536121313371710163415111237121415351634153513381337151016341610141213121511160F16101437121212381600050C0001279511131634161015351313131215351634153712121238161016341512123712131535163515351337133715111634160F141213121214160F16101437121312381A00050A00012992160F1536131213371511160F163414371337160F16341412123816101634151112381337153516341535131313371511160F16101411131315101634161014361300050F0001299113131337151016341412131215361634163414111338121316341610133713121536163416341437123712141634160F1512121216111213170F1536121313371300050E0001299213131238160F1634151212121238173416341511133715101634151113371313153516341634143712371214163416101511121312131610160F1536121313371500050D000127931313153516101535131213131238163416341412133712131634161015361213133715351634153513381213163416101412121312131610160F15351512123712000D050000000000000000",
                        "volume": {
                            "up": "2600900000012694131312381313113912131313123813371337131312381213133812131337131312131337131313131213131312381213133713131337133713371239121313371300050F000127941213133713131337131312141237133812381213133713131337131312381312131312381313111413131213133713131337131312381238133712381313133713000D050000000000000000",
                            "down": "2600900000012794121313381213123813131213133811391238121312391213123813131238121412381238121312141312131312381313111413131139123812381337131313371300050F000127941213133713131238131312131337133812381213133812131337121411391313123812381213131313121313123813131213131312381238133614381114133713000D050000000000000000"
                        },
                        "inputs": [
                            {
                                "name": "CD",
                                "type": "other",
                                "data": "2600900000012794121313381213133713131213133812381238121313381213133713131139131312131214121312141238121312141213133812381238123813131238123812381300050F000127941213133812131238131312131337133812381114133812131337121412381214121313131114121412381213131312131338123812381238131311391238133713000D050000000000000000"
                            },
                            {
                                "name": "CD2",
                                "type": "other",
                                "data": "2600900000012694131312381213123912131313123812381337121412381213133812131337131312381213131312131338121313131213131312381139133713131238133713371300050F000127941213123912131337131312131338123812381213123912131337131312381313123812131313121312391114121412131313113912381337131312381337133713000D050000000000000000"
                            },
                            {
                                "name": "DVD",
                                "type": "other",
                                "data": "2600900000012695121312381214123714131213123812391238121313381213133713131238121412381213123813381213121412131313121313371313121411391238123813371300050F000127941313113912131337131312131239123812381313123812131238131312381214113912131338123812131313111413131214123812131313113912381337133713000D050000000000000000"
                            },
                            {
                                "name": "AUX",
                                "type": "other",
                                "data": "26009000000127931313123813131139111412141139123812381313123813131238121313381213123813371338121312381313121313131114121412131239121313371337133812000510000126951213133713131238131311141337133812381213123912131238121411391213123912381238131311391213131312131214121312141337131312381238133713000D050000000000000000"
                            },
                            {
                                "name": "SERVER",
                                "type": "other",
                                "data": "2600900000012694121412381213133812131214123811391337131311391213133812131238121411141338121313371313121313131213133713131337131312381238133713371300050F000127941313123812131337131312141238123812381313123812131337131312381313121313371313123813131213131312131337131312381313123812381238133713000D050000000000000000"
                            }