5 namespace binary_sensor_map {
7 static const char *
const TAG =
"binary_sensor_map";
20 float total_current_value = 0.0;
21 uint8_t num_active_sensors = 0;
25 for (
size_t i = 0; i < this->
channels_.size(); i++) {
27 if (bs.binary_sensor->state) {
29 total_current_value += bs.sensor_value;
37 float publish_value = total_current_value / num_active_sensors;
38 ESP_LOGD(TAG,
"'%s' - Publishing %.2f", this->
name_.c_str(), publish_value);
43 ESP_LOGD(TAG,
"'%s' - No binary sensor active, publishing NAN", this->
name_.c_str());
52 .sensor_value = value,
54 this->
channels_.push_back(sensor_channel);
void add_channel(binary_sensor::BinarySensor *sensor, float value)
Add binary_sensors to the group.
void set_sensor_type(BinarySensorMapType sensor_type)
binary_sensor::BinarySensor * binary_sensor
void dump_config() override
void loop() override
The loop checks all binary_sensor states When the binary_sensor reports a true value for its state...
std::vector< BinarySensorMapChannel > channels_
void publish_state(float state)
Publish a new state to the front-end.
Base class for all binary_sensor-type classes.
BinarySensorMapType sensor_type_
void process_group_()
methods to process the types of binary_sensor_maps GROUP: process_group_() just map to a value ...