5 namespace binary_sensor_map {
7 static const char *
const TAG =
"binary_sensor_map";
26 float total_current_value = 0.0;
27 uint8_t num_active_sensors = 0;
33 for (
size_t i = 0; i < this->
channels_.size(); i++) {
35 if (bs.binary_sensor->state) {
37 total_current_value += bs.parameters.sensor_value;
46 float publish_value = total_current_value / num_active_sensors;
51 ESP_LOGV(TAG,
"'%s' - No binary sensor active, publishing NAN", this->
name_.
c_str());
59 float total_current_value = 0.0;
65 for (
size_t i = 0; i < this->
channels_.size(); i++) {
67 if (bs.binary_sensor->state) {
68 total_current_value += bs.parameters.sensor_value;
87 for (
size_t i = 0; i < this->
channels_.size(); i++) {
90 posterior_probability *=
92 bs.parameters.probabilities.given_true, bs.parameters.probabilities.given_false);
94 mask |= ((uint64_t) (bs.binary_sensor->state)) << i;
106 float prob_given_false) {
107 float prob_state_source_true = prob_given_true;
108 float prob_state_source_false = prob_given_false;
112 prob_state_source_true = 1 - prob_given_true;
113 prob_state_source_false = 1 - prob_given_false;
116 return prob_state_source_true / (prior * prob_state_source_true + (1.0 - prior) * prob_state_source_false);
123 .sensor_value = value,
126 this->
channels_.push_back(sensor_channel);
134 .given_true = prob_given_true,
135 .given_false = prob_given_false,
139 this->
channels_.push_back(sensor_channel);
void add_channel(binary_sensor::BinarySensor *sensor, float value)
Add binary_sensors to the group when only one parameter is needed for the configured mapping type...
binary_sensor::BinarySensor * binary_sensor
void dump_config() override
void loop() override
The loop calls the configured type processing method.
std::vector< BinarySensorMapChannel > channels_
void publish_state(float state)
Publish a new state to the front-end.
float bayesian_predicate_(bool sensor_state, float prior, float prob_given_true, float prob_given_false)
Computes the Bayesian predicate for a specific observation If the sensor state is false...
constexpr const char * c_str() const
Implementation of SPI Controller mode.
bool has_state() const
Return whether this sensor has gotten a full state (that passed through all filters) yet...
Base class for all binary_sensor-type classes.
BinarySensorMapType sensor_type_
void process_group_()
Methods to process the binary_sensor_maps types.
esphome::sensor::Sensor * sensor