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