Merge branch 'main' of https://git.jerick.xyz/jerick/homeassistantPi
This commit is contained in:
@@ -39,22 +39,23 @@ def connect_mqtt():
|
||||
|
||||
|
||||
def getValues(sensor):
|
||||
try:
|
||||
temp = sensor.temperature
|
||||
humidity = sensor.humidity
|
||||
#While loop to try sensor again if it fails, seems to happen occasionally
|
||||
result = None
|
||||
while result is None:
|
||||
try:
|
||||
temp = sensor.temperature
|
||||
humidity = sensor.humidity
|
||||
|
||||
#convert to Farenheit
|
||||
temp = (temp * 1.8) + 32
|
||||
#Round the decimals
|
||||
temp = round(temp, 2)
|
||||
#print("Temperature: {}*F Humidity: {}% ".format(temp, humidity))
|
||||
except RuntimeError as error:
|
||||
print(error.args[0])
|
||||
time.sleep(2.0)
|
||||
except Exception as error:
|
||||
sensor.exit()
|
||||
raise error
|
||||
return temp, humidity
|
||||
#convert to Farenheit
|
||||
temp = (temp * 1.8) + 32
|
||||
#Round the decimals
|
||||
temp = round(temp, 2)
|
||||
#print("Temperature: {}*F Humidity: {}% ".format(temp, humidity))
|
||||
result = 1
|
||||
except RuntimeError as error:
|
||||
print(error.args[0])
|
||||
time.sleep(2.0)
|
||||
return temp, humidity
|
||||
|
||||
|
||||
def publish(client, temp, humidity):
|
||||
|
||||
Reference in New Issue
Block a user