I'm working on an ESPHome component that publishes three text sensors:
char buf[24];
if (this->remote_id_sensor_ != nullptr) {
snprintf(buf, sizeof(buf), "%llu", (unsigned long long) remote_id);
this->remote_id_sensor_->publish_state(buf);
}
if (this->button_sensor_ != nullptr) {
snprintf(buf, sizeof(buf), "%u", (unsigned) button);
this->button_sensor_->publish_state(buf);
}
if (this->rolling_code_sensor_ != nullptr) {
snprintf(buf, sizeof(buf), "%u", (unsigned) rolling);
this->rolling_code_sensor_->publish_state(buf);
}
}
The three values are all know at the same time and are related, so it's really one bit of data.
There's no guarantee that all three will be updated in Home Assistant before any state-change events fire, correct?
Seems like I have two options.
- Replace the existing three sensors with one that combines the data someway so there's only one publish.
- Have the component issue and event passing the three values and enable
homeassistant_services. And then automations should use the event approach.
Is there another approach?