ChipChop Support Forum
Log in
Log out
Join the forum
My Details
REPLIES: 2
VIEWS: 216
BACK
REPLY TO THIS POST
Andrea
02 Feb 2024
Timers question
Hello,

Is it possible to create a timer action? What I mean is there is no option to make something happen at a certain time. I really don't know how to explain this!

Let say I want the night light in my kids bedroom to turn on at 8PM (and turn off at 6AM)

1. The option I have is to use "Time Is: Between" in the action and set it between 20:00 and 20:00, I have tried that but it will run the action 5-6 times because of the 10 sec heartbeat so I have to test on the ESP32 that I am not repeating the off "digitalWrite(pin.LOW)" more than once in a minute.

That's the first problem, it's ok if it's something like this night light that should only come on automatically. But if I had something that can also be switched on/off manually than if I have the test for "don't repeat this more than once a minute" I wouldn't be able to switch it quickly on/off more than once a minute!

2. You have to use something to "trigger" the action so I have to use the light component for that but then I can't set the "target" to be the same light only the entire device and that can be a problem if you have many components that should also react to "ON/OFF"

Wouldn't it be more logical to simply say at 8PM set the Night Light's light component to OFF?

I don't know, it sounds like a very simple thing and I am surprised that it doesn't exists in ChipChop !? Is there something I am not aware of or I am just using actions in a wrong way? How would you accomplish what I have described?

Thezzi Mfkr
03 Feb 2024

honestly, I had to re-read your post twice to figure out what you were on about!

You basically want a "scheduler"!

I agree it would be nice to have one but I guess there is some valid reason why it's not available. But, it can be done and I do it all the time.

You are obviously not resetting whatever you are using to trigger the light and that's why it keeps firing the same thing over and over again until the minute lapses (funny enough there is a reply from today going through this but for notifications
https://forum.chipchop.io/post/310/)

Without seeing your code I can't really be more detailed but I imagine you do something like:

If at 8PM the Night Light is OFF, send a command to switch it ON...right?

But I have a feeling that when you get the command to the light you don't send back the status ON quickly enough or at all and that's why the action keeps repeating....think about how the whole thing flows and you will have the "light bulb" moment (<<<pun intended!!!)

Your point 2...the answer is not to use the same device! :-) or have the commands sent to be prefixed like "light1_ON", it's all just strings so you can check that in the device code easily. The fact that you get a nice "target component" & "target value" is a convenience but nothing is stopping you from making your own custom logic.

I am sure gizmo will reply to this at some point quoting some rules and technical mumbo-jumbo but in general I do agree that having some form of "scheduler" would be nice

Gizmo
04 Feb 2024

Hi guys

Sorry for not replying earlier but I wanted to have a proper think about this first before answering.

I have thought about a scheduler option loooong time ago but it's a definite no-no in a traditional sense.
ChipChop is a managed platform that has to choreograph communication between thousands of devices... in real-time!... and to check every minute the entire database for potentially thousands (millions) of watering the cabbage alarms and start the cat feeder could put an insane pressure on the engines.

On most "sane" platforms things like that are usually offloaded onto the client. I am not saying that there is anything sane about ChipChop (heck I'm proud of it) but I think I may have a solution using a similar methodology.

Here's a rough concept:

- Your "scheduler" will be driven by the device heartbeat that you want to send some command at a specific time.
The logic here is simple, if the device is not live and connected then there is no point checking for an alarm to send it something. If it's live and has a heartbeat then it's just another custom type of action that needs to be checked and executed.

- Not sure if you should have an IF condition or just a "fire and forget" or both?
Like, in your case, should I bother doing the logic on ChipChop's side or leave it for you to handle. i.e. IF a Night Light > Light is ON then at 8PM -> send command to Light component -> OFF?
Or should it be: it's 8PM -> Night Light -> Light -> OFF
Or 8PM -> Night Light -> send command "8PM alarm"

- I will keep it as a part of Actions but maybe when I have the time I may redesign the section so you can have different categories to make it more manageable

Let me know what you think, I won't be implementing this in a hurry as there is already a functional workaround but it would be a nice touch and make things more user friendly