Skip to content

Commit 8d318e7

Browse files
committed
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.
1 parent b8fcab2 commit 8d318e7

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

wled00/json.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,15 +318,20 @@ void serializeState(JsonObject root)
318318
nl[F("fade")] = (nightlightMode > NL_MODE_SET); //deprecated
319319
nl[F("mode")] = nightlightMode;
320320
nl[F("tbri")] = nightlightTargetBri;
321-
321+
if (nightlightActive) {
322+
nl[F("rem")] = (nightlightDelayMs - (millis() - nightlightStartTime)) / 1000; // seconds remaining
323+
} else {
324+
nl[F("rem")] = -1;
325+
}
326+
322327
JsonObject udpn = root.createNestedObject("udpn");
323328
udpn[F("send")] = notifyDirect;
324329
udpn[F("recv")] = receiveNotifications;
325330

326331
root[F("lor")] = realtimeOverride;
327332

328333
root[F("mainseg")] = strip.getMainSegmentId();
329-
334+
330335
JsonArray seg = root.createNestedArray("seg");
331336
for (byte s = 0; s < strip.getMaxSegments(); s++)
332337
{

0 commit comments

Comments
 (0)