forked from jalmeroth/homie-python
-
Notifications
You must be signed in to change notification settings - Fork 2
/
temperature_sensor.py
executable file
·40 lines (30 loc) · 1.01 KB
/
temperature_sensor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import time
import homie
import logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
TEMPERATURE_INTERVAL = 3
config = homie.loadConfigFile("homie-python.json")
Homie = homie.Homie(config)
temperatureNode = Homie.Node("temperature", "temperature")
humidityNode = Homie.Node("humidity", "humidity")
def main():
Homie.setFirmware("awesome-temperature", "1.0.0")
temperatureNode.advertise("degrees")
humidityNode.advertise("humidity")
Homie.setup()
while True:
temperature = 22.0
humidity = 60.0
logger.info("Temperature: {:0.2f} °C".format(temperature))
temperatureNode.setProperty("degrees").send(temperature)
logger.info("Humidity: {:0.2f} %".format(humidity))
humidityNode.setProperty("humidity").send(humidity)
time.sleep(TEMPERATURE_INTERVAL)
if __name__ == '__main__':
try:
main()
except (KeyboardInterrupt, SystemExit):
logger.info("Quitting.")