Page 1 of 1

Python script for I2C BME280 into Domoticz

Posted: Sunday 21 February 2016 0:33
by stlaha2007
I modified the original adafruit example into this script to remotely insert the newest BME280 with temp-hum-baro into Domoticz.

Requirements:
Adafruit HAT BME280 (possible BMP280 also)
Dummy Device temp-hum-baro
I2C enabled
I2C driver (python) from adafruit (see there docmentation)
python and i2c-tools installed

Code: Select all

 { filename:  /home/pi/scripts/reading_BME280.py }
#!/usr/bin/python

from Adafruit_BME280 import *
import urllib2

sensor = BME280(mode=BME280_OSAMPLE_8)

degrees = sensor.read_temperature()
pascals = sensor.read_pressure()
hectopascals = pascals / 100
humidity = sensor.read_humidity()

#print 'Timestamp = {0:0.3f}'.format(sensor.t_fine)
#print 'Temp      = {0:0.3f} deg C'.format(degrees)
#print 'Pressure  = {0:0.2f} hPa'.format(hectopascals)
#print 'Humidity  = {0:0.2f} %'.format(humidity)

#print degrees
#print pascals
#print humidity

print degrees, pascals, humidity

temp = format(degrees, '0.1f')
baro = format(pascals/100, '0.0f')
humi = format(humidity, '0.0f')

idx_bme280 = IDX_Created_in_Domoticz

domoticz1_url = "http://domoticz-ip:port"

url_data1 = '/json.htm?type=command&param=udevice&idx='
url_data2 = '&nvalue=0&svalue='+str(temp)+';'+str(humi)+';0;'+str(baro)+';0'
url1 = domoticz1_url+url_data1+str(idx_bme280)+url_data2

req1 = urllib2.Request(url1)

response1 = urllib2.urlopen(req1)

Grtz,
Stephan

Re: Python script for I2C BME280 into Domoticz

Posted: Sunday 21 February 2016 15:46
by stlaha2007
Currently missing forecast/prediction based on pressure/baro.
Seen in json its possible to set a number between 0 and 7.

Can someone point me in a direction how to set this number based on pressure. Looks like bme180 already supports this as its a native hardware-device combo.


Grtz,
Stephan

Re: Python script for I2C BME280 into Domoticz

Posted: Saturday 17 September 2016 14:00
by Toyman
Look at Mysensors pressure sketch. It contains the algorithm to convert pressure/time change into a forecast