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:
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… "
)
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).
Rebooted HA and the custom component was be being used instead of the integration.
In my case still does not works , 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).
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).