Any way to get a timed button?

I can not add the timer library, someone has something simpler

Ah, sorry I missed that you were using a Pi. With the Pi unfortunately the only way to do that is to use the MQTT API. Are you familiar with programming Python?

Any update on adding this to the standard dashboard? It seems with the release of MQTT it has been possibly put on hold. It’s just that I’m not familiar with Python - I actually know a bit more about Arduino but this particular project I’m working on moved to the Pi so I’m kind of stuck with it for now. This is actually all that is missing for me is a timed button with enough granularity of control that it could be considered a momentary switch for one widget and be able to latch another switch for ~30 seconds for another widget.

Being able to do that would make the project complete and I could start rolling it out. If there isn’t plans for it anymore that’s fine, just curious how long I can hold off learning MQTT :smile:

this feature is kept on hold for some time as we had other high priority features that we released in the last couple of months. we have this on our roadmap and will be done in 3rd quarter.
if you want some help with your python code, then let me know. i will try and have a code for you.

1 Like

Check out my article on setting up the Anova with MQTT here.

Python and MQTT doesn’t have to be painful.

Also, user @STLWaffles posted code and improvements here in Github - with my permission.

Cheers,

Craig

1 Like

I ran into the same issue trying to get an esp8266 to run my hydroponics I needed to run pumps and relays for a few seconds to a min. I worked with what I had and came up with the following.

I made a button to create an auto routine and attached it to a virtual pin address. I then had that pin enable a variable that togged on an if statement in the main loop. I then added sliders that let me set the duration in seconds in Cayenne basically the slider submits a number in seconds to the input which I multiply by 1000 and store as the variable I calculate millis against. This method should allow you to not only set fixed time on/off’s but set the times from the mobile and web app. (you can ignore the u8x8 lines those just pop stuff on the OLED screen.)

See below for an abstract of my code.

int PumpCycle = 0;

#define PUMPCYCLE 10
#define PUMPDUR 11
#define PUMPINT 12
#define WATER_PIN 0

unsigned long lastMillis = 0;
unsigned long pumpInterval = 60000;
unsigned long pumpLastInterval = 0;
unsigned long pumpDuration = 10000;

void loop() {
Cayenne.loop();
//Publish data every 5 seconds (5000 milliseconds). Change this value to publish at a different interval.
if (PumpCycle == 1 && millis() - pumpLastInterval > pumpInterval) {
pumpLastInterval = millis();
digitalWrite(WATER_PIN, HIGH);
Serial.println(“PumpCycle On”);
u8x8.setFont(u8x8_font_lucasarts_scumm_subtitle_o_2x2_r);
u8x8.setCursor(0, 11);
u8x8.clearDisplay();
u8x8.print(“PumpCycle”);
}
else if (PumpCycle == 1 && millis() - pumpLastInterval > pumpDuration) {
digitalWrite(WATER_PIN, LOW);
}

CAYENNE_IN(PUMPCYCLE)
{
// Write pump cycle routine.
if (getValue.asInt() == 0) {
PumpCycle = 0;
digitalWrite(WATER_PIN, LOW);
Serial.println(“Pump Auto Off”);
u8x8.setFont(u8x8_font_lucasarts_scumm_subtitle_o_2x2_r);
u8x8.setCursor(0, 11);
u8x8.clearDisplay();
u8x8.print(“AutoOff”);

}
else {
PumpCycle = 1;
Serial.println(“Pump Auto On”);
Serial.println(PumpCycle);
u8x8.setFont(u8x8_font_lucasarts_scumm_subtitle_o_2x2_r);
u8x8.setCursor(0, 11);
u8x8.clearDisplay();
u8x8.print(“Auto On”);
}
}
CAYENNE_IN(PUMPDUR)
{
// Write pump cycle var.
pumpDuration = (getValue.asInt()* 1000);
Serial.println(“Pump Dur set:”);
Serial.println(pumpDuration);
}
CAYENNE_IN(PUMPINT)
{
// Write pump cycle var.
pumpInterval = (getValue.asInt()* 1000);
Serial.println(“Pump Interval set:”);
Serial.println(pumpInterval);
}

1 Like

Nice project and good idea to use slider as timer. But there is no timed button currently.

Oh I am aware of that I was just showing how you could make a workaround in the arduino. You can just create a routine in the main loop and have cayenne send a button command to activate it. If you wanted the button for example to pulse a relay for 250ms and reset. You could even have the end line send a signal back to Cayenne as a sensor and trigger an event to turn the button off resetting it automatically. Its a convoluted way to get a pulsed button for things like a garage door. But it works for now until the devs can work out the real deal. Thought it might help other people trying to get a timed function less than 1hr or a pulsed event. There might be a better way but thats what I came up with :slight_smile:

1 Like

Nice workaround and thanks for sharing it.