ESPHome 2025.5.2
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
demo_binary_sensor.h
Go to the documentation of this file.
1#pragma once
2
5
6namespace esphome {
7namespace 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
This class simplifies creating components that periodically check a state.
Definition component.h:301
Base class for all binary_sensor-type classes.
void publish_initial_state(bool state)
Publish the initial state, this will not make the callback manager send callbacks and is meant only f...
void publish_state(bool state)
Publish a new state to the front-end.
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7