Open ambroribo opened 3 years ago
For every device you need monostable output: Start a timer in the callback funktion if the device is switched on and test for the time in the main loop. Set there the device to zero when time is off and call the callback again from the main loop.
Here an example
The time is calculated in milliseconds, 1000 for a second
#define TIMER 600 // = 0,6s
int32_t start, end;
uint8_t timer = 0; // set flag
void s_Callback(EspalexaDevice* d)
{
if (d->getPercent() > 0) // > 0 -> switch on/start
{
Serial.println(" ON");
// RELAIS_ON here;
timer = 1;
start = millis();
end = TIMER; // 0,6s
}
else
{
Serial.println(" OFF");
// RELAIS_OFF here);
timer = 0;
}
}
void loop()
{
......
if ( timer )
{
int32_t time = millis() - start; // running time since start
if ( time > end)
{
device->setValue(0); // relais off
device->doCallback(); // and go
timer = 0;
Serial.println("timer stopped");
}
}
......
}
thanks a lot for the help: it is OK . how could I change the device name from "red light" to " gate" and to see gate in the mobile app please ? Do I have to remove the device and try to device discover again ? what should I say to control the gate ? "Alexa turn_on gate " ? Is there a possibility to only say "alexa gate "? Thanks for all Bye
When you rename the device, two ways are possible:
"Alexa turn on gate" will do, i think (i speak german to alexa, so i do not know the exact english words to say)
Thanks Barneyz, it is working for me but the device status on the app does not reflect the real device status. Is your sketch reporting the rela device staus on the app ? Could you please check ? Thanks bye
No, the sketch is showing the last speech command to the device, not the real device status, but the device can be triggered by voice again. But with a monostable device the real state makes no sense. The device knows the state, there are examples with mqtt and espalexa you can find with google.
Why do you open another (same) issue #172, will you speed up things? This does not work! Plz close #172.
thanks for the explanation.
Bye
At the moment the sketch is used as " light " and so it has four "stable " states. How can we have the system operating in " mono stable " mode or " momentary " mode in order to control door_lock, power_gate and all other units that require a momentary pulse to be controlled ? Thanks for any help on the matter . Bye