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

How to use weather-node with Home assistant and ESPHome #8

Closed
KinDR007 opened this issue Jul 24, 2021 · 4 comments
Closed

How to use weather-node with Home assistant and ESPHome #8

KinDR007 opened this issue Jul 24, 2021 · 4 comments

Comments

@KinDR007
Copy link

KinDR007 commented Jul 24, 2021

Hi ,
its possible use node with Home assistant and ESPHome (esp32) ?
Snímek obrazovky 2021-07-25 v 0 35 58

how to get data for use in home assistant?

@AlexIII
Copy link
Owner

AlexIII commented Jul 25, 2021

Hi!
There's a line [ble_adv:053] 0x53A9: (length 6) in the log on your picture. That's where's the data is stored. You need a way to read and manually convert those 6 bytes to temperature (fist 2 bytes), humidity (2 bytes) and status (1 byte) according to this tabe. You can use 0x53A9 to distinguish this device from any other.

@KinDR007
Copy link
Author

KinDR007 commented Jul 25, 2021

hi , thx for quick reaction

here its my code for ESPHome

 on_ble_manufacturer_data_advertise:
    - mac_address: DE:AD:BE:EF:00:01
      manufacturer_id: 53A9
      then:
        - lambda: |-
            id(humidity).publish_state((x[0] << 8) + x[1]);
            id(temp).publish_state(((x[2] << 8) + x[3]) / 10.0);
            id(battble).publish_state(((x[4] << 8) ) );    


sensor:
  - platform: template
    name: "BLE Sensor temp"
    id: temp
    unit_of_measurement: "C"
    accuracy_decimals: 1

  - platform: template
    name: "BLE Sensor humidity"
    id: humidity
    unit_of_measurement: "%"
    accuracy_decimals: 0
    
  - platform: template
    id: battble  
    
  - platform: template
    name: "BLE Sensor bat"
    id: batt    
    unit_of_measurement: "%"
    accuracy_decimals: 0
    lambda: |-
      int batperc;
      const int battlvl = id(battble).state;
      if (battlvl == 0)
      {
          batperc = 100;
      }
      else if (battlvl == 1)
      {
          batperc = 75;
      }
      else if (battlvl == 2)
      {
          batperc = 50;
      }
      else if (battlvl == 3)
      {
          batperc = 25;
      }
      return batperc;

Snímek obrazovky 2021-07-25 v 9 30 35

I still have a question, what happens when the temperature value is negative?

@AlexIII
Copy link
Owner

AlexIII commented Jul 25, 2021

Seems good to me. To support negative temperature you can do something like this

id(temp).publish_state( (x[2] & 0x80? -1 : 1) * (((x[2] & 0x7F) << 8) + x[3]) / 10.0);

The sign is the higher bit of x[2].
I also suggest you add 2-bit mask to read battery level

const int battlvl = id(battble).state & 0x03;

Do you mind telling what version you're using, nRF24LE1-based or Arduino-based?

@AlexIII AlexIII changed the title not issues How to use weather-node with Home assistant and ESPHome Jul 25, 2021
@KinDR007
Copy link
Author

KinDR007 commented Jul 25, 2021

Hi ,
I use Arduino pro mini board (mod. to 1.8volt@1Mhz) and nrf24l01
Old Mysensors node with HTU21D

@AlexIII AlexIII closed this as completed Jul 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants