From 9cbe8dcdf5586c86a52aca2641f9be2be9495c09 Mon Sep 17 00:00:00 2001 From: Yonsm Date: Mon, 10 Sep 2018 14:41:50 +0800 Subject: [PATCH 1/2] Call wakeUp PMS on first reading cycle to avoid not data in a long period (e.g. PMS entered sleeping and then espurna reboot, we should wake up PMS right now) --- code/espurna/sensors/PMSX003Sensor.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/code/espurna/sensors/PMSX003Sensor.h b/code/espurna/sensors/PMSX003Sensor.h index 9f6ddd4b..7407c699 100644 --- a/code/espurna/sensors/PMSX003Sensor.h +++ b/code/espurna/sensors/PMSX003Sensor.h @@ -269,6 +269,9 @@ class PMSX003Sensor : public BaseSensor, PMSX003 { } } else { readCycle = -1; + if (_readCount == 1) { + wakeUp(); + } } #endif From 3e1031ab7c30b4f0ef5d2ca96e5a5b72a32b2025 Mon Sep 17 00:00:00 2001 From: Yonsm Date: Mon, 10 Sep 2018 15:33:39 +0800 Subject: [PATCH 2/2] define HOMEASSISTANT_PAYLOAD_AVAILABLE and HOMEASSISTANT_PAYLOAD_NOT_AVAILABLE --- code/espurna/config/general.h | 8 ++++++++ code/espurna/homeassistant.ino | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/code/espurna/config/general.h b/code/espurna/config/general.h index 4df05781..eb284f92 100644 --- a/code/espurna/config/general.h +++ b/code/espurna/config/general.h @@ -919,6 +919,14 @@ #define HOMEASSISTANT_PAYLOAD_OFF "0" // Payload for OFF and unavailable messages #endif +#ifndef HOMEASSISTANT_PAYLOAD_AVAILABLE +#define HOMEASSISTANT_PAYLOAD_AVAILABLE "1" // Payload for available messages +#endif + +#ifndef HOMEASSISTANT_PAYLOAD_NOT_AVAILABLE +#define HOMEASSISTANT_PAYLOAD_NOT_AVAILABLE "0" // Payload for available messages +#endif + // ----------------------------------------------------------------------------- // INFLUXDB // ----------------------------------------------------------------------------- diff --git a/code/espurna/homeassistant.ino b/code/espurna/homeassistant.ino index 52fe5c6c..593f4cdb 100644 --- a/code/espurna/homeassistant.ino +++ b/code/espurna/homeassistant.ino @@ -87,8 +87,8 @@ void _haSendSwitch(unsigned char i, JsonObject& config) { config["payload_on"] = String(HOMEASSISTANT_PAYLOAD_ON); config["payload_off"] = String(HOMEASSISTANT_PAYLOAD_OFF); config["availability_topic"] = mqttTopic(MQTT_TOPIC_STATUS, false); - config["payload_available"] = String(HOMEASSISTANT_PAYLOAD_ON); - config["payload_not_available"] = String(HOMEASSISTANT_PAYLOAD_OFF); + config["payload_available"] = String(HOMEASSISTANT_PAYLOAD_AVAILABLE); + config["payload_not_available"] = String(HOMEASSISTANT_PAYLOAD_NOT_AVAILABLE); } #if LIGHT_PROVIDER != LIGHT_PROVIDER_NONE