jasonacox / tinytuya

Python API for Tuya WiFi smart devices using a direct local area network (LAN) connection or the cloud (TuyaCloud API).
MIT License
867 stars 157 forks source link

Aubess WiFi IR Controller S16 - cannot control SONY TV set #492

Open bgolab opened 1 month ago

bgolab commented 1 month ago

Hi, I wonder if you could help me out. The device model S16 is based on Tuya CBU BK7231.

What I did so far but the SONY TV cannot be controlled.

sony_pwr = { "control": "send_ir", "head": "", "key1": "002$000CA900)", "type": 0, "delay": 300, }

payload = d.generate_payload(tinytuya.CONTROL, {"201": json.dumps(sony_pwr)})

d.send(payload)

I would be grateful for any hint what else I could try.

bgolab commented 1 month ago

teardown

uzlonewolf commented 1 month ago

Have you tried using the IRRemoteControlDevice in Contrib? https://github.com/jasonacox/tinytuya/blob/master/examples/Contrib/IRRemoteControlDevice-example.py

head = '010fbb00000000000f001900320064032c0313044c041a03450433046502fa0401035e02e1047e'
key1 = '002$000CA900'
ir.send_key( head, key1 )
bgolab commented 1 month ago

Tried this without success

import sys
import tinytuya
from tinytuya import Contrib
from time import sleep

tinytuya.set_debug(True)

# SONY Tuya Device Debug Log: IR send{"control":"send_ir","head":"010fbb00000000000f001900320064032c0313044c041a03450433046502fa0401035e02e1047e","key1":"002$000CA900)","type":0,"delay":300}
head = '010fbb00000000000f001900320064032c0313044c041a03450433046502fa0401035e02e1047e'
key1 = '002$000CA900)'

ir = Contrib.IRRemoteControlDevice( 'bf778fxxxx', '192.168.1.61', 'x;Df9FZxxx', persist=True )
ir.send_key( head, key1 )
uzlonewolf commented 1 month ago

Actually, remove a leading zero from key1 and try it again (so, key1 = '02$000CA900'). Depending on what DPS set the device uses the key1 from the debug logs could have an extra 0.

bgolab commented 1 month ago

Yes, this works. Thank you.

Maybe you can share more tips about how to use the Contrib library in the real world - like the latest one (i.e. "remove the leading zero"). I know it may require some detailed knowledge about the difference between what we see in the Device Log and the way the data is encoded in the packet. Also the DP ID is kind of interesting topics (I have noticed that it is discovered somehow within the lib).

I also noticed this lib has some 'learning' capabilities - it kind of brute force approach but it looks like it might be very useful when you have the real Remote available. Thank you again. The working script is attached below..

import sys
import tinytuya
from tinytuya import Contrib
from time import sleep

# SONY Tuya Device Debug Log: IR send{"control":"send_ir","head":"010fbb00000000000f001900320064032c0313044c041a03450433046502fa0401035e02e1047e","key1":"002$000CA900)","type":0,"delay":300}
head = '010fbb00000000000f001900320064032c0313044c041a03450433046502fa0401035e02e1047e'
key1 = '02$000CA900)'  # leading zero removed

ir = Contrib.IRRemoteControlDevice( 'bf778f99xxxxx', '192.168.1.61', 'x;Dfxxx', persist=True )
ir.send_key( head, key1 )
jasonacox commented 1 month ago

Maybe you can share more tips about how to use the Contrib library in the real world

Fair point. I'll capture that.