Ble scanner (#976)

* Added ble_scanner component

* ble_scanner: time.h changed to ctime

* ble_scanner: Test added.

* ble_scanner: fixed code formatting.

* Removed duplicate binary sensor tests from test2 and test3 to decrease memory requirements.

* Removed another duplicate test from test2.yaml and moved stepper test to yaml3.yaml to reduce memory requirements of test2.yaml.

* Reverted the last stepper test change

* Moved some sensor tests from test2.yaml to test3.yaml to save memory.

* Moved ruuvitag back to test2.yaml as it requires component esp32_ble_tracker.

* removed apds9960 as it is duplicated

Co-authored-by: Guillermo Ruffino <glm.net@gmail.com>
This commit is contained in:
Jozef Zuzelka 2020-05-20 02:13:50 +02:00 committed by GitHub
parent 1319ff1129
commit 153aadadae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 120 additions and 73 deletions

View File

@ -0,0 +1,16 @@
#include "ble_scanner.h"
#include "esphome/core/log.h"
#ifdef ARDUINO_ARCH_ESP32
namespace esphome {
namespace ble_scanner {
static const char *TAG = "ble_scanner";
void BLEScanner::dump_config() { LOG_TEXT_SENSOR("", "BLE Scanner", this); }
} // namespace ble_scanner
} // namespace esphome
#endif

View File

@ -0,0 +1,38 @@
#pragma once
#include <ctime>
#include <string>
#include "esphome/core/component.h"
#include "esphome/components/esp32_ble_tracker/esp32_ble_tracker.h"
#include "esphome/components/text_sensor/text_sensor.h"
#ifdef ARDUINO_ARCH_ESP32
namespace esphome {
namespace ble_scanner {
class BLEScanner : public text_sensor::TextSensor, public esp32_ble_tracker::ESPBTDeviceListener, public Component {
public:
bool parse_device(const esp32_ble_tracker::ESPBTDevice &device) override {
this->publish_state("{\"timestamp\":" + to_string(::time(NULL)) +
","
"\"address\":\"" +
device.address_str() +
"\","
"\"rssi\":" +
to_string(device.get_rssi()) +
","
"\"name\":\"" +
device.get_name() + "\"}");
return true;
}
void dump_config() override;
float get_setup_priority() const override { return setup_priority::DATA; }
};
} // namespace ble_scanner
} // namespace esphome
#endif

View File

@ -0,0 +1,22 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import text_sensor, esp32_ble_tracker
from esphome.const import CONF_ID
DEPENDENCIES = ['esp32_ble_tracker']
ble_scanner_ns = cg.esphome_ns.namespace('ble_scanner')
BLEScanner = ble_scanner_ns.class_('BLEScanner', text_sensor.TextSensor, cg.Component,
esp32_ble_tracker.ESPBTDeviceListener)
CONFIG_SCHEMA = cv.All(text_sensor.TEXT_SENSOR_SCHEMA.extend({
cv.GenerateID(): cv.declare_id(BLEScanner),
}).extend(esp32_ble_tracker.ESP_BLE_DEVICE_SCHEMA).extend(
cv.COMPONENT_SCHEMA))
def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
yield cg.register_component(var, config)
yield esp32_ble_tracker.register_ble_device(var, config)
yield text_sensor.register_text_sensor(var, config)

View File

@ -100,62 +100,6 @@ sensor:
name: "Xiaomi CGG1 Humidity"
battery_level:
name: "Xiaomi CGG1 Battery Level"
- platform: pmsx003
type: PMSX003
pm_1_0:
name: "PM 1.0 Concentration"
pm_2_5:
name: "PM 2.5 Concentration"
pm_10_0:
name: "PM 10.0 Concentration"
- platform: pmsx003
type: PMS5003T
pm_2_5:
name: "PM 2.5 Concentration"
temperature:
name: "PMS Temperature"
humidity:
name: "PMS Humidity"
- platform: pmsx003
type: PMS5003ST
pm_2_5:
name: "PM 2.5 Concentration"
temperature:
name: "PMS Temperature"
humidity:
name: "PMS Humidity"
formaldehyde:
name: "PMS Formaldehyde Concentration"
- platform: cse7766
voltage:
name: "CSE7766 Voltage"
current:
name: "CSE7766 Current"
power:
name: "CSE776 Power"
- platform: apds9960
type: proximity
name: APDS9960 Proximity
- platform: apds9960
type: clear
name: APDS9960 Clear
- platform: apds9960
type: red
name: APDS9960 Red
- platform: apds9960
type: green
name: APDS9960 Green
- platform: apds9960
type: blue
name: APDS9960 Blue
- platform: homeassistant
entity_id: sensor.hello_world
id: ha_hello_world
- platform: as3935
lightning_energy:
name: "Lightning Energy"
distance:
name: "Distance Storm"
- platform: ruuvitag
mac_address: FF:56:D3:2F:7D:E8
humidity:
@ -178,6 +122,14 @@ sensor:
name: "RuuviTag Movement Counter"
measurement_sequence_number:
name: "RuuviTag Measurement Sequence Number"
- platform: homeassistant
entity_id: sensor.hello_world
id: ha_hello_world
- platform: as3935
lightning_energy:
name: "Lightning Energy"
distance:
name: "Distance Storm"
time:
- platform: homeassistant
@ -186,10 +138,6 @@ time:
then:
- logger.log: It's 16:00
apds9960:
address: 0x20
update_interval: 60s
esp32_touch:
setup_mode: True
@ -210,18 +158,6 @@ binary_sensor:
name: "ESP32 Touch Pad GPIO27"
pin: GPIO27
threshold: 1000
- platform: apds9960
direction: up
name: APDS9960 Up
- platform: apds9960
direction: down
name: APDS9960 Down
- platform: apds9960
direction: left
name: APDS9960 Left
- platform: apds9960
direction: right
name: APDS9960 Right
- platform: homeassistant
entity_id: binary_sensor.hello_world
id: ha_hello_world_binary
@ -291,6 +227,8 @@ text_sensor:
- platform: homeassistant
entity_id: sensor.hello_world2
id: ha_hello_world2
- platform: ble_scanner
name: Scanner
script:
- id: my_script

View File

@ -360,6 +360,39 @@ sensor:
name: "PM2.5"
pm_10_0:
name: "PM10.0"
- platform: pmsx003
type: PMSX003
pm_1_0:
name: "PM 1.0 Concentration"
pm_2_5:
name: "PM 2.5 Concentration"
pm_10_0:
name: "PM 10.0 Concentration"
- platform: pmsx003
type: PMS5003T
pm_2_5:
name: "PM 2.5 Concentration"
temperature:
name: "PMS Temperature"
humidity:
name: "PMS Humidity"
- platform: pmsx003
type: PMS5003ST
pm_2_5:
name: "PM 2.5 Concentration"
temperature:
name: "PMS Temperature"
humidity:
name: "PMS Humidity"
formaldehyde:
name: "PMS Formaldehyde Concentration"
- platform: cse7766
voltage:
name: "CSE7766 Voltage"
current:
name: "CSE7766 Current"
power:
name: "CSE776 Power"
time:
- platform: homeassistant