AQL-PS-8 Remote Emulator App

I am not sure the HA software supports the P4. The key code format is different for the P4.
There's a couple of people with P4's that have changed the code to support it. I just copied what they did. This seems to be the change.

# MOD BEGIN
# self._append_data(frame, self.FRAME_TYPE_LOCAL_WIRED_KEY_EVENT)
self._append_data(frame, self.FRAME_TYPE_REMOTE_WIRED_KEY_EVENT)
self._append_data(frame, key.value.to_bytes(2, byteorder='little'))
self._append_data(frame, b'\x00')
self._append_data(frame, b'\x00')
self._append_data(frame, key.value.to_bytes(2, byteorder='little'))
self._append_data(frame, b'\x00')
self._append_data(frame, b'\x00')
# MOD END
 
  • Like
Reactions: mas985
Are they saying this code actually works:


Code:
        frame = bytearray()
        frame.append(self.FRAME_DLE)
        frame.append(self.FRAME_STX)

        if key.value > 0xffff:
            self._append_data(frame, self.FRAME_TYPE_WIRELESS_KEY_EVENT)
            self._append_data(frame, b'\x01')
            self._append_data(frame, key.value.to_bytes(4, byteorder='little'))
            self._append_data(frame, key.value.to_bytes(4, byteorder='little'))
            self._append_data(frame, b'\x00')
        else:
# MOD BEGIN
            # self._append_data(frame, self.FRAME_TYPE_LOCAL_WIRED_KEY_EVENT)
            self._append_data(frame, self.FRAME_TYPE_REMOTE_WIRED_KEY_EVENT)
            self._append_data(frame, key.value.to_bytes(2, byteorder='little'))
            self._append_data(frame, b'\x00')
            self._append_data(frame, b'\x00')
            self._append_data(frame, key.value.to_bytes(2, byteorder='little'))
            self._append_data(frame, b'\x00')
            self._append_data(frame, b'\x00')
# MOD END

My P4 code converted to python would look like this:
Code:
        frame = bytearray()
        frame.append(self.FRAME_DLE)
        frame.append(self.FRAME_STX)
        self._append_data(frame, b'\x00')
        self._append_data(frame, self.FRAME_TYPE_LOCAL_WIRED_KEY_EVENT)

        if key.value > 0xffff:
            self._append_data(frame, key.value.to_bytes(4, byteorder='little'))
            self._append_data(frame, key.value.to_bytes(4, byteorder='little'))
        else:
            self._append_data(frame, key.value.to_bytes(2, byteorder='little'))
            self._append_data(frame, key.value.to_bytes(2, byteorder='little'))

I think I know why their key presses did not work. I strip out the keep alive packets and do not send them back to the application and they use that to send the packets same as what the EW11 script does.

There may be an issue with the frame generation. I am surprised that works because when @elizb captured the packets directly from the P4, the captured packets are different from what they are using.

Trying to time from an HA wirelessly is going to be very difficult due to latency. That is why I am using the script in the EW11 because it puts the processing close to the controller with minimal latency.

If you want to try my mods with the EW11 script (more adjustments might be needed):
 

Attachments

  • EW11 Script v006 HA Mod.txt
    1.1 KB · Views: 2
  • core MOD v001.py.txt
    24.8 KB · Views: 5
Last edited:
Thanks for the code. I was just coming here to say I did get it to work.

I had to comment out the 2 extra "self._append_data(frame, b'\x00')" and use the LOACL instead of the REMOTE. I also commented out where the code looks for the keep alive frame type. I just send the frame now and let your script handle it from there. I hadn't commented out the Requeue logic, but that's probably a good thing to do.

The code base I'm working from looks like it's passed through too many hands. Each with a small change that may or may not be good I'll probably go back to the original and then apply my changes. There's a few things that need to be added to the original (not related to the key presses).

Thanks for the help and for the script. That was the key to being able to use wireless. You're right, there's just to much latency for wireless to be reliable. Do you mind if I share your script with other HA users (with credit of course)?
 
  • Like
Reactions: mas985
Thanks for the help and for the script. That was the key to being able to use wireless. You're right, there's just to much latency for wireless to be reliable. Do you mind if I share your script with other HA users (with credit of course)?
I actually did some time ago but it has changed a bit since then so feel free to share it.
 
  • Like
Reactions: j4ydubs
WOW! Finally got this to work. Thanks!
Windows version/EW11 Script v006 HA MOD/P4 Mode checked. I also changed buffers from 512 to 1024 but I don't know if that makes a difference.
I already have the Aqualogic Custom Component in Home Assistant but it's not very reliable and I've been unable to send commands successfully. What do I need to do to use this project in Home Assistant? Remove the Custom Component? Add the .py files (which ones for P4?) to my HA config folder, or elsewhere? Thanks again.
 
WOW! Finally got this to work. Thanks!
Windows version/EW11 Script v006 HA MOD/P4 Mode checked. I also changed buffers from 512 to 1024 but I don't know if that makes a difference.
I already have the Aqualogic Custom Component in Home Assistant but it's not very reliable and I've been unable to send commands successfully. What do I need to do to use this project in Home Assistant? Remove the Custom Component? Add the .py files (which ones for P4?) to my HA config folder, or elsewhere? Thanks again.
That script is for Home Assistant although it will work fine for the app it just generates a lot more traffic on WiFi than necessary. The original script works fine for P4 Mode on the app and it suppresses the keep alives that are not needed for app. If you are just using the app, you want the script EW11 Script v006.txt.

This folder contains the code for the Home Assistant:


There are now two code versions (P4 & PS8) that no longer rely on Keep Alive packets so the original script can be used with Home Assistant. I have no way of finding out if these work so if someone is willing...
 
Last edited:
Thanks for getting back to me so quickly, Mark. I'm sorry if I'm a little dense, long day. Just to be clear, which script file do you recommend loading to the EW11, and which core file do you recommend - and where do I put it? In the config folder? Delete the Aqualogic Custom Component folder?
 
You can NOW use the attached script for either the (iOS/Android/Win) APP or Home Assistant.

If you are using Home Assistant, you copy the core.py file from the folder depending on which controller you have P4 or PS8 to where the core.py file resides and overwrite the old version. I haven't done this myself so I am not sure where to do that but it is in the AquaLogic folder somewhere on the Home Assistant server.

 

Attachments

  • EW11 Script v006.txt
    1.1 KB · Views: 3

Attachments

  • EW11 Script v006.txt
    1.1 KB · Views: 1
  • Like
Reactions: mas985

Enjoying this content?

Support TFP with a donation.

Give Support
Registered to say the above for HomeAssistant worked for me too! Have been using it the past 2 days with my PS8 and it works great to control my lights and pumps, however my EW11 seems to lose connection to HomeAssistant after a couple hours (Log shows Socket Timeout) and requires an HA reboot to resolve, however I just checked the Google Drive folder again and saw the integration and script were updated to v4/v7 so I'm going to give those a try and hope that resolves this as well.

Also, any ideas on adding a heater entity? I've tried adding `heater` and `heater_1` as switches but both aren't recognized by the integration.
 
Welcome to the forum!
Registered to say the above for HomeAssistant worked for me too! Have been using it the past 2 days with my PS8 and it works great to control my lights and pumps, however my EW11 seems to lose connection to HomeAssistant after a couple hours (Log shows Socket Timeout) and requires an HA reboot to resolve, however I just checked the Google Drive folder again and saw the integration and script were updated to v4/v7 so I'm going to give those a try and hope that resolves this as well.
The EW11 script only handles the key press timing so that won't help for timeout. The update is mostly for documentation and improved reliability for unlocking the configuration menu when using one of the apps.

You may need to add some code in core.py to check the socket and reset if necessary. The HA may be dropping the TCP connection for some reason.

What is the RSSI of the EW11? If too low, it may be dropping the connection.

Also, the EW11 has a socket timeout setting and that should be 0 to disable that.

Also, any ideas on adding a heater entity? I've tried adding `heater` and `heater_1` as switches but both aren't recognized by the integration.

The original HA AquaLogic code developed by swilson was primarily designed for the P4 controller so it has some limitations and because of that, a few people have attempted changes to the software to add switches. You might want to look at this one:


But that is for the P4 as well so you would need to make some mods for the PS8 key codes.

@j4ydubs
 
Last edited:
Registered to say the above for HomeAssistant worked for me too! Have been using it the past 2 days with my PS8 and it works great to control my lights and pumps, however my EW11 seems to lose connection to HomeAssistant after a couple hours (Log shows Socket Timeout) and requires an HA reboot to resolve, however I just checked the Google Drive folder again and saw the integration and script were updated to v4/v7 so I'm going to give those a try and hope that resolves this as well.

Also, any ideas on adding a heater entity? I've tried adding `heater` and `heater_1` as switches but both aren't recognized by the integration.
I had a bunch of problems with uncaught exceptions, so I added code to trap them and keep the program running (reconnecting when needed). I started with swilson's latest code and worked forward from there adding in things as I saw them or wanted them. Try my forked version and see if it works better for you. You'll need to either uncomment lines 438 and 440 in core.py or if that doesn't work replace _get_key_event_frame from the core.py you have working into this core.py.

I was thinking of adding a config for P4 or P8 and add code to handle it, but haven't gotten to it. I have a P4, so that's all I can test, so I'd like to know if uncommenting 438 and 440 work for you.

I folded in the code others had done for heater (and some other stuff), but I don't have a heater so it's not tested.

Just download the zip (Code/Download Zip) from below and copy the aqualogic files into your aqualogic folder. I've been running for about a week now with no issues. Before I made my changes it would crash after an hour, sometimes less. I also have a directory with my yaml in there so you can see what's available as sensors and switches.


John
 
Thanks for the responses!

I'd like to know if uncommenting 438 and 440 work for you.
Tried this, and I get the following which seems to be preventing things from working properly:
Traceback (most recent call last):
File "/usr/local/lib/python3.12/threading.py", line 1073, in _bootstrap_inner
self.run()
File "/config/custom_components/aqualogic/__init__.py", line 89, in run
panel.process(self.data_changed)
File "/config/custom_components/aqualogic/core.py", line 302, in process
text = frame.replace(b'\xdf', b'\xc2\xb0').decode('utf-8')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xba in position 29: invalid start byte
 
Thanks for the responses!


Tried this, and I get the following which seems to be preventing things from working properly:
Traceback (most recent call last):
File "/usr/local/lib/python3.12/threading.py", line 1073, in _bootstrap_inner
self.run()
File "/config/custom_components/aqualogic/__init__.py", line 89, in run
panel.process(self.data_changed)
File "/config/custom_components/aqualogic/core.py", line 302, in process
text = frame.replace(b'\xdf', b'\xc2\xb0').decode('utf-8')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xba in position 29: invalid start byte
Replace that line (302) in core.py with:

text = frame.replace(b'\xdf', b'\xc2\xb0').decode('latin-1')

I'm not sure why that's happening, but it must have something to do with the environment that you have. Mark had a similar issue.
 
Here is a version that I have that will work for both the P4 and PS8. There is a variable in core.py to enable/disable PS8 and default is PS8 enabled.

In addition, we found that it is recommended that you do not override the default components but to create new ones instead so this version is a new component that gets installed into "custom_components" folder in the "config/" aka "homeassistant/" folder.

Here is the github:


And documentation:


I know it works for the PS8 because I tried in on a virtual machine and it should for the P4 as well but let me know if you have any issues.

Forgot to mention that I ran this overnight and it did not lose the socket connection at least for my configuration.
 
Last edited:
  • Love
Reactions: mitalian