Created
March 13, 2018 16:11
-
-
Save gretel/22b7b042ef0317d779e5d114710d1e17 to your computer and use it in GitHub Desktop.
openbsd has native support for 'ugold' temperature/humidity sensors - this does publish the measured values via mqtt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# | |
# https://gist.github.com/gretel/22b7b042ef0317d779e5d114710d1e17 | |
MQTT_HOST='mqtt.jitter.local' | |
import subprocess | |
from time import sleep | |
import paho.mqtt.client as mqtt | |
def publish(): | |
r = str(subprocess.check_output(["sysctl", "-n", "hw.sensors.ugold0.temp0"]), 'utf-8') | |
t = float(r.split(' ')[0]) | |
print(t) | |
mqttc.publish("home/sensor/studio/temperature", t) | |
r = str(subprocess.check_output(["sysctl", "-n", "hw.sensors.ugold0.humidity0"]), 'utf-8') | |
h = float(r.split('%')[0]) | |
print(h) | |
mqttc.publish("home/sensor/studio/humidity", h) | |
r = str(subprocess.check_output(["sysctl", "-n", "hw.sensors.km0.temp0"]), 'utf-8') | |
c = float(r.split(' ')[0]) | |
print(c) | |
mqttc.publish("sys/sensor/svaha/cpu", c) | |
mqttc = mqtt.Client() | |
mqttc.connect(MQTT_HOST) | |
print('connected') | |
mqttc.loop_start() | |
while True: | |
publish() | |
sleep(15) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment