From 9b1ecf73ceb617ef9325de20e5d5e2e3077d4e30 Mon Sep 17 00:00:00 2001 From: Nicu Hodos Date: Wed, 4 Jun 2025 17:14:14 +0200 Subject: [PATCH 1/5] add sensor for wifi signal strength --- library.json | 2 +- src/esp.h | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/library.json b/library.json index e79e522..9885b79 100644 --- a/library.json +++ b/library.json @@ -1,7 +1,7 @@ { "$schema": "https://raw.githubusercontent.com/platformio/platformio-core/develop/platformio/assets/schema/library.json", "name": "ha-mqtt", - "version": "1.6.0", + "version": "1.7.0", "description": "Home Assistant classes for integration with MQTT auto discovery", "repository": { "type": "git", diff --git a/src/esp.h b/src/esp.h index 4dd511b..2987e4f 100644 --- a/src/esp.h +++ b/src/esp.h @@ -1,5 +1,6 @@ #pragma once +#include #include "TaskScheduler.h" #include "ha.h" @@ -9,6 +10,7 @@ namespace HaESP { struct { bool heapStats = false; bool restartInfo = false; + bool wifiInfo = false; } activeSensors; Task tHeap(5 * TASK_MINUTE, TASK_FOREVER, []() { @@ -28,6 +30,10 @@ namespace HaESP { Sensor::mapSensors["restart_reason"]->updateState(ESP.getResetReason().c_str()); }, &ts); + Task tWifi(3 * TASK_MINUTE, TASK_FOREVER, []() { + Sensor::mapSensors["wifi_signal_strength"]->updateState(to_string(WiFi.RSSI()).c_str()); + }, &ts); + template Builder& heapStats(Builder& builder) { auto heap = new Sensor{ "Heap fragmentation", "heap_fragmentation" }; @@ -60,6 +66,19 @@ namespace HaESP { return builder; } + template + Builder& wifiInfo(Builder& builder) { + builder.addDiagnostic(Builder::instance(( + new Sensor{ "WiFi Signal (RSSI)", "wifi_signal_strength" })) + .withDeviceClass("signal_strength") + .withUnitMeasure("dBm") + .withPrecision(0) + .build() + ); + activeSensors.wifiInfo = true; + return builder; + } + Builder