Exemplo n.º 1
0
def startpump(target, activationseconds, MinAveragetemp, MaxAverageHumid):

    logger.info('WateringPlan Startpump evaluation: %s', target)
    #workmode=autowateringmod.checkworkmode(target)
    #if workmode=="Full Auto":
    if target in autowateringmod.allowwateringplan:
        if not autowateringmod.allowwateringplan[target]:
            logger.info(
                'WateringPlan: %s pump activation blocked by automation',
                target)
            pumpit = False
            return False

    duration = hardwaremod.toint(activationseconds, 0)
    print(target, " ", duration, " ", datetime.now())

    # evaluate parameters
    #MinAverageLight=500 not used now
    MinutesOfAverage = 120  #minutes in which the average data is calculated from sensor sampling

    print("waterpump check")
    logger.info('execute water pump check %s',
                datetime.now().strftime("%Y-%m-%d %H:%M:%S"))

    # then check the temperature and Humidity

    print("Check Humidity and Temperature")

    MinAveragetempnum = hardwaremod.tonumber(MinAveragetemp, "NA")
    MaxAverageHumidnum = hardwaremod.tonumber(MaxAverageHumid, "NA")

    # all the below conditions should be verified to start the PUMP
    pumpit = True

    hsensornamelist = hardwaremod.getsensornamebymeasure(
        hardwaremod.MEASURELIST[1])
    if hsensornamelist:
        sensordata = []
        hsensorname = hsensornamelist[0]  # get first found sensor in the list
        sensordbmod.getsensordbdata(hsensorname, sensordata)
        starttimecalc = datetime.now() - timedelta(
            minutes=int(MinutesOfAverage))
        isok, quantitylist = sensordbmod.EvaluateDataPeriod(
            sensordata, starttimecalc, datetime.now())
        humquantity = quantitylist["average"]

        logger.info(
            'Waterpump Check parameter if humquantity=%s < MaxAverageHumid=%s ',
            str(humquantity), str(MaxAverageHumid))
        print('Waterpump Check parameter if humquantity=', humquantity,
              ' < MaxAverageHumid=', MaxAverageHumid)

        if (MaxAverageHumidnum != "NA"):
            if (humquantity < MaxAverageHumidnum):
                logger.info(
                    'Humidity check PASSED, humquantity=%s < MaxAverageHumid=%s ',
                    str(humquantity), str(MaxAverageHumid))
            else:
                logger.info('Humidity check FAILED')
                print('Humidity check FAILED')
                pumpit = False

    tsensornamelist = hardwaremod.getsensornamebymeasure(
        hardwaremod.MEASURELIST[0])
    if tsensornamelist:
        sensordata = []
        tsensorname = tsensornamelist[0]  # get first found sensor in the list
        sensordbmod.getsensordbdata(tsensorname, sensordata)
        starttimecalc = datetime.now() - timedelta(
            minutes=int(MinutesOfAverage))
        isok, quantitylist = sensordbmod.EvaluateDataPeriod(
            sensordata, starttimecalc, datetime.now())
        tempquantity = quantitylist["average"]
        logger.info(
            'Waterpump Check parameter if tempquantity=%s > MinAveragetemp=%s ',
            str(tempquantity), str(MinAveragetemp))
        print('Waterpump Check parameter if tempquantity=', tempquantity,
              ' > MinAveragetemp=', MinAveragetemp)

        if (MinAveragetempnum != "NA"):
            if (tempquantity > MinAveragetempnum):
                logger.info(
                    'Temperature check PASSED, tempquantity=%s > MinAveragetemp=%s ',
                    str(tempquantity), str(MinAveragetemp))
            else:
                logger.info('Temperature check FAILED')
                print('Temperature check FAILED')
                pumpit = False

    # weather Forecast
    sensorname = weatherAPImod.DefaultCounterName()
    sensorlist = sensordbmod.gettablelist()
    if sensorname in sensorlist:
        ActiveActuatorList = weatherAPImod.ActiveActuatorList()
        if target in ActiveActuatorList:
            sensordata = []
            samplesnumber = 1
            sensordbmod.getsensordbdatasamplesN(sensorname, sensordata,
                                                samplesnumber)
            MaxPastMinutes = 1200
            starttimecalc = datetime.now() - timedelta(minutes=MaxPastMinutes)
            isok, quantitylist = sensordbmod.EvaluateDataPeriod(
                sensordata, starttimecalc, datetime.now())
            if isok:
                RainMultipier = quantitylist["average"]
                logger.info('Waterpump weather multiplier =%s ',
                            str(RainMultipier))
            else:
                logger.warning(
                    'Waterpump weather multiplier NOT found within 20 Hours apply 100 '
                )
                RainMultipier = 100
            duration = int(duration * RainMultipier / 100)
    else:
        logger.warning('Weather Sensor not found, no multpilier applied ')

    if pumpit:
        # activation of the doser before the pump
        doseron = autofertilizermod.checkactivate(target, duration)
        # watering
        #hardwaremod.makepulse(target,duration)
        activateandregister(target, duration)
        # salva su database
        #logger.info('Switch Pump %s ON, optional time for sec = %s', target, duration)
        #print 'Pump ON, optional time for sec =', duration
        #actuatordbmod.insertdataintable(target,duration)

    return True
Exemplo n.º 2
0
def startpump(target,activationseconds,MinAveragetemp,MaxAverageHumid):

	logger.info('WateringPlan Startpump evaluation: %s', target)	
	#workmode=autowateringmod.checkworkmode(target)
	#if workmode=="Full Auto":
	if target in autowateringmod.allowwateringplan:
		if not autowateringmod.allowwateringplan[target]:
			logger.info('WateringPlan: %s pump activation blocked by automation', target)
			pumpit=False
			return False
	
	duration=1000*hardwaremod.toint(activationseconds,0)
	print target, " ",duration, " " , datetime.now() 

	# evaluate parameters
	#MinAverageLight=500 not used now
	MinutesOfAverage=120 #minutes in which the average data is calculated from sensor sampling

	print "waterpump check"
	logger.info('execute water pump check %s', datetime.now().strftime("%Y-%m-%d %H:%M:%S"))

	# then check the temperature and Humidity

	print "Check Humidity and Temperature"
	
	MinAveragetempnum=hardwaremod.tonumber(MinAveragetemp,"NA")
	MaxAverageHumidnum=hardwaremod.tonumber(MaxAverageHumid,"NA")
	
	# all the below conditions should be verified to start the PUMP
	pumpit=True	
	
	hsensornamelist=hardwaremod.getsensornamebymeasure(hardwaremod.MEASURELIST[1])
	if hsensornamelist:
		sensordata=[]		
		hsensorname=hsensornamelist[0]  # get first found sensor in the list
		sensordbmod.getsensordbdata(hsensorname,sensordata)
		starttimecalc=datetime.now()-timedelta(minutes=int(MinutesOfAverage))
		humquantity=sensordbmod.EvaluateDataPeriod(sensordata,starttimecalc,datetime.now())["average"]	
		logger.info('Waterpump Check parameter if humquantity=%s < MaxAverageHumid=%s ', str(humquantity), str(MaxAverageHumid))
		print 'Waterpump Check parameter if humquantity=',humquantity,' < MaxAverageHumid=' ,MaxAverageHumid
		
		if (MaxAverageHumidnum!="NA"):
			if (humquantity<MaxAverageHumidnum):		
				logger.info('Humidity check PASSED, humquantity=%s < MaxAverageHumid=%s ', str(humquantity), str(MaxAverageHumid))			
			else:
				logger.info('Humidity check FAILED')
				print 'Humidity check FAILED'
				pumpit=False			
		
	
	tsensornamelist=hardwaremod.getsensornamebymeasure(hardwaremod.MEASURELIST[0])
	if tsensornamelist:
		sensordata=[]		
		tsensorname=tsensornamelist[0]  # get first found sensor in the list
		sensordbmod.getsensordbdata(tsensorname,sensordata)
		starttimecalc=datetime.now()-timedelta(minutes=int(MinutesOfAverage))
		tempquantity=sensordbmod.EvaluateDataPeriod(sensordata,starttimecalc,datetime.now())["average"]	
		logger.info('Waterpump Check parameter if tempquantity=%s > MinAveragetemp=%s ', str(tempquantity), str(MinAveragetemp))
		print 'Waterpump Check parameter if tempquantity=',tempquantity,' > MinAveragetemp=' ,MinAveragetemp
		
		if (MinAveragetempnum!="NA"):
			if (tempquantity>MinAveragetempnum):		
				logger.info('Temperature check PASSED, tempquantity=%s > MinAveragetemp=%s ', str(tempquantity), str(MinAveragetemp))			
			else:
				logger.info('Temperature check FAILED')
				print 'Temperature check FAILED'
				pumpit=False	
				

	if pumpit:
		# activation of the doser before the pump
		doseron=autofertilizermod.checkactivate(target,duration)	
		# watering
		hardwaremod.makepulse(target,duration)
		# salva su database
		logger.info('Switch Pump %s ON, optional time for sec = %s', target, duration)
		print 'Pump ON, optional time for sec =', duration
		actuatordbmod.insertdataintable(target,duration)
		
	return True
Exemplo n.º 3
0
def startpump(target, activationseconds, MinAveragetemp, MaxAverageHumid):
    duration = 1000 * hardwaremod.toint(activationseconds, 0)
    print target, " ", duration, " ", datetime.now()
    logger.info('Startpump evaluation')
    # evaluate parameters
    #MinAverageLight=500 not used now
    MinutesOfAverage = 120  #minutes in which the average data is calculated from sensor sampling

    print "waterpump check"
    logger.info('execute water pump check %s',
                datetime.now().strftime("%Y-%m-%d %H:%M:%S"))

    # then check the temperature and Humidity

    print "Check Humidity and Temperature"

    hsensornamelist = hardwaremod.getsensornamebymeasure(
        hardwaremod.MEASURELIST[1])
    if hsensornamelist:
        sensordata = []
        hsensorname = hsensornamelist[0]  # get first found sensor in the list
        sensordbmod.getsensordbdata(hsensorname, sensordata)
        starttimecalc = datetime.now() - timedelta(
            minutes=int(MinutesOfAverage))
        humquantity = sensordbmod.EvaluateDataPeriod(sensordata, starttimecalc,
                                                     datetime.now())["average"]
        logger.info(
            'Waterpump Check parameter if humquantity=%s < MaxAverageHumid=%s ',
            str(humquantity), str(MaxAverageHumid))
        print 'Waterpump Check parameter if humquantity=', humquantity, ' < MaxAverageHumid=', MaxAverageHumid

    tsensornamelist = hardwaremod.getsensornamebymeasure(
        hardwaremod.MEASURELIST[0])
    if tsensornamelist:
        sensordata = []
        tsensorname = tsensornamelist[0]  # get first found sensor in the list
        sensordbmod.getsensordbdata(tsensorname, sensordata)
        starttimecalc = datetime.now() - timedelta(
            minutes=int(MinutesOfAverage))
        tempquantity = sensordbmod.EvaluateDataPeriod(
            sensordata, starttimecalc, datetime.now())["average"]
        logger.info(
            'Waterpump Check parameter if tempquantity=%s > MinAveragetemp=%s ',
            str(tempquantity), str(MinAveragetemp))
        print 'Waterpump Check parameter if tempquantity=', tempquantity, ' > MinAveragetemp=', MinAveragetemp

    MinAveragetempnum = hardwaremod.tonumber(MinAveragetemp, "NA")
    MaxAverageHumidnum = hardwaremod.tonumber(MaxAverageHumid, "NA")

    # all the below conditions should be verified to start the PUMP
    pumpit = True

    if (MinAveragetempnum != "NA"):
        if (tempquantity > MinAveragetempnum):
            logger.info(
                'Temperature check PASSED, tempquantity=%s > MinAveragetemp=%s ',
                str(tempquantity), str(MinAveragetemp))
        else:
            logger.info('Temperature check FAILED')
            print 'Temperature check FAILED'
            pumpit = False

    if (MaxAverageHumidnum != "NA"):
        if (humquantity < MaxAverageHumidnum):
            logger.info(
                'Humidity check PASSED, humquantity=%s < MaxAverageHumid=%s ',
                str(humquantity), str(MaxAverageHumid))
        else:
            logger.info('Humidity check FAILED')
            print 'Humidity check FAILED'
            pumpit = False

    if pumpit:
        hardwaremod.makepulse(target, duration)
        # salva su database
        logger.info('Pump ON, optional time for sec = %s', duration)
        print 'Pump ON, optional time for sec =', duration
        actuatordbmod.insertdataintable(target, duration)
Exemplo n.º 4
0
def startpump(target, activationseconds, MinAveragetemp, MaxAverageHumid):

    logger.info('WateringPlan Startpump evaluation: %s', target)
    #workmode=autowateringmod.checkworkmode(target)
    #if workmode=="Full Auto":
    if target in autowateringmod.allowwateringplan:
        if not autowateringmod.allowwateringplan[target]:
            logger.info(
                'WateringPlan: %s pump activation blocked by automation',
                target)
            pumpit = False
            return False

    duration = hardwaremod.toint(activationseconds, 0)
    print target, " ", duration, " ", datetime.now()

    # evaluate parameters
    #MinAverageLight=500 not used now
    MinutesOfAverage = 120  #minutes in which the average data is calculated from sensor sampling

    print "waterpump check"
    logger.info('execute water pump check %s',
                datetime.now().strftime("%Y-%m-%d %H:%M:%S"))

    # then check the temperature and Humidity

    print "Check Humidity and Temperature"

    MinAveragetempnum = hardwaremod.tonumber(MinAveragetemp, "NA")
    MaxAverageHumidnum = hardwaremod.tonumber(MaxAverageHumid, "NA")

    # all the below conditions should be verified to start the PUMP
    pumpit = True

    hsensornamelist = hardwaremod.getsensornamebymeasure(
        hardwaremod.MEASURELIST[1])
    if hsensornamelist:
        sensordata = []
        hsensorname = hsensornamelist[0]  # get first found sensor in the list
        sensordbmod.getsensordbdata(hsensorname, sensordata)
        starttimecalc = datetime.now() - timedelta(
            minutes=int(MinutesOfAverage))
        isok, quantitylist = sensordbmod.EvaluateDataPeriod(
            sensordata, starttimecalc, datetime.now())
        humquantity = quantitylist["average"]

        logger.info(
            'Waterpump Check parameter if humquantity=%s < MaxAverageHumid=%s ',
            str(humquantity), str(MaxAverageHumid))
        print 'Waterpump Check parameter if humquantity=', humquantity, ' < MaxAverageHumid=', MaxAverageHumid

        if (MaxAverageHumidnum != "NA"):
            if (humquantity < MaxAverageHumidnum):
                logger.info(
                    'Humidity check PASSED, humquantity=%s < MaxAverageHumid=%s ',
                    str(humquantity), str(MaxAverageHumid))
            else:
                logger.info('Humidity check FAILED')
                print 'Humidity check FAILED'
                pumpit = False

    tsensornamelist = hardwaremod.getsensornamebymeasure(
        hardwaremod.MEASURELIST[0])
    if tsensornamelist:
        sensordata = []
        tsensorname = tsensornamelist[0]  # get first found sensor in the list
        sensordbmod.getsensordbdata(tsensorname, sensordata)
        starttimecalc = datetime.now() - timedelta(
            minutes=int(MinutesOfAverage))
        isok, quantitylist = sensordbmod.EvaluateDataPeriod(
            sensordata, starttimecalc, datetime.now())
        tempquantity = quantitylist["average"]
        logger.info(
            'Waterpump Check parameter if tempquantity=%s > MinAveragetemp=%s ',
            str(tempquantity), str(MinAveragetemp))
        print 'Waterpump Check parameter if tempquantity=', tempquantity, ' > MinAveragetemp=', MinAveragetemp

        if (MinAveragetempnum != "NA"):
            if (tempquantity > MinAveragetempnum):
                logger.info(
                    'Temperature check PASSED, tempquantity=%s > MinAveragetemp=%s ',
                    str(tempquantity), str(MinAveragetemp))
            else:
                logger.info('Temperature check FAILED')
                print 'Temperature check FAILED'
                pumpit = False

    if pumpit:
        # activation of the doser before the pump
        doseron = autofertilizermod.checkactivate(target, duration)
        # watering
        hardwaremod.makepulse(target, duration)
        # salva su database
        logger.info('Switch Pump %s ON, optional time for sec = %s', target,
                    duration)
        print 'Pump ON, optional time for sec =', duration
        actuatordbmod.insertdataintable(target, duration)

    return True