OpenSprinkler Forums Hardware Questions controlling an unused zone

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #46138

    jjrushford
    Participant

    Greetings,

    I am using the OpenSprinkler version 2.1.7 to operate my 7 zone sprinkler system. I have schedules setup and all is working fine. My opensprinkler pi is mounted in a cabinet on the side of my house near the sprinkler valves and I’ve noticed that the cpu temperature nears 80C on a hot day. I’d like to use the currently unused 8th zone to power on a 24vac computer fan that I would install in the cabinet to help cool the rpi. With version 2.1.7 can I send commands to switch on and off zone 8 such that the opensprinkler firmware will not interfere by resetting this unused zone off? The idea would be to run a cron job every 5 minutes and depending on the cpu temperature, the script would switch on or off zone 8 which controls the fan. Can I do this without interfering with my watering schedules? Potentially, I might have two zones on at once, any of the 7 operating sprinkler valves and the 8th running a 24vac fan. can the ospi handle driving both a fan and a valve simultaneously?

    thanks
    John
    [email protected]

    #46152

    jjrushford
    Participant

    Well I’m going to try this. I’ve ordered a new outdoor vented electronics enclosure that has a rain hood on the door. Inside the door behind the rain hood is a mount for a 120mm fan. I’ve found a 120mm 24vac fan on ebay that should do nicely. I’ve already written a perl script that utilizes the OpenSprinkler 2.1.7 firmware API that will check the raspberry pi cpu temperature and start the fan whenever the temperature is above 40C. If anyone is interested, I’ll post pictures and the script here when I’m done.

    #46322

    Ray
    Keymaster

    If you set the unused zone as ‘parallel’ — in other words, turn off it’s ‘sequential’ flag, then you can send command to it to turn it on or off at any time. By default, all zones have the ‘sequential’ flag on. With the sequential flag on, if there is any other zone running (or scheduled to run), it will be serialized (which is probably ok because it will run eventually when the other zones finish running). However, if you don’t want it to be serialized with other zones, turning the sequential flag off would do it.

    #46417

    jjrushford
    Participant

    I have it running and I left it in the sequential state as this works out pretty well. I ended up installing this in a outside electronics enclosure with a rain hood on the side of my house. The fan mount was for an 80mm fan so, I bought a 12vdc 80mm fan and a small power supply, 24vac input with 12vdc output, to power the fan when the 24vac is switched on by zone 8. The fan lowers the temp during the day by about 10c. I wrote the following perl script that is run from cron every 5 minutes. It checks the cpu temp on the pi and starts the fan using zone 8 to keep the pi cool.

    chkRpiTemp:

    
    #!/usr/bin/perl
    #
    # Checks the raspberry pi cpu temperature and turns on a fan 
    # connected to one of the opensprinkler zones.
    #
    # Uses OpenSprinkler Firmware 2.1.7 API for station i/o.
    #
    
    use LWP::Simple;
    use JSON qw(decode_json);
    use POSIX qw(strftime);
    use Data::Dumper;  # for debugging.
    use strict;
    use warnings;
    
    my $base_url = "http://127.0.0.1/";  # base api url.
    my $duration = 600;   # run the fan for this number of seconds.
    my $fan_station = 7;  # fan is controlled by this station, stations are 0 to 7.
    my $hi_temp = 45;     # start the fan when the cpu temp is this or higher.
    my $pw = "f6d2aec0621aa5110240ca144520bdea";  # MD5 hash of opensprinkler password.
    my $temp_file = '/sys/devices/virtual/thermal/thermal_zone0/temp';
    
    # log messages.
    sub logMessage {
      my $_msg = shift;
      my $_tm = strftime('%b %d %C%y %H:%M:%S', localtime());
      print "$_tm - $_msg\n";
    }
    
    #
    # Reads and returns the raspberry pi cpu temperature
    sub getTemp {
      my $_centigrade = 0;
      my $_fahrenheit = 0; 
    
      open(my $fh, '<:encoding(UTF-8)', $temp_file)
        or die "Could not open file '$temp_file' $!";
      
      while(my $_t = <$fh>) {
        chomp $_t;
        $_centigrade = $_t / 1000.00;
        $_fahrenheit = (($_centigrade * 1.8) + 32);
      }
      close($fh);
    
      return (sprintf("%.2f",$_centigrade), sprintf("%.2f",$_fahrenheit));
    }
    
    # read the state of the station that controls the fan.
    sub getFan {
      my $_url = $base_url . "js?pw=$pw";
      my $_json = get($_url);
      my $_decoded_json = decode_json($_json);
      return $_decoded_json->{'sn'}[$fan_station];
    }
    
    # set the fan station on or off.
    sub setFan {
      my $_state = @_;
      my $_url = $base_url;
    
      if ($_state == 0) {
        $_url = $_url . "cm?pw=$pw&sid=$fan_station&en=0";
      }
      elsif ($_state == 1) {
        $_url = $_url . "cm?pw=$pw&sid=$fan_station&en=1&t=$duration";
      }
      else {
        logMessage("setFan(): invalid state $_state");
        return;
      }
      my $_json = get($_url);
      my $_decoded_json = decode_json($_json);
    
      return $_decoded_json->{'result'};
    }
    
    my ($temp_c,$temp_f)  = getTemp();
    
    # if the cpu temp has reached the hi temperature setting,
    # turn on the fan.
    my $fan = getFan();
    if ($temp_c >= $hi_temp) {
    
      if ($fan == 0) {
        my $result = setFan(1);
        if ($result == 1) {
          logMessage("cpu temperature is ${temp_c}C (${temp_f}F), fan started.");
        } else {
          logMessage("cpu temperature is ${temp_c}C (${temp_f}F), error starting fan.");
        }
      } else {
        logMessage("cpu temperature is ${temp_c}C (${temp_f}F), fan is already running.");
      }
    } else {
      if ($fan == 0) {
        logMessage("cpu temperature is ${temp_c}C (${temp_f}F), the fan is off.");
      } elsif ($fan == 1) {
        logMessage("cpu temperature is ${temp_c}C (${temp_f}F), the fan is running.");
      }
    }
    
    #46700

    Ray
    Keymaster

    Cool. Thanks for sharing!

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.

OpenSprinkler Forums Hardware Questions controlling an unused zone