I am building a small temperature management system.
(Ce n’est pour l’instant qu’un test, donc le codes ets un peu en bazard)
The principle is simple, I try to manage the temperature according to cycles that I call ON and OFF. In ON I need X temperature and in OFF I need Y temperature.
I have a cycle management button (cycle 1: 18 hours and cycle 2: 12 hours) and a variable for the start time.
I wrote my code so that if I choose 11 a.m. the cycle stops at 11 p.m. There everything is fine but if I choose the start of the cycle at 3 p.m. it will stop at 3 a.m. Since I use the RTC clock in 24H my function cannot work. (I put a copy of code to better understand)
What would be the best solution? Set up a timer?
I need your opinions and your solutions.
(if you need more details don’t hesitate to ask me!
use automations run your code to read your data at select times rather then coding to only read at specific times. Will make your code wayyyy easier to adjust accordingly. Just go to automations and enable a switch to start turn the sensor reading on and then pick the time for when to run it you can set 5 weekly automation with free blynk
Let me give you an insight into what happens in my mind when I start reading your original post…
What button?
Is it a physical button? If so is it attached to the master or slave device, and if so to which pin. Is it normally HIGH OR LOW.
Or, is it a button widget? If so is it attached to a digital or virtual pin, and which pin is this?
What is this variable for the start time? Is it a variable within the sketch, and if so which one?
Or is it a variable that’s associated with a widget?
So, from this one sentence I have multiple questions, that aren’t answer by having a quick glance at the code because that contains no in-code documentation.
At this point I ask myself why you aren’t using the time input widget, or maybe two time input widgets and a switch to change between one set of times and another, but decide that I don’t really want to get into that discussion, and move on.
So when I say:
It doesn’t mean that I want to to repeat what you’ve already said, it means that you need to provide significantly more new, additional and not previously provided information, which I don’t really feel like trying to extract from you one drop at a time.
I think you’re missing the point. This was just one example of the gaps in the information that you’ve provided. You have to look at the data you are providing from the point of view of someone who has no information about what you are trying to achieve, and provide all of that data in a structured format, with screenshots and code as appropriate, if you want people to get on board with assisting you.
You don’t even explain that you are using Blynk Legacy with a local server, or the type of hardware that you’re using, which would help to avoid people wasting their time with suggestions that aren’t appropriate to your situation.
You have to help others to help you, and for that you need to provide significantly more information.
timeOff (which is equal to timeOn + 18 hours or 12 hours with a selection by a switch) → SETUP CYCLE
cycle status ( cycleOn and cycleOff ) → CYCLE STATUS
And send its information via LED
Works with RTC
The code works, but isn’t perfect. I would like to check the hours from timeOn to timeOff regardless of what time the cycle starts
Let cycleOn start at timeOn and 12 or 18 hours RTC later go to cycleOff.
My problem is that when the cycle is OFF I have a return cycleOn and cycleOff each time the loop etatCycle is read
That’s because you are changing the value of the cycleOn Variable in your first if statement, which makes the second if statement evaluate as true as well.
You need a return command at the end of your first if statement so that the second if statement isn’t executed if the first one evaluates as true.
As I’ve said before, if you describe the big picture overview of what you are trying to achieve and why, instead of getting bogged-down in the details of why your current approach isn’t working, then you may get further.
I suspect that it would be far better to use the time input widget or timer widget to achieve your goals, but you haven’t yet explained what your goals are.
I can’t really talk about this project on the forum but I can explain it to you in DM. I am not sure that people appreciate this kind of project but it is necessary for my health.
I need to make an indoor garden. For that I must be able to have a light management (lamp).
The cycles correspond to the time of sunshine necessary for growth (18 hours per day) and flowering (12 hours per day).
So I need to control the cycle ( cycleOn or cycleOff ) of lighting. And the lighting time (timeOn and timeOff ).
I also need the slider to choose when to start the cycle
Because I don’t know what is the best solution. and that I don’t know the others
It seemed to me to be the best solution, and because of my reduced capacity I try to make an analogy (with for example the thermostat slider which sets a temperature, so why not a departure time)