Anyone tried to get data from a BME280 sensor?

Hi guys. I’m trying to collect temp, pressure and humidity from a BME280 sensor. I’m fairly new to the Home Assistant club, so I don’t know how to proceed. I know it’s a i2c sensor, but is it possible to extract parts of a python script that reads the value or anything like that?

The sensor is connected to the GPIO on my Raspberry Pi 3.

You need support for i2c on your hardware platform. At the moment there is no support for i2c available in Home Assistant but you could use an external with smbus2 with the command-line sensor.

Hi,
I’ve just created similar (BMP280) component code, it’s described here. The commit also contains i2c support on Rpi via smbus2, as @fabaff suggested.
I will order BME280 or even BME680 too, and will try to code it,
but don’t know if it’s worth to be integrated in main branch, while effort to properly submit PR is rather big to me…
Kind regards,
Jurek

That is great news!

I use BMP180 on ESP8266 with ESPEasy firmware. ESPEasy supports BMP085, BMP280 and BME280. It works really well with HA as it sends the data over MQTT. I didn’t manage to get it working with HA when it was connected to RPi.
Only disadvantage is that you need another piece of hardware.
In my setup with RPi I used DHT22 to monitor temp and humidity in one room and BPM180 on ESP8266 to monitor temperature and pressure in other room. Pressure can be measured anywhere as long as you want to measure places at the same altitude.

Using BMP/BME280 on separate hardware may be better option than connecting it directly to Raspberry Pi because RPi may affect temperature readings.
In my case it’s +2.5 deg with sensor located as on this https://goo.gl/photos/7NEk26Kd2qQqvNb36 photo. The sensor in in metal cage, under the hood is RPi B+, 8 relays module, 2A power supply and 3.5’’ LCD screen. I will do another try with replacing metal screws with plastic ones, it may help.
Of course, longer wires would minimize the effect, too. As temporary solution I introduced correction parameter in configuration part of the sensor HA component.
However, I would rather prefer battery-powered a BLE device than ESP8266, which its relatively high energy demand (3.3 V, 250mA peak AFIK) that imposes using AC adapter.
Kind regards,
Jurek

I have been suspicious of the same when reading the values in my python test script. I have ordered an ESP8266 now to test it further. I’m looking into some of the cheap aliexpress wireless sensors, but I guess those will be hard to integrate as well. What line can I add in the configuration for temp correction?

To use my component code, configuration is as follows:

sensor:
  - platform: bmp280
    address: 0x76
    temp_name: Room temperature
    temp_adj: -2.0
    press_name: Pressure
    press_adj: 8.0

Of course temp_adj and press_adj are adjustment values. Sensor address may be 0x76 or 0x77, depending on sensor’s SDO pin level.
To make this component work, it’s also necessary use of i2c bus support.
Good luck!
– Jurek

If you’re looking for BLE powered temperature sensor I would suggest looking at Xiaomi Mi Flora https://home-assistant.io/components/sensor.miflora/ .
It is designed to monitor plant growing conditions like temperature, humidity, light.
It’s officially supported and you can select specific parameters to monitor in HA.
What you’ll only miss will be the pressure but it can be monitored by BMP280 on RPi as it won’t be affected by heat from RPi and related components.

Pozdrawiam;)

Thanks @jaskie, I will look into it :slight_smile:

I have actually ordered the Mi Flora sensor @rogeer, and I’m looking forward to test it. I am also looking forward to getting my first plant…

1 Like

I ended up using an ESP8266 with ESPEasy. Publishes an MQTT message every 30 seconds with all three values and the setup is really easy, so I am satisfied. Thanks for the help guys! :slight_smile:

Hi jaskie
I tried your code and it worked very well
Thank you for sharing!

Hi, I am also having problems getting (Adafruit) BME280 running in HA.

I have installed the Adafruit_Python_BME components as at

The sensor works fine from command line interrogation including in the HA virtual environment
if I run a simple outputting script from e.g. /home/pi/Adafruit_Python_BME280/BME280p.py

from Adafruit_BME280 import *
sensor = BME280(mode=BME280_OSAMPLE_8)
pascals = sensor.read_pressure()
hectopascals = pascals / 100
print '{0:0.2f}'.format(hectopascals)

but for a configuration.yaml entry

sensor BME280:
  - platform: command_line
    name: Ambient pressure
    command: "python2 /home/pi/Adafruit_Python_BME280/BME280p.py"
    unit_of_measurement: "hPa"
    value_template: '{{ value | round(2) }}'

I get:
17-01-12 00:49:00 homeassistant.components.sensor.command_line: Command failed: python2 /home/pi/Adafruit_Python_BME280p.py

The command failure seems to result from the script line:
sensor = BME280(mode=BME280_OSAMPLE_8)
in the BME280p.py script, as mentioned, it works fine from command line in the virtual environment but not as command line sensor in HA.

Advice much appreciated.

1 Like

I have an acceptable solution without working up a sensor definition for the BME280 in home assistant, which can reliably ingest data into home assistant through an external process running under cron that queries the sensor every minute (or as required) and writes data to file. Home assistant then happily picks up value data from that file every minute with an e.g. configuration.yaml entry:

sensor BMEPressure:
  - platform: command_line
    name: Ambient msl pressure
    command: "cat /home/pi/p.dat"
    unit_of_measurement: "hPa"
    value_template: '{{ value | round(2) }}'
1 Like

Would a MQ2 smoke sensor work like your?

wwill I am just looking at setting this up an this is the first remote sensor I will be doing. Any chance you could provide some instruction on how to set it up with an ESP8266

It’s not that hard really. If you are familiar with flashing the ESP8266 with firmware found on GitHub etc, then it should be an ok task. I use Arduino IDE or Atom. Google ESPEasy and find the latest version, flash it onto the ESP8266, and choose BME280 as the sensor in the settings on the web interface when the ESP is up and running.

1 Like