Fluval Aquasky BLE RGB-Light

Thank you for your quick reply! Sorry. I forgot to change the channel back to 4. I have been testing various settings to see if anything would cause additional errors, but wasn’t able to since it just won’t connect.

I changed it back to 4 channels, and it still won’t connect.

I changed the order from:

ble_client:
  - mac_address: "44:A6:E5:38:CF:85"
    id: "Left"

  - mac_address: "44:A6:E5:35:B2:0C"
    id: "Right"

to

ble_client:
  - mac_address: "44:A6:E5:35:B2:0C"
    id: "Right"

  - mac_address: "44:A6:E5:38:CF:85"
    id: "Left"

and it was the same result.

I removed the working device from the yaml and tried to connect by itself only, and it still has the same issue.

I re-verified that I can connect to the Aquasky in the Fluval app just fine. I also confirmed that I had the correct mac address.

I’m really scratching my head on this one. I’ve been looking for documentation on how to factory reset the fluval device, but haven’t found any luck with it yet. Still looking.

I appreciate your help, and again, thank you so much for working on this!!! This has been a dream project that I’ve been wanting to get going for a couple of years now.

I have occassional power outages where I live, and resetting the time was the biggest hiccup for me. I resorted to putting them on a smart switch that automatically reset at 12am every night just to try to keep the time synced. Your solution is way more elegant and functional!!!
I

I know this isn’t super helpful, but this is what I am seeing.

[10:35:25][D][esp32_ble_client:048]: [0] [44:A6:E5:38:CF:85] Found device
[10:35:25][D][esp32_ble_tracker:214]: Pausing scan to make connection...
[10:35:25][V][esp32_ble:178]: (BLE) gap_event_handler - 18
[10:35:25][I][esp32_ble_client:064]: [0] [44:A6:E5:38:CF:85] 0x00 Attempting BLE connection
[10:35:26][V][esp32_ble:206]: (BLE) gattc_event [esp_gatt_if: 4] - 41
[10:35:26][V][esp32_ble_client:114]: [0] [44:A6:E5:38:CF:85] gattc_event_handler: event=41 gattc_if=4
[10:35:26][V][esp32_ble_client:168]: [0] [44:A6:E5:38:CF:85] ESP_GATTC_DISCONNECT_EVT, reason 62
[10:35:26][V][fluval_ble_led:225]: GOT GATTC EVENT: 41
[10:35:26][W][fluval_ble_led:228]: Disconnected from Fluval LED. Resetting handshake.
[10:35:26][V][esp32_ble:206]: (BLE) gattc_event [esp_gatt_if: 4] - 2
[10:35:26][V][esp32_ble_client:114]: [0] [44:A6:E5:38:CF:85] gattc_event_handler: event=2 gattc_if=4
[10:35:26][V][esp32_ble_client:129]: [0] [44:A6:E5:38:CF:85] ESP_GATTC_OPEN_EVT
[10:35:26][W][esp32_ble_client:134]: [0] [44:A6:E5:38:CF:85] Connection failed, status=133
[10:35:26][V][fluval_ble_led:225]: GOT GATTC EVENT: 2
[10:35:26][V][esp32_ble:206]: (BLE) gattc_event [esp_gatt_if: 5] - 41
[10:35:26][V][esp32_ble_client:114]: [1] [44:A6:E5:35:B2:0C] gattc_event_handler: event=41 gattc_if=5
[10:35:26][V][component:204]: Component esp32_ble took a long time for an operation (0.08 s).
[10:35:26][V][component:205]: Components should block for at most 20-30ms.
[10:35:26][D][esp32_ble_tracker:246]: Starting scan...

Hi @3dgeb,

thanks for the log. I checked the “reason 62” code, but unfortunately it just means “Connection fail to establish” So right after trying to establish the connection (“Attempting BLE connection”) it gets the gattc_event 41 (Disconnect) with the probably most generic reason.

After trying to reconnect (“Resetting handshake…”) it fails with status 133 - which again just means “error”.

When I get back from work today, I will try to recreate this issue - I have a total of three aquasky lights in two tanks, and recently I just tested with the single aquasky light, not with the dual setup.

Just as an idea - did you disconnect the app before trying to connect the ESP? Unfortunately, the lights do not support connections from both app and ESP at the same time.

Update:
After blowing up my ESP32 and getting a new one I managed to connect two LED to one ESP32 - without any issues connecting to both as well as controlling both lights. So unfortunately, I am not able to reproduce the issue.

Best regards
mrzottel

Another random thing my lights seem to do - if I reset them, and connect them via the ESP - it never seems to set the time. I have to disconnect the esp and connect my phone to make it work. Otherwise I have lights switch on at 1am which my other half doesn’t enjoy

Hello ! I can confirm this issue !

Hi @slothking87,

the module / esp32 will sync the time on first connection, and on “reconnect” after detecting a disconnection. Maybe in your case the reset is not long enough for the ESP32 to detect a disconnect and trigger the new time sync.

I will have a look at this and implement something like a “once per x minutes time resync” option to force time resync for these cases. I will try the “difficult” strategy and implement an automation with a “time_sync” method. This way it is better integrated into ESPHome and can be triggered by buttons, time based cronjob kind of stuff or interval component. Might take a couple of hours to get into that though :wink: At home, I never reset my lights, so that was not a use case until now :wink:

I might also have to resend all stored information like mode / light settings etc. after such a reset - I will check with my lights if they keep their mode and channel values etc. after a reset. Could you please tell me how you reset the lights? Simple power cycle?

@titilambert
Do you mean this issue, or the one above with two lights where one is not able to connect?

Update:
I implemented an automation thingy so time sync can be triggered by buttons or pretty much anything. I am currently testing with an interval:

interval:
  - interval: 60s
    then:
      if:
        condition: 
          time.has_time:            
        then:
          - fluval_ble_led.sync_time: fluval_freki1
          - fluval_ble_led.sync_time: fluval_freki2

where fluval_freki1 and 2 are my light ids.

This syncs the time every 60 seconds (if the time source already has a valid time). It is also smart enough not to try to sync the time to lights that are disabled by the ble_client switch or not connected. :wink:

Best regards
mrzottel

1 Like

Have you had any luck looking into this issue?
Do you have a second light setup in your own homelab?

I am still only able to connect to one of my lights. I don’t think it is an issue with multiple lights because if I only include the light that is having the status 133 error, it still doesn’t connect with the esp32. I can connect to both lights with my phone just fine, and I can connect one light with the ESP just fine. Only 1 of them is throwing errors.

Hi @3dgeb,

yes, I was able to connect to and control both fluval leds (AquaSky 2.0) located at the same tank. It is working for at least two weeks now. Comparing your config to mine, the only difference I can see is, that you made “strings” out of some IDs and parameters. While I have no idea why this might make a difference, it might be a bug in ble_client.

So my config looks like this:

ble_client:
  - mac_address: 44:A6:E5:63:E8:7F
    id: ble_freki1
  - mac_address: 44:A6:E5:72:CE:A1
    id: ble_freki2

fluval_ble_led:
  - ble_client_id: ble_freki1
    time_id: ha_time
    number_of_channels: 4
    id: fluval_freki1
  - ble_client_id: ble_freki2
    time_id: ha_time
    number_of_channels: 4
    id: fluval_freki2

So no " … " around mac and id.

I also have a pin set on both lights - but the pin is only for “show”. It is not verified on the light, but in the app. So if you are not connecting via app, the pin is never used.

I am not using the captive portal and ap mode of wifi, as it uses a lot of memory - as the ble stack does.

From my testing, I fear that the issue is not within the fluval ble module, but somewhere “above”. The stack is first the ble_tracker, which scans and detects the light with the issue - so that should be working ok. The ble_tracker hands over to the ble_client which handles connection and service discovery. This seems to fail in this case. Only after establishing a connection, the fluval module will kick in and subscribe to “incoming data notifications” (return messages from the light, which are decoded and send to the sensor entities) as well as encoding and sending user actions like mode switches to the light using the ble_client.

So my best guess would be to try to debug the ble_client connection issues. But I can try to help you with that as well :wink:

Best regards,
mrzottel

I guess I’m going to need to get help debugging the ble_client connection issue. I have been fiddling around with this for a few weeks, and haven’t made any progress.

I removed the quotes and I even renamed my devices, and nothing seems to work.

I get an endless log of connection failed attempts:

[17:45:05][I][esp32_ble_client:064]: [0] [44:A6:E5:38:CF:85] 0x00 Attempting BLE connection
[17:45:06][W][fluval_ble_led:228]: Disconnected from Fluval LED. Resetting handshake.
[17:45:06][W][esp32_ble_client:134]: [0] [44:A6:E5:38:CF:85] Connection failed, status=133
[17:45:06][D][esp32_ble_tracker:246]: Starting scan...
[17:45:13][D][esp32_ble_client:048]: [0] [44:A6:E5:38:CF:85] Found device
[17:45:13][D][esp32_ble_tracker:214]: Pausing scan to make connection...
[17:45:13][I][esp32_ble_client:064]: [0] [44:A6:E5:38:CF:85] 0x00 Attempting BLE connection
[17:45:14][W][fluval_ble_led:228]: Disconnected from Fluval LED. Resetting handshake.
[17:45:14][W][esp32_ble_client:134]: [0] [44:A6:E5:38:CF:85] Connection failed, status=133
[17:45:14][D][esp32_ble_tracker:246]: Starting scan...
[17:45:33][D][esp32_ble_client:048]: [0] [44:A6:E5:38:CF:85] Found device
[17:45:33][D][esp32_ble_tracker:214]: Pausing scan to make connection...
[17:45:33][I][esp32_ble_client:064]: [0] [44:A6:E5:38:CF:85] 0x00 Attempting BLE connection
[17:45:34][W][fluval_ble_led:228]: Disconnected from Fluval LED. Resetting handshake.
[17:45:34][W][esp32_ble_client:134]: [0] [44:A6:E5:38:CF:85] Connection failed, status=133
[17:45:34][D][esp32_ble_tracker:246]: Starting scan...
[17:45:52][D][esp32_ble_client:048]: [0] [44:A6:E5:38:CF:85] Found device
[17:45:52][D][esp32_ble_tracker:214]: Pausing scan to make connection...
[17:45:52][I][esp32_ble_client:064]: [0] [44:A6:E5:38:CF:85] 0x00 Attempting BLE connection
[17:45:53][W][fluval_ble_led:228]: Disconnected from Fluval LED. Resetting handshake.
[17:45:53][W][esp32_ble_client:134]: [0] [44:A6:E5:38:CF:85] Connection failed, status=133
[17:45:53][D][esp32_ble_tracker:246]: Starting scan...
[17:49:28][D][esp32_ble_client:048]: [0] [44:A6:E5:38:CF:85] Found device
[17:49:28][D][esp32_ble_tracker:214]: Pausing scan to make connection...
[17:49:28][I][esp32_ble_client:064]: [0] [44:A6:E5:38:CF:85] 0x00 Attempting BLE connection
[17:49:31][W][fluval_ble_led:228]: Disconnected from Fluval LED. Resetting handshake.
[17:49:31][W][esp32_ble_client:134]: [0] [44:A6:E5:38:CF:85] Connection failed, status=133
[17:49:31][D][esp32_ble_tracker:246]: Starting scan...
[17:50:07][D][esp32_ble_client:048]: [0] [44:A6:E5:38:CF:85] Found device
[17:50:07][D][esp32_ble_tracker:214]: Pausing scan to make connection...
[17:50:07][I][esp32_ble_client:064]: [0] [44:A6:E5:38:CF:85] 0x00 Attempting BLE connection
[17:50:11][W][fluval_ble_led:228]: Disconnected from Fluval LED. Resetting handshake.
[17:50:11][W][esp32_ble_client:134]: [0] [44:A6:E5:38:CF:85] Connection failed, status=133
[17:50:11][D][esp32_ble_tracker:246]: Starting scan...

Ok, so lets get to debugging :wink:

So at first we can rule out that the number of lights is an issue, as the BLE_Client should be able to handle 3 lights, I tested it with two, and even if you test only the “broken” light, it won’t work.

Unfortunately, it is also unlikely that the fluval_ble_led component is the issue, as it has no dealings in the initial connection. Unfortunately, because thats the code I know best in this whole setup.

The ble_client component uses the esp32_ble_client component to initiate the connection, and the esp32_ble_client component uses the call to “esp_ble_gattc_open” to establish the connection. This returns successfull (which only means that it is going to try, not that it succeeded). Within less than a second, esp32_ble_client receives an esp_gattc_open_evt with the 133 state, so it fails.

esp_ble_gattc_open is a command supplied by the framework, in your case:

esp32:
  board: esp32dev
  framework:
    type: arduino

I was mostly using the idf (the framework directly supplied by the ESP32 people) for tests:

esp32:
  board: az-delivery-devkit-v4
  framework:
    type: esp-idf
    version: recommended

So this might make a difference in the supplied esp_ble_gattc_open command of the framework.
(I will check the issues logged for this command later in the evening, but I found quite some on a quick google search)

Lastly, this command directly uses the hardware. It is somewhat unlikely that the hardware has a fault here, as it works for the other light. The only thing I could come up with was that maybe a bit is stuck in a hardware register handling the mac address in the bluetooth hardware - so it would affect some but not all mac addresses.

tl;dr:

So further things you could test are:

  1. Check if changing to esp-idf as framework makes a difference. You might have to “Clean Build Files” from the burger menu of your esp in esphome before it compiles right with the new framework. Also compilation might take a while, as it has to recompile everything.

  2. If you have a second ESP32 available, you might try this one to rule out hardware issues.

I will follow up if I am through with the list of known issues regarding esp_ble_gattc_open.

Best regards,
mrzottel

You are a rock star and a legend. I didn’t think about switching to esp-idf, but that seemed to do the trick.

So weird that the Arduino framework worked with one and not the other.

Anyway, I will Give this a whirl for a while, and I’ll let you know how it goes.

@mrzottel another think I have noticed is the status of the lights don’t seem to update unless I interact with them in some way. I.e. Setting the mode to Pro, Auto etc… and changing it back.

Is this what you are seeing as well? Want to make sure I’m not missing something.

@3dgeb
Thank you for testing this with esp-idf - I will see if I can reproduce the issue with arduino framework and dive deeper into that - as it should work with both, even if the framework is to blame. I can raise an issue there then :wink:

And yes, I have the same issue with the status only becoming available after an interaction. I am still trying to find out how the app does this.

The background is, that the light is always sending back the current status after an interaction, but not just on connection. So at least one interaction is required. As the app works without an interaction, I think there is a “just send status, do not change anything”-command used by the app. The source code of the app has such a command, but it freezes my lights, so I abandoned it. The source code was quite old though, and I got a ble sniffer now to go on a hunt for this command.

I will update here as soon as I got it implemented. As we have a bank holiday tomorrow, chances are good that it won’t take long :wink:

Best regards
mrzottel

@3dgeb

Sorry for the delay - I just fixed the issue with the status only beeing updated after an interaction. The status should come right up after conneting for the first time - and each reconnection if required.

The issue regarding arduino framework is still under investigation.

Best regards
mrzottel

2 Likes

Hello;

Thanks for the mod it works well. If there any way to have the light appear with the colour options more integrated with HA? Was hoping for a colour selector.

Are the external components still required?

Hi Wheemer,

I also was wondering if integration into HA could be improved. Unfortunately, I am quite new to HA itself. It might be possible to create a color picker, but it must scale to fit into this 0-1000 range the Fluval LED is using. Most other LEDs use a 0-255 range. Also, the LEDs are 4 or 5 channels, while most other LEDs are 3 to 4 channels.

But if I find the time, I will have a look for sure to implement a “light” component which tries to map this stuff.

External component is still required. The PR is kind of waiting for someone from the ESPHome team to have a look at it, but so far nothing happened.

Currently I am trying to work around a breaking change introduced in ESPHome 2023.6 though :wink:

Best regards
mrzottel

Update: I just commited a new version which is compatible with ESPHome 2023.6. They did a breaking change on the time component, so it was necessary.

Hi,
any news regarding the framework issue ? I am not using HA but webserver and that does not work with esp variant ;-(
web_server: [source fluval.yaml:25]

This feature is only available with frameworks [‘arduino’].

Thanks
Michael

src/esphome/components/fluval_ble_led/fluval_ble_led.cpp:4:10: fatal error: esphome/core/time.h: No such file or directory
#include “esphome/core/time.h”
^~~~~~~~~~~~~~~~~~~~~
compilation terminated.

@mpovel

Unfortunately, no news regarding arduino framework. Are you running into the same issue that you are only able to connect one of two LEDs to a single ESP? I used the arduino framework for a long time during development and never had an issue with one light, and also had no luck replicating the issue with two lights.

Best regards
mrzottel