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).