Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement Direct connection to BT temperature sensor with the fallback option #2341

Open
Andrecall opened this issue Oct 22, 2024 · 2 comments
Labels
Add-on: Bluetooth Covers both BLE Tracker and Bluetooth Proxy related issues. Customization Suggests features or modifications tailored to specific user groups. Enhancement For suggestions that add new features or improve existing functionalities.

Comments

@Andrecall
Copy link

Andrecall commented Oct 22, 2024

Enhancement Summary

Direct connection to BT temperature sensor with the fallback option

Detailed Description

Hi!
I highly appreciate what you are doing with NS Panel, this brings this hardware to the whole new level. So I thought I might share with you and the community something what works quite stable for me since last 3 months and I would say elevates NS Panel even a bit more.

Problem statement
As everyone here knows, temperature sensor is quite bad in NS Panel, not actually bad, but highly impacted by NS Panel own temperature. Yes, we can set up an offset to compensate, but NS Panel own temperature is not stable as well. It deepens on Brightness(I'm setting it based on light sensor) and if some other features are enabled at the moment.
Currently we do have am option to use external temperature sensor from HA, which also works until...HA is there. I believe, thermostat is a kind of device, that not just should, but must be able to work completely standalone.

Idea
NS Panel and ESP32 in general could connect to BLE temperature sensor directly, but even that was not enough for me, I wanted to have a fallback option to NS Panel internal temperature sensor, if Bluetooth sensor is not available, so the climate function could stay as stable as possible. So here we go:

**Pre-requisites **

  1. This line should be enabled in you config:
    - esphome/nspanel_esphome_addon_ble_tracker.yaml
  2. You should have any bt temperature sensor, which is supported by esphome.

Code
Let's add some flag to let HA know which sensor is currently used:

#BLE sensor flag
binary_sensor:
  - platform: template
    name: "BLE Sensor"
    id: ble_state

Now adding a bt temperature sensor (xiaomi_lywsdcgq in my case) to esphome config and setting up a 60s update limit in oder not to spam our climate with a new value every second:

#external temp sensor 
sensor:
  - platform: xiaomi_lywsdcgq
    mac_address: 58:58:58:58:58:58
    temperature:
      name: BLE Temperature
      id: ble_temp
      internal: true
      filters:
        - throttle_average: 60s

And here is the most interesting part. We need to build a new temperature sensor, which will switch between Bluetooth and internal sensors based on the first one availability:

  - platform: template
    name: Consolidated Temperature
    id: cons_temp
    icon: mdi:thermometer
    lambda: |-
      if (isnan(id(ble_temp).state)) {
        id(ble_state).publish_state(false);        
        return id(temp_nspanel).state;
      } else {
        id(ble_state).publish_state(true);
        return id(ble_temp).state;
      }

The last step left. Nothing will work until we extend builtin climate with our new consolidated sensor:

#replace internal temp sensor with combined
climate:
  - id: !extend thermostat_embedded
    sensor: cons_temp

Thanks!

Bonus

Almost every bt sensor has a humidity sensor on board as well. So this could be also included and used for some internal logic or automation

Additional Context

No response

@Andrecall Andrecall added the Enhancement For suggestions that add new features or improve existing functionalities. label Oct 22, 2024
@Andrecall
Copy link
Author

Andrecall commented Oct 22, 2024

Not an expert, but suppose this logic could be included as a part of blueprint, at least for the most common bt temperature sensors.
Btw., adding light sensor to enable automatic brightness adjustment could be also beneficial

@Andrecall Andrecall changed the title Enhancement Enhancement Direct connection to BT temperature sensor with the fallback option Oct 22, 2024
@edwardtfn
Copy link
Collaborator

This is awesome!!
Thanks a lot for sharing!

@edwardtfn edwardtfn added Customization Suggests features or modifications tailored to specific user groups. Add-on: Bluetooth Covers both BLE Tracker and Bluetooth Proxy related issues. labels Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Add-on: Bluetooth Covers both BLE Tracker and Bluetooth Proxy related issues. Customization Suggests features or modifications tailored to specific user groups. Enhancement For suggestions that add new features or improve existing functionalities.
Projects
None yet
Development

No branches or pull requests

2 participants