samsinnamon / airtouch4pyapi

An api allowing control of AC state (temperature, on/off, mode) of an Airtouch 4 controller locally over TCP
MIT License
27 stars 14 forks source link

Can't contact AT5 system? #18

Closed majurgens closed 1 year ago

majurgens commented 1 year ago

I might be doing something wrong but I'll go through what I am doing and what is happening. I finally got an operational AT5 system, hence why I am trying now.

The AT5 is on my network. I know the IP, I can see the port 9005 is open and listening. I have run all the AT5 system updates. I modified line 18 of the demo.py file to at = AirTouch(ip,AirTouchVersion.AIRTOUCH5) (as per the readme file)

I run the script python demo.py at5

The script eventually times out. I ran a packet capture and I see the script trying to talk to the AT5 unit IP address but on port 0 (zero) not port 9005.

Interestingly, if I revert the demo.py change above (so presumably it will default to AT4), the following happens: The script correctly reports the summary system information and then asks me if I want to perform operations. If I say "y" to any of them then I get python errors like:

Traceback (most recent call last):
  File "/opt/hvac/airtouch4pyapi/demo.py", line 92, in <module>
    asyncio.run(updateInfoAndDisplay(sys.argv[1]))
  File "/usr/lib64/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/lib64/python3.10/asyncio/base_events.py", line 646, in run_until_complete
    return future.result()
  File "/opt/hvac/airtouch4pyapi/demo.py", line 36, in updateInfoAndDisplay
    await at.TurnGroupOffByName(group.GroupName)
  File "/opt/hvac/airtouch4pyapi/airtouch4pyapi/airtouch.py", line 184, in TurnGroupOffByName
    await self.TurnGroupOff(targetGroup.GroupNumber);
  File "/opt/hvac/airtouch4pyapi/airtouch4pyapi/airtouch.py", line 226, in TurnGroupOff
    await self.SendMessageToAirtouch(controlMessage)
  File "/opt/hvac/airtouch4pyapi/airtouch4pyapi/airtouch.py", line 368, in SendMessageToAirtouch
    MESSAGE = communicate.MessageObjectToMessagePacket(messageObject, messageObject.MessageType, self.atVersion);
  File "/opt/hvac/airtouch4pyapi/airtouch4pyapi/communicate.py", line 21, in MessageObjectToMessagePacket
    binaryMessagePayloadString = AddMapValueToBinaryValue(binaryMessagePayloadString, groupControlPacketLocationMap[attribute], messageObject.MessageValues[attribute])
KeyError: 'HaveTemperatureControl'

In the packet capture I see that the script tries on port 9004 but gets reset and then tries on port 9005. Does the script know to try the AT5 port - this seems to be the logic in the findVersion() function operating. When the script tries on the port 9005 a network dialogue happens (hence you see above that the status info is collected). So if the version is automatically detected and the status can be read then why do the operations not actually work?

Also, why does the readme say that you have to initialise like airTouch = AirTouch("192.168.1.1", AirTouchVersion.AIRTOUCH5)? This seems to be at least partly handled by the findVersion() function

cemilbrowne commented 1 year ago

This is a great edge case find, @majurgens . The intention when I modified was that you'd EITHER let it automatically find OR specify version + port.

at = AirTouch(ip, AirTouchVersion.AIRTOUCH5, 9005)

Works.

If you look at 83-100 of airtouch.py, you skip all three tests. first one is if the port is specified, but no version - error. Second one is if version isn't specified, auto detect. Third one, if the version is still not there, print error, that one gets skipped too, because you've specified version. So the first error point is when you try to send the 'give me groups' error.

At the very least, the README should reflect this information. Thanks for finding.

cemilbrowne commented 1 year ago

@majurgens - as a side note, I got an email notification that you asked about AC mode, but can't find the comment. Did you delete because you found it? If not, try this: print(f"AC Name: {ac.AcName:15s} AC Number: {ac.AcNumber:3d} IsOn: {ac.IsOn} PowerState: {ac.PowerState:3s} Target: {ac.AcTargetSetpoint:3.1f} Temp: {ac.Temperature:3.1f} Mode: {ac.AcMode} Modes Supported: {ac.ModeSupported} Fans Supported: {ac.FanSpeedSupported} startGroup: {ac.StartGroupNumber: 2d} GroupCount: {ac.GroupCount:2d} Spill: {ac.Spill}") at line 15 of demo.py

Note specifically:

Mode: {ac.AcMode}

majurgens commented 1 year ago

@majurgens - as a side note, I got an email notification that you asked about AC mode, but can't find the comment. Did you delete because you found it? If not, try this: print(f"AC Name: {ac.AcName:15s} AC Number: {ac.AcNumber:3d} IsOn: {ac.IsOn} PowerState: {ac.PowerState:3s} Target: {ac.AcTargetSetpoint:3.1f} Temp: {ac.Temperature:3.1f} Mode: {ac.AcMode} Modes Supported: {ac.ModeSupported} Fans Supported: {ac.FanSpeedSupported} startGroup: {ac.StartGroupNumber: 2d} GroupCount: {ac.GroupCount:2d} Spill: {ac.Spill}") at line 15 of demo.py

Note specifically:

Mode: {ac.AcMode}

Ignore. I deleted since after trawling through the code a bit more (I am not a python expert), I found AcMode, like you suggested

majurgens commented 1 year ago

at = AirTouch(ip, AirTouchVersion.AIRTOUCH5, 9005)

This seems to work the same as auto-discovery. I still can't control the AT5 system

cemilbrowne commented 1 year ago

@majurgens odd - so you're not working at all... Out of curiosity, is your AT5 on a separate VLAN or anything?

majurgens commented 1 year ago

Both the python client and the AT5 system are on the same /24 subnet. Additionally, in the packet capture I can clearly see that the MAC addresses in the TCP flows are the client and the AT5 so no router is involved

cemilbrowne commented 1 year ago

The key error seems to me like it's version related, which is strange. Do you also have an AT4?

Can you add a bit of debugging gunk into async def UpdateInfo(self): and let's see what version you're getting? by line 101, self.atPort and self.atVersion should be defined?

majurgens commented 1 year ago

Debug output Collected Version Info: Port=9005, Version=AirTouchVersion.AIRTOUCH5

I only have an AT5

cemilbrowne commented 1 year ago

Can you also log at line 72 in communicate.py async def SendMessagePacketToAirtouch(messageString, ipAddress, atVersion, atPort): let's log the attributes there too?

majurgens commented 1 year ago
Collected Version Info (communicate.py): Port=9005, Version=AirTouchVersion.AIRTOUCH5
Collected Version Info (communicate.py): Port=9005, Version=AirTouchVersion.AIRTOUCH5
Collected Version Info (communicate.py): Port=9005, Version=AirTouchVersion.AIRTOUCH5
Collected Version Info (communicate.py): Port=9005, Version=AirTouchVersion.AIRTOUCH5
cemilbrowne commented 1 year ago

really strange then that you're seeing comms over port 0. Really strange. Is that the heart of the problem, you think?

majurgens commented 1 year ago

FYI: My Airtouch console software version is 1.03 and the Main Module version is 2.0.0.2 with a hardware version 2.3.0.E

majurgens commented 1 year ago

really strange then that you're seeing comms over port 0. Really strange. Is that the heart of the problem, you think?

This only occurs if I at = AirTouch(ip,AirTouchVersion.AIRTOUCH5) (as per the readme file)

I get the python errors when I leave it to auto-detect - but also remember the status collection works ok just the set operations fail

mrvautin commented 1 year ago

FYI:

My Airtouch console software version is 1.03 and the Main Module version is 2.0.0.2 with a hardware version 2.3.0.E

This doesn't help much but these are the same versions my unit is running which is working ok with the code.

majurgens commented 1 year ago

Is there something I need to configure on my console perhaps to allow set operations?

cemilbrowne commented 1 year ago

Not that I'm aware of. I don't think this is a comms issue. The python error up the top is just strange given that you're ATv5. Do you have temp sensors on all your zones?

cemilbrowne commented 1 year ago

Actually, are you positive you have the latest version of the code? In your traceback: File "/opt/hvac/airtouch4pyapi/airtouch4pyapi/airtouch.py", line 368, in SendMessageToAirtouch MESSAGE = communicate.MessageObjectToMessagePacket(messageObject, messageObject.MessageType, self.atVersion); That's not on line 368 for me. That's 374. Same here github link

I'm guessing you have an older version of code?

majurgens commented 1 year ago

I'm guessing you have an older version of code?

It is. I must have updated after the initial AT5 support and then not since later patches.

It now all works

The line numbers might have been out also because I am adding some other changes (to allow JSON output). When I submit that PR I will also fix up the readme

Closing this issue