From 8d318e7206203e70a7fd05ec56900f5802b24b2d Mon Sep 17 00:00:00 2001 From: Chris AtLee Date: Fri, 30 Oct 2020 15:18:27 -0400 Subject: [PATCH] Return remaining nightlight time in json API This returns the number of seconds remaining in the nightlight in the "rem" field of the nightlight ("nl") state. If there is no nightlight active, it returns -1. --- wled00/json.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/wled00/json.cpp b/wled00/json.cpp index 62c6a334..74217b10 100644 --- a/wled00/json.cpp +++ b/wled00/json.cpp @@ -318,7 +318,12 @@ void serializeState(JsonObject root) nl[F("fade")] = (nightlightMode > NL_MODE_SET); //deprecated nl[F("mode")] = nightlightMode; nl[F("tbri")] = nightlightTargetBri; - + if (nightlightActive) { + nl[F("rem")] = (nightlightDelayMs - (millis() - nightlightStartTime)) / 1000; // seconds remaining + } else { + nl[F("rem")] = -1; + } + JsonObject udpn = root.createNestedObject("udpn"); udpn[F("send")] = notifyDirect; udpn[F("recv")] = receiveNotifications; @@ -326,7 +331,7 @@ void serializeState(JsonObject root) root[F("lor")] = realtimeOverride; root[F("mainseg")] = strip.getMainSegmentId(); - + JsonArray seg = root.createNestedArray("seg"); for (byte s = 0; s < strip.getMaxSegments(); s++) {