Beispiel #1
0
    def mqtt_set_mode_callback(self, client, userdata, message):
        try:
            payload = message.payload.decode().lower()
            logging.info("Received HVAC mode update request: {}".format(payload))
            self.set_mode(payload)
        except Exception as e:
            logging.error('Unable to proces message.', e)

        mqtt.publish(self.topic, self.payload())
Beispiel #2
0
    def mqtt_set_temperature_set_point_callback(self, client, userdata, message):
        try:
            logging.info("Received temperature set point update request: {}".format(message.payload))
            payload = float(message.payload.decode())
            if self.mode == HVAC.HEAT:
                self.set_point_heat = payload
            else:
                self.set_point_cool = payload
        except Exception as e:
            logging.error('Unable to proces message.', e)

        mqtt.publish(self.topic, self.payload())
Beispiel #3
0
    def mqtt_callback(self, client, userdata, message):
        try:
            # print(message)
            logging.info("Received command message: {}".format(message))
            payload = message.payload
            if payload == 'ON':
                self.on()
            elif payload == 'OFF':
                self.off()
        except Exception as e:
            logging.error('Unable to proces message.', e)

        mqtt.publish(self.topic, self.payload())
Beispiel #4
0
    def setup(self):
        # config = json.dumps({'name': self.name, 'device_class': self.device_class})

        device_config = {
            'name': "Laundry Room Climate",
            'identifiers': self.name,
            'sw_version': 'rpi2mqtt',
            'model': "DHT 22",
            'manufacturer': 'Generic'
        }

        config = json.dumps({
            'name': self.name + '_temperature',
            'device_class': 'temperature',
            'unit_of_measurement': '°F',
            'value_template': "{{ value_json.temperature }}",
            'unique_id': self.name + '_temperature_rpi2mqtt',
            'state_topic': self.topic,
            "json_attributes_topic": self.topic,
            'device': device_config
        })

        mqtt.publish(
            'homeassistant/sensor/{}_{}/config'.format(self.name, 'temp'),
            config)

        config = json.dumps({
            'name': self.name + '_humidity',
            'device_class': 'humidity',
            'json_attributes_topic': self.topic,
            'unit_of_measurement': '%',
            'value_template': "{{ value_json.humidity }}",
            'unique_id': self.name + '_humidity_rpi2mqtt',
            'state_topic': self.topic,
            'device': device_config
        })

        mqtt.publish(
            'homeassistant/sensor/{}_{}/config'.format(self.name, 'humidity'),
            config)
Beispiel #5
0
    def callback(self, **kwargs):
        # system active, should we turn it off?
        logging.info('Checking temperature...temp = {}, heat_setpoint = {}, cool_setpoint = {}, set_point_tolerance = {}'.format(self.temperature, self.set_point_heat, self.set_point_cool, self.set_point_tolerance))
        self.append_tempearture_history()
        
        if self.active:
            if self.mode in ['heat', 'aux'] and self.temperature > self.set_point_heat + self.set_point_tolerance:
                # turn hvac off
                logging.info('Temperature is {}. Turning heat off.'.format(self.temperature))
                self.off()

                # reset mode to normal heat
                if self._boosting_heat:
                    self.boost_heat(HVAC.OFF)

            elif self.mode == 'cool' and self.temperature < self.set_point_cool - self.set_point_tolerance:
                # turn hvac off
                logging.info('Temperature is {}. Turning cool off.'.format(self.temperature))
                self.off()

            # should system boost heating with aux heat?
            logging.debug("Checking temperature rate of change...current rate = {}, min rate = {}".format(self.temperature_rate_of_change, self.minimum_temp_rate_of_change))
            if self.mode == HVAC.HEAT and self.temperature_rate_of_change and self.temperature_rate_of_change <= self.minimum_temp_rate_of_change:
                self.boost_heat(HVAC.ON)

        else:
            if self.mode == 'heat' and self.temperature < self.set_point_heat - self.set_point_tolerance:
                # turn hvac on
                logging.info('Temperature is {}. Turning heat on.'.format(self.temperature))
                self.on()
            elif self.mode == 'cool' and self.temperature > self.set_point_cool + self.set_point_tolerance:
                # turn hvac on
                logging.info('Temperature is {}. Turning cool on.'.format(self.temperature))
                self.on()
            # system is inactive, should we turn it on?
        # logging.info('HVAC is {}. Mode is {}. Temperature is {}.'.format(self.active, self.mode, self.temperature))
        mqtt.publish(self.topic, self.payload())
Beispiel #6
0
 def callback(self, **kwargs):
     mqtt.publish(self.topic, self.payload())
Beispiel #7
0
    def publish_mqtt_discovery(self):

        mqtt.publish(self.homeassistant_mqtt_config_topic, self.homeassistant_mqtt_config_json)
        logging.debug("Published MQTT discovery config to {}".format(self.homeassistant_mqtt_config_topic))