BME280 Rpi integration to custom component

As pointed out by several people, making the existing Home Assistant (2/2022) bme280 Raspberry Pi integration into a custom component was fairly easy. Here is what I did, note YMMV:

  1. Downloaded the latest source code zip file that has the bme280 integration in it using the following link in Github: https://github.com/home-assistant/core/archive/refs/tags/2022.2.9.zip .

  2. Unzipped the file in a convenient place.

  3. For the BME280 I had to add a version to manifest.json:

“iot_class”: “local_push”,
“version”: “1.1.1”
}

Changed the “The Bosch BME280 Environmental Sensor integration is deprecated and …” message in init.py to something appropriate:

_LOGGER.warning(
"Now a Custom Component… "
)

  1. Copied the bme280 folder located in homeassistant/components into the config/custom_components folder of my Rpi install (I used Samba Share but other methods can be used).

  2. Rebooted HA and the custom component was be being used instead of the integration.

HA 2022.7 broke it again… :frowning:
Now Python dependencies are not met, bme280spi cannot be used.

Unfortunately, I do not have sufficient Python skills to create custom components myself, any help would be appreciated.

Hi, did you found some solution for bme280, via i2c bus in raspberry pi?, I have the same issue :frowning:, also for DHT sensors integration …

Thanks in advance for any tips.

If using I2C, you can for now get away with removinf everything related to SPI like so:

manifest.json

{
  "domain": "bme280",
  "name": "Bosch BME280 Environmental Sensor",
  "documentation": "https://www.home-assistant.io/integrations/bme280",
  "requirements": [
    "i2csense==0.0.4",
    "smbus-cffi==0.5.1"
  ],
  "codeowners": [],
  "iot_class": "local_push",
  "loggers": [ "i2csense", "smbus"],
  "version": "1.0.0"
}

sensor.py:
comment out if statement.like below. For me, that starts at line 61.

if CONF_SPI_BUS in sensor_conf and CONF_SPI_DEV in sensor_conf:
        #spi_dev = sensor_conf[CONF_SPI_DEV]
        #spi_bus = sensor_conf[CONF_SPI_BUS]
        #_LOGGER.debug("BME280 sensor initialize at %s.%s", spi_bus, spi_dev)
        #sensor = await hass.async_add_executor_job(
        #    partial(
        #        BME280_spi,
        #        t_mode=sensor_conf[CONF_OVERSAMPLING_TEMP],
        #        p_mode=sensor_conf[CONF_OVERSAMPLING_PRES],
        #        h_mode=sensor_conf[CONF_OVERSAMPLING_HUM],
        #        standby=sensor_conf[CONF_T_STANDBY],
        #        filter=sensor_conf[CONF_FILTER_MODE],
        #        spi_bus=sensor_conf[CONF_SPI_BUS],
        #        spi_dev=sensor_conf[CONF_SPI_DEV],
        #    )
        #)
        #if not sensor.sample_ok:
            _LOGGER.error("BME280 sensor using SPI not supported.")
        #    return
    else:

Let’s see how long that works…

1 Like

In my case still does not works :frowning:, now i have two faults in logs:

Logger: homeassistant.loader
Source: loader.py:635
First occurred: 09:08:18 (1 occurrences)
Last logged: 09:08:18

Unexpected exception importing platform custom_components.bme280.sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/loader.py", line 618, in get_platform
    cache[full_name] = self._import_platform(platform_name)
  File "/usr/src/homeassistant/homeassistant/loader.py", line 635, in _import_platform
    return importlib.import_module(f"{self.pkg_path}.{platform_name}")
  File "/usr/local/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 879, in exec_module
  File "<frozen importlib._bootstrap_external>", line 1017, in get_code
  File "<frozen importlib._bootstrap_external>", line 947, in source_to_code
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/config/custom_components/bme280/sensor.py", line 80
    else:
         ^
IndentationError: unindent does not match any outer indentation level

and:

Logger: homeassistant.setup
Source: setup.py:298
First occurred: 09:08:18 (1 occurrences)
Last logged: 09:08:18

Unable to prepare setup for platform bme280.sensor: Platform not found (Exception importing custom_components.bme280.sensor).

my configuration.yaml:

bme280:
  - name: PARTER
    delta_temperature: 0.5
    scan_interval: 30

my current core version: core-2022.7.7
Home Assistant OS 8.4

Hi,
I am also in same situation is there a solution to this problem?

Not what you may want to hear but, the only way I found was to forget trying to use the gpio and spi etc on the rpi & move over to esp home. esp D1 mini boards will plug into a usb port with a cable and go that route to get you up and running. or if you have a spare esp 8266 board you could poss use that. Install esphome and attach the sensor the esp board and add the relevant code thru esphome to get you going. Its not too hard of a task once you get started and it seems to be the way forward as it is more compatable with a lot more other hardware (pc, Nas, nuc, etc) and not limited just to the rpi. ( I know the rpi can do it but it is limited to the rpi ecosystem, If you ever decide to upgrade to a different hardware system then your esphome devices will move with very little reconfiguring, plug and play style) you can even power them from a usb wall plug and place the esp/sensors wherever you want (unlinke when its attached to an rpi).