Skip to content

Commit

Permalink
added bme280 humidity and pressure
Browse files Browse the repository at this point in the history
  • Loading branch information
escomputers committed Mar 26, 2023
1 parent 49aa4f5 commit 4d44501
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 18 deletions.
27 changes: 18 additions & 9 deletions sensors/bme280/air-humidity.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import threading
import board
from adafruit_bme280 import basic as adafruit_bme280
import syslog

syslog.openlog(facility=syslog.LOG_LOCAL0)

LLA_TOKEN = os.environ["TOKEN"]

Expand All @@ -14,12 +17,18 @@ def sensing():

# GET & SEND AIR HUMIDITY
air_humidity = str(("%.2f" % round(bme280.humidity, 2)))
requests.post('http://localhost:8123/api/states/sensor.air_humidity', headers={
'Authorization': 'Bearer ' + LLA_TOKEN,
'Content-Type': 'application/json'
}, json={
'state': air_humidity,
'attributes': {
'unit_of_measurement': '°C'
}
})
try:
response = requests.post('http://localhost:8123/api/states/sensor.air_humidity', headers={
'Authorization': 'Bearer ' + LLA_TOKEN,
'Content-Type': 'application/json'
}, json={
'state': air_humidity,
'attributes': {
'unit_of_measurement': '%'
}
})
response.raise_for_status()
except requests.exceptions.RequestException as e:
syslog.syslog(syslog.LOG_WARNING, str(e))

sensing()
27 changes: 18 additions & 9 deletions sensors/bme280/air-pressure.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import threading
import board
from adafruit_bme280 import basic as adafruit_bme280
import syslog

syslog.openlog(facility=syslog.LOG_LOCAL0)

LLA_TOKEN = os.environ["TOKEN"]

Expand All @@ -14,12 +17,18 @@ def sensing():

# GET & SEND AIR PRESSURE
air_pressure = str(("%.2f" % round(bme280.pressure, 2)))
requests.post('http://localhost:8123/api/states/sensor.air_pressure', headers={
'Authorization': 'Bearer ' + LLA_TOKEN,
'Content-Type': 'application/json'
}, json={
'state': air_pressure,
'attributes': {
'unit_of_measurement': '°C'
}
})
try:
response = requests.post('http://localhost:8123/api/states/sensor.air_pressure', headers={
'Authorization': 'Bearer ' + LLA_TOKEN,
'Content-Type': 'application/json'
}, json={
'state': air_pressure,
'attributes': {
'unit_of_measurement': 'hPa'
}
})
response.raise_for_status()
except requests.exceptions.RequestException as e:
syslog.syslog(syslog.LOG_WARNING, str(e))

sensing()

0 comments on commit 4d44501

Please sign in to comment.