ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
sen21231.cpp
Go to the documentation of this file.
1#include "sen21231.h"
2#include "esphome/core/log.h"
3
5
6ESPHOME_LOG_TAG(TAG, "sen21231_sensor.sensor");
7
9
11 ESP_LOGCONFIG(TAG, "SEN21231:");
12 LOG_I2C_DEVICE(this);
13 LOG_UPDATE_INTERVAL(this);
14}
15
18 if (!this->status_comm_result(this->read_bytes(PERSON_SENSOR_I2C_ADDRESS, (uint8_t *) &results, sizeof(results)))) {
19 ESP_LOGW(TAG, "Failed to read data from SEN21231");
20 return;
21 }
22 ESP_LOGD(TAG, "SEN21231: %d faces detected", results.num_faces);
23 this->publish_state(results.num_faces);
24 if (results.num_faces == 1) {
25 ESP_LOGD(TAG, "SEN21231: is facing towards camera: %d", results.faces[0].is_facing);
26 }
27}
28
29} // namespace esphome::sen21231_sensor
bool status_comm_result(bool ok)
Clears the warning when ok, else sets it with message (default "Communication failed"); returns ok.
bool read_bytes(uint8_t a_register, uint8_t *data, uint8_t len)
Compat APIs All methods below have been added for compatibility reasons.
Definition i2c.h:249
void publish_state(float state)
Publish a new state to the front-end.
Definition sensor.cpp:65
struct __attribute__((__packed__)) { person_sensor_results_header_t header; int8_t num_faces; person_sensor_face_t faces[PERSON_SENSOR_MAX_FACES_COUNT]; uint16_t checksum; } person_sensor_results_t
Definition sen21231.h:59
ESPHOME_LOG_TAG(TAG, "sen21231_sensor.sensor")