diff --git a/src/sensesp/sensors/constant_sensor.h b/src/sensesp/sensors/constant_sensor.h index a433e7c33..6341d23f5 100644 --- a/src/sensesp/sensors/constant_sensor.h +++ b/src/sensesp/sensors/constant_sensor.h @@ -57,12 +57,15 @@ class ConstantSensor : public Sensor { : Sensor(config_path), value_{value}, send_interval_{send_interval} { this->load_configuration(); + // Emit the initial value once to set the output + ReactESP::app->onDelay(0, + [this]() { this->emit(value_); }); + // Then, emit the value at the specified interval ReactESP::app->onRepeat(send_interval_ * 1000, [this]() { this->emit(value_); }); } - void set_value(T value) { value_ = value; } - T get_value() { return value_; } + void set(T value) { value_ = value; } protected: virtual void get_configuration(JsonObject &doc) override {