Hi Folks.
Please could you help me? I am having some issues getting mInput(LightSlot)=0, or mInput(LightSlot)=Souliss_T1n_OffCmd to work on a Nodemcu (ESP8266 12e-01) module.
I am trying to get a light to turn off after a certain time. (The AUTOLIGHT feature did not work for me so I am trying a different approach)
The use case is:
1. Turn light on with Souliss app (or capsense button) if it is darker that the LDR threshold.
2. PIR keeps light on while there is someone present (and moving)
3. When movement stops, a timer counts down to a set threshold.
4. When the threshold is reached the light switches off.
(I will be duplicating this setup for a fan.)
Here is the snippet that I am having trouble with.
The "if" statement evaluates correctly because the debug code runs perfectly.
if(LIGHTTIMER > 0){// If the LIGHTTIMER is greater than 0, run the countdown logic to switch the light off.
OnTime1 = (LIGHTTIMER * 1000);
if(millis() - PreviousMillis >= OnTime1 && mOutput(LIGHTSLOT) == 1 ){
mInput(LIGHTSLOT) = 0; // Turn off the light. I initially tried mInput(LightSlot)=Souliss_T1n_OffCmd but it did also not work
if (Debug.ative(Debug.DEBUG)){
Debug.println("------------------------------------------------------");
Debug.print("mOutput(LIGHTSLOT) --- ");
Debug.print("\t");
Debug.println(mOutput(LIGHTSLOT));
Debug.print("Previous Millis --- ");
Debug.print("\t");
Debug.println(PreviousMillis);
Debug.print("Millis --- ");
Debug.print("\t\t");
Debug.println(millis());
Debug.print("OnTime1 --- ");
Debug.print("\t\t");
Debug.println(OnTime1);
Debug.print("Millis-PrevMillis --- ");
Debug.print("\t");
Debug.println(millis() - PreviousMillis);
delay(100);
}
}
}
When I move the mInput(LIGHTSLOT) =0 to this piece of code, It works as expected by switching the light off immediately after switching it on.
if(mOutputAsFloat(LDRSLOT) < LDRTHRESHOLD){//Only allow the light to be turned on below LDR threshold.
Logic_SimpleLight(LIGHTSLOT); //Logic to drive the light.
nDigOut(LIGHTOUTPUTPIN, Souliss_T1n_Coil, LIGHTSLOT);
mInput(LIGHTSLOT) = Souliss_T1n_OffCmd;
}
Would you need to see the whole sketch ?