bezmi / homeassistant_jvc_projector_remote

Custom components for homeassistant
Apache License 2.0
14 stars 11 forks source link

Issue with JVC X35 #11

Closed Shogun1978 closed 1 year ago

Shogun1978 commented 1 year ago

I tried to get the integration work with my X35. The state (standby) is shown, but I can't power on the projector. The command is send out, I don't get an error returned. I haven't set a password, this is not an option by the projector.

Any ideas, what I'm doing wrong?

bezmi commented 1 year ago

It could be that the command format is different. The best way to test this is run the python library directly on a computer and see if the projector responds. This will allow you to isolate the problem. See the readme here for instructions on how to do this.

If that's doesn't work then we'll have to add the commands for your model. Otherwise, it's a problem with this homeassistant component.

Shogun1978 commented 1 year ago

I am not that familiar with python, so I have no idea how to test this. How do I use the code in"Here is an example for using this module standalone:"? Create a .py file and making it executable didn't work. I've installed the jvc_projector_remote with pip, that worked well. But I have no idea how to use the code.

bezmi commented 1 year ago

Okay so if you've managed to install python and the jvcprojector package, all you need to do is open "IDLE" the python interpreter and type each of the lines that have a >>> into that and hit enter (leave out the >>> and any lines that start with #. If you're on mac or linux, you might not have IDLE. In that case, open a terminal and type python to launch the interpreter.

For example if you type print("hello world") it would look like:

>>> print("hello world")
hello world
>>>

For your projector, you wont need the line that sets the password and use the initialisation line which just has host not host, password

Shogun1978 commented 1 year ago

Thanks! I could issue the commands, but don't responses except "False". The initialization worked with the host only method. The only command that works flawless is "projector.is_on()". When I manually switch on the projector, I get a "True". If (like now) it's in standby, I get a "False" in response. So the communication itself works, but somehow he seems to have issues with the hex-codes. I tried the "older ones" that you referenced. No matter, what command I issue, it's a "False" in response. In my projector manual there is no password named nor can I set a password in the on-screen UI.

Do you have any ideas, what could be the problem?

EDIT: maybe the handshake didn't work? "Before controlling via LAN, it is necessary to estabilsh connection of the TCP layer by a "3-way-handshake" (JVC x35 projector manual page 72).

bezmi commented 1 year ago

The handshake is done every time a command is sent, so if it is able to respond with the is_on() command, then the handshake step is working. It's possible that the commands are different for your model. I will have to see if I can dig up a manual for this one.

Shogun1978 commented 1 year ago

I have already found the manual, but the codes should be the same. On oage 73 there is the description for the command. But it looks identical to the ones you use here in this integration.

jvcdla-x95_x75_x55_x35-an-en (1).pdf .

bezmi commented 1 year ago

Okay, yeah the commands should be the same. You've probably already done this, but there is a list of hex commands and their names in the __init__.py file in the python module github. A few commands to try:

>>> from jvc_projector import JVCProjector, Commands, ACKs
# follow the setup steps woth IP, etc

>>> projector._send_command(Commands.power_status.value)
# return a hex code which corresponds to the power status

>>> projector.power_state()
# return the power state

>>> projector._send_command(Commands.current_output.value)
# return a hex code with the currently hdmi input (yes my naming of the command is wack)

>>> projector._send_command(Commands.menu.value)
# pop up the menu

# I know the built in power on command didn't work but you can try:
>>> projector._send_command(Commands.power_on.value)

# try with the ACK
>>> projector._send_command(Commands.power_on.value, ACKs.power_ack.value)

Apologies for rehashing this if you've already tried it. If it doesnt work, I'll do some testing in the morning and try to get a debugging release of the python module for you with lots of print statements so we can pinpoint where it's breaking down.

P.s. the password stuff is only for the newest models so shouldnt present any problems for us.

bezmi commented 1 year ago

Whoops, i forgot that projector.command only returns True or False. I'll edit the previous comment with the correct syntax.

Shogun1978 commented 1 year ago
>>> from jvc_projector import JVCProjector, Commands, ACKs
# follow the setup steps woth IP, etc

>>> projector._send_command(Commands.power_status.value)
# return a hex code which corresponds to the power status

>>> projector.power_state()
# return the power state

>>> projector._send_command(Commands.current_output.value)
# return a hex code with the currently hdmi input (yes my naming of the command is wack)

>>> projector._send_command(Commands.menu.value)
# pop up the menu

# I know the built in power on command didn't work but you can try:
>>> projector._send_command(Commands.power_on.value)

# try with the ACK
>>> projector._send_command(Commands.power_on.value, ACKs.power_ack.value)

Ok, so we got one step further.

>>> projector.power_state()
'standby'

>>> projector._send_command(Commands.power_on.value, ACKs.power_ack.value)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/jvc_projector/__init__.py", line 165, in _send_command
    message = jvc_sock.recv(1024)
socket.error: [Errno 104] Connection reset by peer

But at least, the projector turned on! Any other command from your list returns a "false". Finally I tried something not from the list ;-)

>>> projector._send_command(Commands.power_off.value, ACKs.power_ack.value)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/jvc_projector/__init__.py", line 165, in _send_command
    message = jvc_sock.recv(1024)
socket.error: [Errno 104] Connection reset by peer

And the projector switched off :-) The time till I get the response at power on and power off was maybe 10-20 seconds. Then I got the traceback message.

Does this help a little bit?

bezmi commented 1 year ago

Is it responding to the power on and off commands straight away, but just takes 10-20 seconds for the error to show up? If this is true then it should be working with the _send_command without the ACK included as well since the error is something weird going on with the ACK.

False is just the default value of the _send_command function so it should still do something for the menu command.

I'm not actually at home and so haven't tested all of the commands I wrote in my previous message. Now that I think about it, an ACK is required to receive a message back from the projector and not just False. For power status and input the commands should actually be:

>>> projector._send_command(Commands.power_status.value, ACKs.power_ack.value)
>>> projector._send_command(Commands.current_output.value, ACKs.input_ack.value)

Also, you can just hit ctrl+c to abort code execution if you're tired of waiting for it to error out (and you already know what the error will be).

Try these and let me know how it goes. We're getting somewhere.

Shogun1978 commented 1 year ago

Without the "ACKs.***.value" it seems not to work.

>>> projector._send_command(Commands.power_status.value, ACKs.power_ack.value)
'@\x89\x01PW0\n'
>>> projector._send_command(Commands.current_output.value, ACKs.input_ack.value)
^CTraceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/jvc_projector/__init__.py", line 162, in _send_command
    ACK = jvc_sock.recv(len(ack))
KeyboardInterrupt
>>> projector._send_command(Commands.power_status.value)
False

At the "current_output" command the projector was off. So I this is the reason for the error.

bezmi commented 1 year ago

Okay a few more suggestions before I turn in for the night. Firstly, you're running python 2.7. It's way out of date and you need to be running python 3.8, 3.9 or 3.10. Please install the latest version from here if you're on windows. On Mac or Linux, doing python3 from the terminal should bring up the correct one as it should be installed by default this is very important as the code is written for python 3.

Next, try the commands from your latest message above with the power turned on to begin with. You don't need the 3rd one as sending an information request command like power_status without an ACK will always return False (ACK is required to retrieve the projector's response). Sending commands without an ACK can be used for the "operations" like power on, off, input change etc where our eyes will tell us whether the command worked or not and we dont care about the projector's response.

Also, just confirming that the menu command fails to bring up the menu on screen when the projector is on? It will return False but should still work.

In the morning I'll write up a debug script that you should be able to run that will definitely help get to the bottom of this.

Edit: you'll need to reinstall the jvc_projector python module after installing python3. If you get a module not found error, try pip3 install ... instead of pip install ...

Shogun1978 commented 1 year ago

The behaviour didn't change. I used not Python 3.10.5 on my laptop (previously I was running the commands from a virtual Ubuntu maschine).

>>> projector._send_command(Commands.current_output.value, ACKs.input_ack.value)
b'@\x89\x01IP6\n'
>>> projector._send_command(Commands.power_status.value, ACKs.power_ack.value)
b'@\x89\x01PW1\n'
>>> projector._send_command(Commands.power_off.value, ACKs.power_ack.value)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\haral\AppData\Local\Programs\Python\Python310\lib\site-packages\jvc_projector\__init__.py", line 165, in _send_command
    message = jvc_sock.recv(1024)
ConnectionResetError: [WinError 10054] Eine vorhandene Verbindung wurde vom Remotehost geschlossen

That's the result from the output request. So not much changed, but at least there is some communication :-)

Shogun1978 commented 1 year ago

Did you get a chance to take a look?

bezmi commented 1 year ago

When initialising the projector, try doing this instead of the standard:

projector = JVCProjector(host, delay_ms=700)

Try with multiple higher values of delay_ms until it (hopefully) works. The default is 600. Other than that, i am working on a little more robust version of the library that might fix your issues. Without hands on access to that particular model, debugging is extremely difficult.

bezmi commented 1 year ago

hi, please try the latest alpha version of the homeassistant component and let me know if it has sorted out any of the issues you were having. See the community post here.

Shogun1978 commented 1 year ago

Sorry for the late reply. I just had now the chance to test it, unfortunately no change. Still no commands work (Remote On/Off).

EDIT: Correcting myself. It works! I tested with the latest beta on a fresh install of Home Assistant (seems like something went wrong on my production system). So I can switch on and off the projector, getting some basic information (lamp state, input etc.). I will continue to test if everything runs well. Thank you for your support!

bezmi commented 1 year ago

Closing this, looks like problems are gone based on the last comment and edit!