예제 #1
0
def handle_temperature(topic, message):
    reading = float(message)
    storage.store_temperature_reading(reading)
    temperature = statistics.mean(storage.get_temperature_readings())
    temperature = round(temperature, 2)
    storage.set("temperature", temperature)

    ch_set_on = storage.get("ch_set_on")

    if ch_set_on:
        # Thermostat logic
        delta_above = storage.get("thermostat_delta_above")
        delta_below = storage.get("thermostat_delta_below")
        set_temp = storage.get("thermostat_temperature")

        if temperature < (set_temp - delta_below):
            heating_on()

        if temperature > (set_temp + delta_above):
            heating_off()

        ch_running = storage.get("ch_running")
        if ch_running:
            # This will send the MQTT "on" signal which must be sent
            # regularly to prevent the heating turning off due to lack
            # of communication.
            heating_on()

    ws.get_instance().publish("temperature", {"latest_reading": temperature})
    mqtt.publish("hub/module/heating/averaged_temperature", temperature)
예제 #2
0
def heating_on():
    mqtt.publish("flat/heating/hallway/chState", "on")
    storage.set("ch_running", True)

    ws.push_state()
예제 #3
0
def heating_set_on():
    mqtt.publish("flat/heating/hallway/sensorLed", "on")
    storage.set("ch_set_on", True)

    ws.push_state()
예제 #4
0
def heating_set_off():
    mqtt.publish("flat/heating/hallway/sensorLed", "off")
    storage.set("ch_set_on", False)

    heating_off()  # This will also call ws.push_state()
예제 #5
0
def heating_off():
    mqtt.publish("flat/heating/hallway/chState", "off")
    storage.set("ch_running", False)

    ws.push_state()