Access BLE signal strength or last updated directly from ESP32

I’m using xiaomi_lywsd03mmc and ESP32 to control my underfloor heating.
The climate module in ESPHome together with the xiaomi bluetooth temperature devices seems to be making a fine autonomous system that can operate even if HA is not accessible.

There’s just a small issue… If one of the underfloorheating valves open and the BT device for some reason goes offline or is just inaccessible then the climate controller will keep heating .

I wonder if there is a way of accessing the bluetooth signal strength directly inside an ESP32?
Or if its possible to check last time the ESP heard from a bluetooth device? - remember we are talking directly in ESP to keep the system autonomous .

Can you post your yaml?

hi @danielw

(I’ll remove some code to keep it simple)
Here is one of my relays:

  - platform: gpio
    name: "${esphome_name}_Relay_1"
    id: stue_heat
    pin: 13
    inverted: True
    restore_mode: RESTORE_DEFAULT_OFF
    on_turn_on:
      - logger.log: "Switch Turned On: Stue"
    on_turn_off:
      - logger.log: "Switch Turned Off: Stue"

Here’s the climate controller that uses the relay:

climate:
  - platform: thermostat
    name: "Stue Termostat"
    sensor: stue_temp
    default_target_temperature_low: 20 °C
    heat_action:
      - switch.turn_on: stue_heat
    idle_action:
      - switch.turn_off: stue_heat
    visual:
      min_temperature: 16 °C
      max_temperature: 22 °C
      temperature_step: 1 °C

I’ve actually managed to get a rssi working on the BT sensor:
(This code doesnt work yet!)
I would like to know if the rssi signal is … well anything else than a number that is acceptable.
I can see that the esp console just output “nan” if the sensor is not accessable, but this doesnt work directly in lambda if statement.

  - platform: ble_rssi
    mac_address: A4:C1:38:5E:02:EB
    name: "sensor signal strength"
    id: stue_rssi
    filters:
      - lambda: if (x == "nan") return x; else return {}; #Not working...
    on_value:
      then:
        - logger.log: "No contact to sensor!"

OK, nice. So you got it working.

You can check for nan (Not a Number) with the isnan function like so:

  - platform: ble_rssi
    mac_address: A4:C1:38:5E:02:EB
    name: "sensor signal strength"
    id: stue_rssi
    filters:
      - lambda: if ( isnan(x) ) return -1; else return x; 
    on_value:
      then:
        - logger.log: "No contact to sensor!"

thanks @danielw , I’ll implement it when I get a esp with a little more flash - I think I have pushed it to the limit right now :smiley: