Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^3: Efficiency of indoor grow light timer

by holli (Abbot)
on Nov 12, 2017 at 20:35 UTC ( [id://1203238]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Efficiency of indoor grow light timer
in thread Efficiency of indoor grow light timer

No, you don't, you Stoner :-) But finding out wether a time in between a given interval or not is easy. Doing it this way saves you from having to deal with fixed switch times, which are, as you wrote, unreliable in case of outages or just the computer being shut down at the wrong moment.
use 5.24.1; use feature qw:signatures:; no warnings qw:experimental:; my @off_from = (22, 0, 0); #22:00:00 my @off_until = (08, 0, 1); #08:00:00 sub cmpt ( $a, $b ) { for ( 0 .. 2 ){ return $a->[$_] <=> $b->[$_] if $a->[$_] != $b->[$_] ; } return 0; } sub is_nighttime( $now ) { my @now = @{$now} || (localtime(time))[2,1,0]; if ( cmpt( \@off_from, \@off_until ) == 1 ) { # over midnight return cmpt(\@now, \@off_from) == 1 || cmpt( \@now, \@off_unti +l ) == -1; } else { # all same day return cmpt(\@now, \@off_from) == 1 && cmpt( \@now, \@off_unti +l ) == -1; } return 0; }
Edit: Removed C&P remnant
Edit: added code
Edit: added <=> (it's been a while)


holli

You can lead your users to water, but alas, you cannot drown them.

Replies are listed 'Best First'.
Re^4: Efficiency of indoor grow light timer
by stevieb (Canon) on Nov 12, 2017 at 21:39 UTC

    Heh ;)

    Full disclaimer and to be fully honest, I've been growing cannabis indoors and out for 25+ years. I have an issue with "Restless Leg Syndrome", and every day, moments before I go to sleep, I vaporize about three puffs of an indica-based strain that eradicates the problem in its entirety. I very rarely smoke or use it other than for that specific purpose (there's the odd time a family member or friend may be over and I'll roll a dube or use the bong, but that's a handful of times a year).

    I'm actually an outcast in my family relative to cannabis use, as many of them use it, some even daily for recreational purposes.

    Not that I need to explain myself, but my point here is that I use it legit for medicine, have for numerous years, and feel it should have been *de-criminalized* a long, long time ago. There are as many medicinal, economical (building materials, rope, clothing etc), ecological (supplants trees; hemp is a yearly reproduceable product, trees are not) and *insert many other benefits here*.

    I just went on a mission to get Perl, my favourite programming language, to be a part of this process.

    Now I can say this is one thing that Perl has done for me (see How has Perl affected you?). It helps with a decades-old issue that I have due to a severe injury I suffered many moons ago, and periodically the odd anxiety bout.

    Stoner? Sure. But a Perl-based Stoner :)

      No objections. What kind of automation system(s) do you use and how do you access it from Perl?


      holli

      You can lead your users to water, but alas, you cannot drown them.

        It's been a couple years-long process. I use my WiringPi::API to communicate with a Raspberry Pi in the backend, front-ended (API-wise) with my RPi::WiringPi distribution. I then laid on top of it App::RPi::EnvUI as the web-based, single-page front end to the entire system.

        I also wrote Async::Event::Interval to handle tasks that need to be run in parallel.

        Much of the core is C/XS based, such as the logic that controls the hygrometer, amongst other stuff.

        Not too long ago, I put together all of the hardware in a prototype that has 120v relays to control fans, humidifiers, and of course, the grow lamps. I still haven't found the time to put together a blog post about it, as we've got 6" of snow here and its consistently -15 degrees celsius where I now live (northern BC, Canada) so I'm just catching up on wood cutting for heat. I will though, sometime.

Re^4: Efficiency of indoor grow light timer
by stevieb (Canon) on Dec 12, 2017 at 00:11 UTC

    So after a month of testing, the compare code most definitely breaks after the clock switches past midnight. I hacked and played, but to no avail. I have reverted back to my original idea of comparing DateTime objects, that I documented in Benchmark routines earlier in the thread. Although the modules that 1nickt suggested were good ideas, they did not provide what I needed in the specific manner in which I needed them.

    So right now, I'm doing trials with this code starting at line 114 and ending at line 191. I have left the private functions immediately beneath the main method in this commit for clarity here. I've also made immortal the link by ensuring that the file is referenced to the commit itself.

    In all my testing so far, it works exactly how I need. I have two RPis running this code, both set with different times and time zones (and different "light on" times along with different "light on hours" times). We'll see what happens.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1203238]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-04-24 19:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found