eslavnov / pylips

Control Philips TVs (2015+) and Ambilight (+ Hue) through their reverse-engineered API (+ MQTT support!)
MIT License
334 stars 58 forks source link

[FEAT] Controll actual RGB color #83

Closed Erehr closed 3 years ago

Erehr commented 3 years ago

I don't really know what I'm doing but I managed to make simple commands like ambilight_on and _off work but have problem with ambilight_color. By reading readme and how some other --body arguments look like I can't get this command to work. python pylips.py --command ambilight_color --body '{"hue": 360, "saturation": 100, "brightness": 255}' getting error: unrecognized arguments: 360, saturation: 100, brightness: 255}'

Anyway the feature I think is missing as I don't think it is in this one above is to set manually RGB color and I mean all 3 channels (R,G,B) separately. In my model (50PUS7303) this can be done by selecting 'Warm White' profile which had small unlocked padlock and 'ISF' icon before it's name. Then in ambilight advanced settings there's ISF tuning with 3 separate color channel sliders.

eslavnov commented 3 years ago

Hi @Erehr,

I've copied & pasted the command you provided and it works well for me. The error you are getting shows that you are missing quotes around your arguments, so probably you copied it wrong.

It also allows to set an individual color, but it uses HSB instead of RGB. You can convert RGB to HSB here and then plug in the values to hue/saturation/brightness arguments in the command above.

So this will set Ambilight to green: python pylips.py --command ambilight_color --body '{"hue": 120, "saturation": 100, "brightness": 255}'

And this will set it to red: python pylips.py --command ambilight_color --body '{"hue": 0, "saturation": 100, "brightness": 255}'

Erehr commented 3 years ago
c:\>cd pylips

c:\pylips>pip install -r requirements.txt
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: pycryptodome>=3.9.4 in c:\users\erehr\appdata\roaming\python\python39\site-packages (from -r requirements.txt (line 1)) (3.9.9)
Requirement already satisfied: requests>=2.20.0 in c:\users\erehr\appdata\roaming\python\python39\site-packages (from -r requirements.txt (line 2)) (2.25.0)
Requirement already satisfied: paho-mqtt>=1.4.0 in c:\users\erehr\appdata\roaming\python\python39\site-packages (from -r requirements.txt (line 3)) (1.5.1)
Requirement already satisfied: certifi>=2017.4.17 in c:\users\erehr\appdata\roaming\python\python39\site-packages (from requests>=2.20.0->-r requirements.txt (line 2)) (2020.12.5)
Requirement already satisfied: chardet<4,>=3.0.2 in c:\users\erehr\appdata\roaming\python\python39\site-packages (from requests>=2.20.0->-r requirements.txt (line 2)) (3.0.4)
Requirement already satisfied: idna<3,>=2.5 in c:\users\erehr\appdata\roaming\python\python39\site-packages (from requests>=2.20.0->-r requirements.txt (line 2)) (2.10)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in c:\users\erehr\appdata\roaming\python\python39\site-packages (from requests>=2.20.0->-r requirements.txt (line 2)) (1.26.2)

c:\pylips>python pylips.py
Checking API version and port...
Trying http://192.168.31.129:1925/6/system
{'notifyChange': 'http', 'menulanguage': 'English', 'name': '50PUS7303/12', 'country': 'Poland', 'serialnumber_encrypted': 'BZZ3N53dFimFJvSkbviUyQbtmZ1xX+D0VFfXuweUBTQ=\n', 'softwareversion_encrypted': 'CK1zTIabONURsMAN99S4O7Mx5w+7HHvTaX9EngYvS5x93xZ2stbhkBXSkYjDQHyu\n', 'model_encrypted': 'zcSB1yratLmBI89BGEdybvh7npGHBxW86V2nPIzmwWA=\n', 'deviceid_encrypted': 'd63JbzjngrJmX9MJDn/59kjbIr2bnqpyMvmv9yNT+tk=\n', 'nettvversion': '8.0.2', 'epgsource': 'one', 'api_version': {'Major': 6, 'Minor': 1, 'Patch': 0}, 'featuring': {'jsonfeatures': {'editfavorites': ['TVChannels', 'SatChannels'], 'recordings': ['List', 'Schedule', 'Manage'], 'ambilight': ['LoungeLight', 'Hue', 'Ambilight'], 'menuitems': ['Setup_Menu'], 'textentry': ['context_based', 'initial_string_available', 'editor_info_available'], 'applications': ['TV_Apps', 'TV_Games', 'TV_Settings'], 'pointer': ['not_available'], 'inputkey': ['key'], 'activities': ['intent'], 'channels': ['preset_string'], 'mappings': ['server_mapping']}, 'systemfeatures': {'tvtype': 'consumer', 'content': ['dmr', 'pvr'], 'tvsearch': 'intent', 'pairing_type': 'digest_auth_pairing', 'secured_transport': 'true', 'companion_screen': 'true'}}, 'os_type': 'MSAF_2018_O'}
No valid credentials found, starting pairing process...
Sending pairing request
{'scope': ['read', 'write', 'control'], 'device': {'device_name': 'heliotrope', 'device_os': 'Android', 'app_name': 'Pylips', 'type': 'native', 'app_id': 'app.id', 'id': 'm9iQ89wg9oFN4nLM'}}
https://192.168.31.129:1926/6/pair/request
Enter onscreen passcode: 6189
Attempting to pair
{'User-Agent': 'python-requests/2.25.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive', 'Content-Length': '302', 'Content-Type': 'application/json', 'Authorization': 'Digest username="m9iQ89wg9oFN4nLM", realm="XTV", nonce="MTYwNzcyMjU5MzI4MToxMDgyNTYzYWE3OWY5Y2JkYmJhZjg3YzU3MWQ3YzYyNw==", uri="/6/pair/grant", response="06bce1f0fb5075581f86d4cc92a7bf65", algorithm="MD5", qop="auth", nc=00000001, cnonce="a6eba80fd22bcd69"'}
b'{"auth": {"auth_AppId": "1", "pin": "6189", "auth_timestamp": 324757, "auth_signature": "b\'ZTBlMDBiMWY5MGIxMDg3ZTVjYzA2MDhkYjc4MzRmMzlkYWIxOWQ3ZQ==\'"}, "device": {"device_name": "heliotrope", "device_os": "Android", "app_name": "Pylips", "type": "native", "app_id": "app.id", "id": "m9iQ89wg9oFN4nLM"}}'
Username for subsequent calls is: m9iQ89wg9oFN4nLM
Password for subsequent calls is: 703baea60087230ab79589c03963c48817186f8746001cd68ccfe39023199303
The credentials are saved in the settings.ini file.
Please enable mqtt_listen in settings.ini or provide a valid command with a '--command' argument

c:\pylips>python pylips.py --command ambilight_color --body '{"hue": 0, "saturation": 100, "brightness": 255}'
usage: pylips.py [-h] [--host HOST] [--user USER] [--pass PASSWORD] [--command COMMAND] [--path PATH] [--body BODY]
                 [--verbose VERBOSE] [--apiv APIV] [--config CONFIG]
pylips.py: error: unrecognized arguments: 0, saturation: 100, brightness: 255}'

c:\pylips>python pylips.py --command ambilight_off
Sending POST request to https://192.168.31.129:1926/6/ambilight/power
Request sent!
{"response": "OK"}

c:\pylips>python pylips.py --command ambilight_on
Sending POST request to https://192.168.31.129:1926/6/ambilight/power
Request sent!
{"response": "OK"}

Still the same, even with fresh download and pasting your own command directly. Other simple commands works but none using --body.

eslavnov commented 3 years ago

Since you are using Windows you need to escape the quotes in your command. Here is an example from Readme for a different command, notice the '^' symbols:

python3 pylips.py --host %TV's_ip_address% --user %username% --pass %password% --command post --path menuitems/settings/current --body ^"{^"^"nodes^"^":[{^"^"nodeid^"^":2131230774}]}^"