예제 #1
0
    def set_mode(self, client, userdata, message):
        mode = message.payload.decode('utf-8')
        previous_mode = self.mode

        # reset PID if switching between modes
        if previous_mode != mode:
            pid_options = self.config.getPIDOptions(mode)
            temp_options = self.config.getTempOptions(mode)
            self.temp = Temp(**{**temp_options, **pid_options})

        if mode == 'off':
            self.manual = True
            self.mode = 'auto'
            self.power.state = False
            self.logger.info('Set mode to off')
        if mode == 'auto':
            self.manual = True
            self.power.state = True
            self.mode = 'auto'
            self.temp.temp_set = self.temp.temp_request
            self.logger.info('Set mode to manual')
        elif mode == 'heat':
            self.manual = False
            self.mode = mode
            self.logger.info('Set mode to %s', self.mode)
        elif mode == 'cool':
            self.manual = False
            self.mode = mode
            self.temp.temp_set = self.temp.temp_absolute
            self.logger.info('Set mode to %s', self.mode)

        self.state.setMode(mode)
        self.publish_mode()
        self.setHVAC()
        self.set_next_iteration(2)
예제 #2
0
    def __init__(self):
        self.logger = logging.getLogger('hvac-pid')
        self.logger.info('Starting hvac-pid')

        self.config = Config()
        self.util = Util()

        # PID options
        pid_options = self.config.getPIDOptions(self.mode)
        temp_options = self.config.getTempOptions(self.mode)

        # Temp
        self.temp = Temp(**{**temp_options, **pid_options})

        # Fan
        self.fan = Fan()

        # Power
        self.power = Power()

        # Occupancy state
        self.state = State(**self.config.getStateOptions())

        # MQTT
        self.topic_prefix = os.getenv('MQTT_PID_TOPIC_PREFIX')
        self.mqtt = MQTTClient(os.getenv('MQTT_CLIENT_ID'),
                               os.getenv('MQTT_BROKER_HOST'))
        self.mqtt.connect()

        # subscribe
        self.mqtt.subscribe(os.getenv('MQTT_TEMP_TOPIC'), 0,
                            self.temp_update_callback)
        self.mqtt.subscribe(os.getenv('MQTT_TEMP_OUTDOORS_TOPIC'), 0,
                            self.temp_outdoors_update_callback)
        self.mqtt.subscribe(os.getenv('MQTT_HVAC_STATE_TOPIC'), 0,
                            self.hvac_callback)
        self.mqtt.subscribe(self.topic_prefix + '/mode/set', 0, self.set_mode)
        self.mqtt.subscribe(self.topic_prefix + '/temperature/set', 0,
                            self.set_temp)
        self.mqtt.subscribe(self.topic_prefix + '/fan/set', 0, self.set_fan)
        self.mqtt.subscribe(os.getenv('MQTT_HVAC_OCCUPANCY_STATE_TOPIC'), 0,
                            self.set_occupancy_state)

        self.logger.info('MQTT connected')

        self.publish_temp()
        self.publish_mode()
        self.publish_fan()

        self.next_iteration = datetime.now() + timedelta(minutes=2)

        # wait a bit before enabling control
        time.sleep(5)
        self.control_enable = True
예제 #3
0
  def __init__(self):

    self.motionDetected = False;
    self.relay = Relays(7);
    self.relay.setAllOff();
    self.motion = Motion(0, 3, self);
    self.light = Light(3, 1000, self);
    self.temp = Temp(1, 85, self);

    self.start = time.time();

    while True:
      print('********** Switch Module Starting **********');
      time.sleep(5);
예제 #4
0
def test_upperLimit():
    temp = Temp(**{
        'Kp': 1, 
        'Ki': 1, 
        'Kd': 1,
        'temp_min': 17,
        'temp_max': 30,
        'mode': 'heat',
    })
    temp.temp_set = 40
    temp.setMeasurement(40, 40)
    temp.setRequest(40)
    temp.iteratePID()

    assert temp.temp_set == 30
예제 #5
0
def test_lowerLimit():
    temp = Temp(**{
        'Kp': 1, 
        'Ki': 1, 
        'Kd': 1,
        'temp_min': 17,
        'temp_max': 30,
        'mode': 'heat',
    })
    temp.temp_set = 17
    temp.setMeasurement(17, 17)
    temp.setRequest(17)
    temp.iteratePID()

    assert temp.temp_set == 17
예제 #6
0
def run(delay, sensor_type, pin, webhook, source, metric_prefix, output,
        format):
    sensor = None
    is_polling = False
    if sensor_type.startswith('DHT'):
        pin = int(pin)
        sensor = Temp(source, metric_prefix, output, sensor_type, pin, format)
        is_polling = True
    elif sensor_type == 'HC-SRO':
        pins = pin.split(',')
        sensor = Distance(source, metric_prefix, output, sensor_type,
                          int(pins[0]), int(pins[1]), format)
        is_polling = True
    elif sensor_type == 'SSM-1':
        pin = int(pin)
        sensor = Generic(source, metric_prefix, output, sensor_type, pin,
                         'Sound')
    elif sensor_type == 'HC-SR501':
        pin = int(pin)
        sensor = Motion(source, metric_prefix, output, sensor_type, pin)
    elif sensor_type == 'SEO53':
        pin = int(pin)
        sensor = Generic(source, metric_prefix, output, sensor_type, pin,
                         'Vibration')
    elif sensor_type == 'SEO23':
        pin = int(pin)
        sensor = Generic(source, metric_prefix, output, sensor_type, pin,
                         'Tilt')
    elif sensor_type == 'YL-69':
        pin = int(pin)
        sensor = Moisture(source, metric_prefix, output, sensor_type, pin,
                          'Moisture', delay)
    else:
        sensor = Host(source, metric_prefix, output)
        is_polling = True

    while True:
        sensor.get_info()
        metrics = sensor.format_metrics()
        if webhook is not None:
            send_metrics(metrics, output, webhook, source)
        else:
            print(metrics)
        # check if the senor is something that needs to poll for results based on a delay.
        if is_polling:
            time.sleep(delay)
예제 #7
0
 def __init__(self, conf, name):
     threading.Thread.__init__(self)
     self.daemon = True
     if conf["enabled"] == "true":
         self.enabled = True
     else:
         self.enabled = False
     self.gpio_number = conf["gpio_number"]
     self.target = int(conf["target"])
     self.sensor = Temp(fileName = conf["temp_sensor"], correctionFactor = conf["temp_offset"])
     self.band = conf["band"]
     self.jee = Adafruit_MCP230XX(address=0x26, num_gpios=8, busnum=1)
     self.jee.config(self.gpio_number,self.jee.OUTPUT)
     self.name = name
     self.state = conf["state"]
     self.usePid = conf["usePid"]
     self.pid_Kp = conf["pid_Kc"]
     self.pid_Ki = conf["pid_Ti"]
     self.pid_Kd = conf["pid_Td"]
     self.cycle_time = conf["cycle_time"]
     self.pid = mypid.mypid(kp=self.pid_Kp,ki=self.pid_Ki,kd=self.pid_Kd, history_depth=3)
예제 #8
0
    web_server.stop()
    if 'yes' == MASTER:
        my_screen.stop()
    time.sleep(0.5)
    sys.exit(0)


# The main program, start thread, then update continuously
if __name__ == '__main__':

    # Install the signal handler
    signal.signal(signal.SIGTERM, signal_handler)
    signal.signal(signal.SIGINT, signal_handler)

    # Create a new temp object with specified temp modifier, and polling rate
    temp = Temp(-3, 1)
    temp.start()

    # Create a new web server and bind it to the specified address:port
    web_server = MyServer(WEB_BIND_ADDRESS, WEB_BIND_PORT)
    web_server.start()

    # If this is the MASTER, setup slave URL, screen thread and web server thread
    if 'yes' == MASTER:

        # Construct the URL for getting the slave's temperature
        SLAVE_TEMP_URL = 'http://' + SLAVE_IP + ':' + str(
            WEB_BIND_PORT) + '/api/temp-F'
        debug("--> SLAVE_TEMP_URL = \"" + SLAVE_TEMP_URL + "\"")

        # Create a new screen handler object
예제 #9
0
#battery.volts()
#print("Battery volts: {0:.2f}v".format(battery.volts()))
#if battery.alarm():
#    print('Battery Needs a charge')
#else:
#    print('Battery okay')

# roughly works ...
vin = Vin('P16', 'P10')
led = Led('P11')
battery = Battery(py)

# still need work
stateMachine = StateMachine()
bilgeSwitch = BilgeSwitch('P13')
temp = Temp('P9')
button = Button('P14')

check = Checks(led, vin, bilgeSwitch, battery, temp, stateMachine)
check.whichToDo()

# https://forum.pycom.io/topic/1626/pytrack-gps-api/12

# to sleep with GPS VBACKUP on
# should go down to 17ua
# https://forum.pycom.io/topic/2525/power-consumption/16
#
# py.go_to_sleep(True)

# tell us why we woke
# display the reset reason code and the sleep remaining in seconds
예제 #10
0
def main():
	global temp
	if sys.argv[1] is None:
		raise ValueError('Need to set target temparature as float')
	temp = Temp(float(sys.argv[1]))
	run(server='paste', host='0.0.0.0', port=8080, debug=True, reloader=False)
예제 #11
0
#!/usr/bin/env python
import time
import eeml
from temp import Temp

# COSM variables. API_KEY and FEED are specific
API_KEY = 'SCf8E2SZG3W68pbyUuf1qzg9umMWy6VCkHoeVuuDPEjI2SPN'
FEED = '2053937525'
API_URL = '/v2/feeds/{feednum}.xml'.format(feednum=FEED)

#replace 28-00000449ef31 below with the id of your temperature probe
sensor1 = Temp(fileName='28-000004d93f9d')
sensor2 = Temp(fileName='28-000004d9ad58')
sensor1.start()
sensor2.start()

#the rest of your code is below.
# The Temp class will be updating on its own thread which will allow you to do
#  anything you want on the main thread.
while True:

    temp1 = sensor1.getCurrentTemp()
    temp2 = sensor2.getCurrentTemp()

    print temp1
    print temp2

    #open cosm feed
    pac = eeml.Pachube(API_URL, API_KEY)

    #send fahrenheit data