ESPHome 2026.5.1
Loading...
Searching...
No Matches
demo_binary_sensor.h
Go to the documentation of this file.
1#pragma once
2
5
6namespace esphome::demo {
7
9 public:
10 void setup() override { this->publish_initial_state(false); }
11 void update() override {
12 bool new_state = last_state_ = !last_state_;
13 this->publish_state(new_state);
14 }
15
16 protected:
17 bool last_state_ = false;
18};
19
20} // namespace esphome::demo
This class simplifies creating components that periodically check a state.
Definition component.h:602
Base class for all binary_sensor-type classes.
void publish_state(bool new_state)
Publish a new state to the front-end.
void publish_initial_state(bool new_state)
Publish the initial state, this will not make the callback manager send callbacks and is meant only f...