Blue Connect pool measurements

I am getting it connected once at startup sometimes (but not always). Whenever I enable the switch, all I get is:

[15:38:29][D][switch:012]: 'whirlpool Enable' Turning ON.
[15:38:29][D][switch:055]: 'whirlpool Enable': Sending state ON

I played around with the scanning parameters, changing the the interval and window and also the active/passive. But no effect so far.

Hello,
first thank to all for ESPhome configuration.
my esphome with nomeMCU esp 32 was working for 1 day.
today stop to work, when i activate the switch, the ble will be ON , but the BLE gateway canā€™t find the blueconnect.

esp32_ble:178 (BLE) gap_event_handler -3 

Can you help me?

image
the log from web server of esphome


my blueconnect device

It is exactly the same situation as for me. Got no solution so far. Sometimes it works once after a reboot.

i will try to reboot the blueconnect, or searching on internat also to put in stanby and resume it.
iā€™m requesting data every hourā€¦mabe there is some limitation on readingā€¦if you exceed the bluetooth will block it to save battery maybe, make sense?

I am only trying to connect every 2h. And even after 12h I get no connect. So dont think this is the issue. When i reboot the esp, i then get often a connect. Also the mobile app can connect whenever I want. So for me it looks like a bug in the esp ble stack or so.

I am logging in the on_ble_advertise function and even this code part seems not to be used sometimes.

Ok i am a step further now. I am getting a log message for the scan start, but even it is configured, no scan end message. So somewhere in the middle of the scan there is a bug, which stops the scan.
P.S.: I have massively reduced my code to only have the blueriiot code.


substitutions:
  name: atom-lite-1
#  name: atom-lite-1-de0ce8
  roomname: Wohnzimmer
  staticip: 192.168.1.145
  yourname: Lukas

  # erster Blueconnect
  blueriiot1_mac: '00:A0:50:C7:46:XX'
  blueriiot1_name_prefix: 'whirlpool'
  blueriiot1_id_prefix: 'pl'

  # send true 0x01 to this service ID
  blueriiot_send_service_uuid: 'F3300001-F0A2-9B06-0C59-1BC4763B5C00'
  blueriiot_send_characteristic_uuid: 'F3300002-F0A2-9B06-0C59-1BC4763B5C00'
  
  # notification is recieved on this Service ID                  
  blueriiot_recieve_service_uuid: 'F3300001-F0A2-9B06-0C59-1BC4763B5C00'
  blueriiot_recieve_characteristic_uuid: 'F3300003-F0A2-9B06-0C59-1BC4763B5C00'


esphome:
  name: ${name}
  name_add_mac_suffix: True
  platformio_options:
    build_flags: 
      - -Wno-maybe-uninitialized
packages:
  esphome.bluetooth-proxy: github://esphome/bluetooth-proxies/m5stack-atom-lite.yaml@main

esp32:
  board: m5stack-atom
  framework:
    type: arduino
#    type: esp-idf    

# Enable logging
logger:
  level: VERY_VERBOSE
  #level: DEBUG

# Enable Home Assistant API
api:
  password: ""

ota:
  password: ""

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  manual_ip:
    # Set this to the IP of the ESP
    static_ip: $staticip
    # Set this to the IP address of the router. Often ends with .1
    gateway: 192.168.1.3
    # The subnet of the network. 255.255.255.0 works for most home networks.
    subnet: 255.255.255.0

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Atom-Lite-1 Fallback Hotspot"
    password: "Pol8GUJw7wTe"

#captive_portal:

bluetooth_proxy:
  active: true

#web_server:
#  port: 80
#  auth:
#    username: admin
#    password: Quatschkopf01

esp32_ble_tracker:
  scan_parameters:
    #interval: 300ms
    #window: 50ms
    active: true
    interval: 1000ms
    window: 1000ms
    #active: false
  #on_ble_advertise:
  #  - then:
  #    - lambda: |-
  #        ESP_LOGD("ble_adv", "New BLE device");
  #        ESP_LOGD("ble_adv", "  address: %s", x.address_str().c_str());
  #        ESP_LOGD("ble_adv", "  name: %s", x.get_name().c_str());
  on_scan_end:
    - then:
        - lambda: |-
             ESP_LOGD("ble_auto", "The scan has ended!");

ble_client:
  # erster Sensor
  - mac_address: ${blueriiot1_mac}
    id: ble_client_${blueriiot1_id_prefix}
    on_connect: 
      then:
        - lambda: |-
            ESP_LOGD("ble_client_on_connect", "Connected to blueriiot ${blueriiot1_mac}");
            id(binary_sensor_${blueriiot1_id_prefix}_connected).publish_state(true);
        - delay: 3s
        - button.press: button_${blueriiot1_id_prefix}_doreading
    on_disconnect: [lambda: "id(binary_sensor_${blueriiot1_id_prefix}_connected).publish_state(false);"]

switch:
  # erster Sensor
  - platform: ble_client
    ble_client_id: ble_client_${blueriiot1_id_prefix}
    name: "${blueriiot1_name_prefix} Enable"
    id: switch_${blueriiot1_id_prefix}_enable
    restore_mode: ALWAYS_OFF

sensor:
  # erster Sensor
  - platform: template 
    id: sensor_${blueriiot1_id_prefix}_temperature
    name: ${blueriiot1_name_prefix} Temperature
    # Optional variables:
    unit_of_measurement: "Ā°C"
    icon: "mdi:water-percent"
    device_class: "temperature"
    state_class: "measurement"
    accuracy_decimals: 1

  - platform: template 
    id: sensor_${blueriiot1_id_prefix}_ph
    name: ${blueriiot1_name_prefix} PH
    # Optional variables:
    #unit_of_measurement: "Ā°C"
    #icon: "mdi:water-percent"
    #device_class: "temperature"
    state_class: "measurement"
    accuracy_decimals: 1
 
  - platform: template 
    id: sensor_${blueriiot1_id_prefix}_orp
    name: ${blueriiot1_name_prefix} Chlor
    # Optional variables:
    #unit_of_measurement: "Ā°C"
    #icon: "mdi:water-percent"
    device_class: "voltage"
    state_class: "measurement"
    accuracy_decimals: 1
    
  - platform: template 
    id: sensor_${blueriiot1_id_prefix}_bat
    name: ${blueriiot1_name_prefix} Battery
    # Optional variables:
    #unit_of_measurement: "Ā°C"
    #icon: "mdi:water-percent"
    device_class: "battery"
    state_class: "measurement"
    accuracy_decimals: 1
    
binary_sensor:
# erster Sensor  
  - platform: template
    id: binary_sensor_${blueriiot1_id_prefix}_connected
    name: ${blueriiot1_name_prefix} Status
    device_class: connectivity
    entity_category: diagnostic

button:
  - platform: template
    id: button_${blueriiot1_id_prefix}_doreading
    name: ${blueriiot1_name_prefix} do reading
    internal: true
    on_press:
      then:
        - ble_client.ble_write:
            id: ble_client_${blueriiot1_id_prefix}
            service_uuid: ${blueriiot_send_service_uuid}
            characteristic_uuid: ${blueriiot_send_characteristic_uuid}
            # A lambda returning an std::vector<uint8_t>.
            value: !lambda |-
              return {0x01};
  - platform: template
    id: button_start_scan
    name: Start BLE Scan
    on_press:
      then:
        - esp32_ble_tracker.start_scan:
            continuous: false

  - platform: restart
    id: room_restart
    name: "$yourname $roomname restart"

text_sensor:
  # erster Sensor
  - platform: ble_client
    id: ${blueriiot1_id_prefix}_reading_data
    name: ${blueriiot1_name_prefix} reading data
    internal: true
    ble_client_id: ble_client_${blueriiot1_id_prefix}
    service_uuid: ${blueriiot_recieve_service_uuid}
    characteristic_uuid: ${blueriiot_recieve_characteristic_uuid}
    notify: true
    update_interval: never
    on_notify:
      then:
       lambda: |-
          std::string rawhex = format_hex_pretty((uint8_t *) x.c_str(), x.size()).c_str();
          ESP_LOGD("raw_hex", "%s", rawhex.c_str());
 
          float temperature = (float)((int16_t)(x[2]<< 8) + x[1])/100;
          ESP_LOGD("temp", "%f", temperature);
          id(sensor_${blueriiot1_id_prefix}_temperature).publish_state(temperature);
              
          float raw_ph = (float)( (int16_t) (x[4]<< 8) + x[3]) ;
          float ph = (float)( (int16_t) (2048 - raw_ph)) / 232  + 7 ; 
          ESP_LOGD("ph", "%f", ph);
          id(sensor_${blueriiot1_id_prefix}_ph).publish_state(ph);
          
          float orp = (float)( (int16_t) (x[6]<< 8) + x[5]) / 3.86 ;
          ESP_LOGD("orp", "%f", orp);
          id(sensor_${blueriiot1_id_prefix}_orp).publish_state(orp);
          
          float bat = (float)( (int16_t) x[11]) ;
          ESP_LOGD("bat", "%f", bat);
          id(sensor_${blueriiot1_id_prefix}_bat).publish_state(bat);
          
          id(switch_${blueriiot1_id_prefix}_enable).turn_off();
    # ENDE erster Sensor
 

the only difference from mine yaml.
for my problem i discover that also blueconnect app canā€™t connect. i decided to open the blue connect go, and disconnect the battery. After disconnection and reconnect ion, the app and the ble gateway start go work. today are 2 days without problem.

i also decide to receive the raw data, only for PH, and wrote a DSL rule in openhab to transform raw data to real ph

rule "piscina graph"
when
	Item pump_dosing_controll received command or
	Item ph_level received update or
	Item esphome_blueconnect_pH_raw received update or
	Item esphome_blueconnect_temperature received update
then
	if(receivedCommand == ON) g_pump.postUpdate(pump_on)
	else g_pump.postUpdate(pump_off)	
	g_set.postUpdate(ph_level.state)
	var Number ph_raw = esphome_blueconnect_pH_raw.state as Number
	var Number temp = esphome_blueconnect_temperature.state as Number
	var Number slope = 54.2 + temp * 0.1984
	var Number ph_calc = ph_raw / (slope * 4) + 7 + ph_offset
	g_ph.postUpdate(ph_calc) 
	ph_ave.postUpdate(ph_calc)
	esphome_blueconnect_pH.postUpdate(ph_calc)
end

the slope is influenced by water temperature

cheers

1 Like

Hi, I will also try a reboot of the device.
Questions regarding your cool calculation of the real ph value.
First: That you recalculate the value assumes, that the blue connect is not calculating it himself - right?
Second: You use a variable called ā€žph_offsetā€œ, which is not defined. Whats the value of it?

ciao
my replies:

  1. yes correct. i was think this because the guys that make the first attempt, the resuls was ever near and not precise as for the APP. i also try to ask at the blueriiot support, we will see what they are saying.
  2. is a variable that i will use in future , when i will try to calibrate the ph with buffer solution, is just for future integration.

Thanks, Iā€™ll try to backport your findings into my yaml definitions soon. Is there a similar formula for ORP?

not for ORP

1 Like

ciao Tomas, Iā€™m trying to port your code, with no luck. I have this data coming from the sensor and the formula doesnā€™t seem to fit:

  • temperature: 27.80
  • raw_ph = 2046

When trying your formula, the values are off. Any hints? Thanks.

for PH my yaml is like this:

float raw_ph = (float)( (int16_t) (x[4]<< 8) + x[3]) ;
          float ph = (float)( (int16_t) (2048 - raw_ph)) ; 
          ESP_LOGD("ph", "%f", ph);
          id(sensor_${blueriiot1_id_prefix}_ph).publish_state(ph);

can you share your esphome configuration yaml?


the translationā€¦
Hi Thomas,

The Blue Connect itself incorporates Automatic Temperature Compensation (ATC) as part of its design. This means that the Blue Connect device hardware is equipped with sensors that can detect changes in water temperature and adjust the measurements of parameters such as pH and chlorine levels accordingly. The ATC function does not depend on the Android application, but is an integral part of the device technology. This ensures accurate readings directly from the device, regardless of the platform or app used to access the data.

Sharyn

i need to correct my calculation.

1 Like

In meanwhile I dont get any connection from my esp. With the app I can connect without any problems. Not sure, if it is usefull, to reconnect the battery for me, but I saw, that you need to remove the tape to do this, not sure if this is a good idea. I have really no idea, why the esp cant connect. I am using a atom lite here.
While the bluetooth connect is not possible I felt back using the mqtt based solution.

Hi,

My guess is that the bluetooth_proxy has something to do with it. Looks like it keep the connection going. In my setup (first version of the yaml) I had the same issue as the BT stayed connected to the sensor. I had to disable BT in the esp to disconnect from the sensor.
For just the sensor reading you donā€™t need the proxy, as I understood correctly is more used as a relay to regular temp sensors.

Did you try to disable it?
Maybe just connect to the blueriiot

ā€œor my problem i discover that also blueconnect app canā€™t connect. i decided to open the blue connect go, and disconnect the battery. After disconnection and reconnect ion, the app and the ble gateway start go work. today are 2 days without problem.ā€

The sensor only allows 1 connection, the app connects request a reading, waits for the data and then disconnects. After that it sends the raw data to the cloud for conversion where the app then gets the reply. Using the lordmike integration the same result is retrieved.

Kind regards,
Peter

Reading up on the conversation, i had my notification wrongly configured and missed out on the conversation. Good work!
Where are you now with the values? Is your yaml conversion more inline with the app?

-Peter