Python script for I2C BME280 into Domoticz

Moderator: leecollings

Post Reply
stlaha2007
Posts: 370
Joined: Monday 05 October 2015 10:16
Target OS: -
Domoticz version:
Contact:

Python script for I2C BME280 into Domoticz

Post 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
stlaha2007
Posts: 370
Joined: Monday 05 October 2015 10:16
Target OS: -
Domoticz version:
Contact:

Re: Python script for I2C BME280 into Domoticz

Post 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
Toyman
Posts: 23
Joined: Wednesday 31 August 2016 16:17
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python script for I2C BME280 into Domoticz

Post by Toyman »

Look at Mysensors pressure sketch. It contains the algorithm to convert pressure/time change into a forecast
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest