Skip to content

Instantly share code, notes, and snippets.

@OttoWinter
Created May 25, 2018 19:42
Show Gist options
  • Save OttoWinter/ab9ec0b17c8f54a64db220af5b65b911 to your computer and use it in GitHub Desktop.
Save OttoWinter/ab9ec0b17c8f54a64db220af5b65b911 to your computer and use it in GitHub Desktop.
#include "esphomelib/application.h"
#ifdef ARDUINO_ARCH_ESP32
#include <WiFi.h>
#else
#include <ESP8266WiFi.h>
#endif
using namespace esphomelib;
// DEFINE CUSTOM SENSOR
class WiFiSignalSensor : public sensor::PollingSensorComponent {
public:
WiFiSignalSensor(const std::string &friendly_name, uint32_t update_interval)
: sensor::PollingSensorComponent(friendly_name, update_interval) {}
void update() override { push_new_value(WiFi.RSSI()); }
std::string unit_of_measurement() override { return "dB"; }
int8_t accuracy_decimals() override { return 2; }
};
void setup() {
// ===== DO NOT EDIT ANYTHING BELOW THIS LINE =====
// ========== AUTO GENERATED CODE BEGIN ===========
App.set_name("test");
App.init_log();
App.init_wifi("YOUR_SSID", "YOUR_PASSWORD");
App.init_ota()->start_safe_mode();
App.init_mqtt("MQTT_HOST", "USERNAME", "PASSWORD");
// =========== AUTO GENERATED CODE END ============
// ========= YOU CAN EDIT AFTER THIS LINE =========
auto *custom_sensor = App.register_component(new WiFiSignalSensor("Custom Sensor Example", 5000));
App.register_sensor(custom_sensor);
App.setup();
}
void loop() {
App.loop();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment