Add I2c BME280 temperature, humidity and pressure sensor for Raspberry Pi #7989
Conversation
|
@azogue, thanks for your PR! By analyzing the history of the files in this pull request, we identified @balloob, @fabaff and @robbiet480 to be potential reviewers. |
|
I think that |
|
@fabaff, I thought about that structure, but I dismissed it by verifying that the common I2c bus logic is minimal compared to the specific logic required for each sensor. Although the idea of running and parsing the output of So what do you think I should do now? I have the other 2 PRs ready, I was planning to propose them today. We can try switching to component i2c + platforms after integrating these, or do it sooner. |
|
For the three sensors I'm working with (BME280, BH1750 and HTU21D), after getting the i2c bus: import smbus
bus = smbus.SMBus(config.get(CONF_I2C_BUS))The only common code relative to the i2c bus are the calls to: bus.write_byte
bus.write_byte_data
bus.read_byte_data
bus.read_i2c_block_data
bus.read_word_dataAnother thing I thought of is to share the bus handler in with hass.data['SMBUS'] as bus:
bus.read_byte_data ...
...I do not know if it's a good idea... |
pvizeli
left a comment
There was a problem hiding this comment.
Amazing work but it is not allow to have proto specific code inside HomeAssistant. Please export this device specific code into a new mini library and use this for this sensor.
|
@pvizeli, thanks for your review. There are already a lot of libraries to handle sensors on the I2c bus, some better and some worse, some more feature-complete and some simpler. For that reason, there are already multiple ways to integrate one of these sensors into Home Assistant, usually via command line sensors. The reason for these PRs was to implement a simple, but feature-complete, and explicit way of including these sensors in HA, I was not aware of the prohibition of including 'proto specific code' (which I understand you mean the byte operations to talk to sensors, extracted from its spec sheets, right?) I guess I can upload the nth I2c sensor library to pypi, and place the classes there to handle the sensors. Any suggestions for the name? |
|
@pvizeli , I've done that. I uploaded a new library # homeassistant.components.sensor.bme280
i2csense==0.0.2or # homeassistant.components.sensor.bme280
# i2csense==0.0.2like the smbus lib: # homeassistant.components.sensor.bme280
# homeassistant.components.sensor.envirophat
# smbus-cffi==0.5.1If you were so kind to review these changes, please... I'm going to push the changes for the other PRs |
|
Good work 👍 You can add this here: https://github.com/home-assistant/home-assistant/blob/dev/script/gen_requirements_all.py#L9 Please remove |
|
Thanks for reviewing @pvizeli, I will do the changes, but first I want to polish a little more the new library, so I will increase the version needed here and in the others PRs (the BH1750 light level sensor is giving me consistent but very low lux values, so I'm not sure about the implementation, I need to play with sensitivity values and low/high res modes to be sure). I hope this week will be done. |
|
Hi @pvizeli, changes are done, and I've increased the version of the external lib to use. I think is ready to go. The light sensors were working fine, in fact, this implementation is much more complete than the ones I found on the network for arduinos or in python. It was a problem of sensor location. I've added an optional light level I've pushed the changes to the others PR's: #8049 and #8050. Changes in |
|
Amazing. I'll merge it after tests pass |
|
Please rebase others and add my last changes to that |
…y Pi (home-assistant#7989) * Add new BME280 temperature, humidity and pressure sensor * Add BME280 sensor to optional requirements and .coveragerc * move validation to sensor handler, async fix in setup * fix Invalid attribute name * review changes: move sensor code to external module * async fix * add i2csense to COMMENT_REQUIREMENTS, require i2csense 0.0.3, round prec to 1 dec * change style for hass * fix lint * fix lint part 2
Introduction:
Many of us use a Raspberry Pi to run Home Assistant, and we have different sensors connected to it, but for many of them there is no direct support, and it is necessary to use template sensors or command line sensors to make them work within Home Assistant.
Problem is using shell commands to retrieve the values of some sensors limits the working modes of these sensors, and, IMHO, it could be an entry barrier for some beginners.
I think that, as it exists for sensors like the DHT11/22 or the onewire ones, specific platforms for good and cheap digital sensors, with a simple configuration in Home Assistant, are very convenient.
This is the first of a series of PR that I intend to propose for supporting I2c digital sensors compatible with Raspberry Pi. A light level sensor (BH1750) and another temperature and humidity sensor (HTU21D) will be as follows.
Description:
Bosch BME280 Environment sensor support as a sensor platform, with multiple working modes as described in its data sheet.
Senses temperature, humidity and pressure.
The docs include a section to easy install the
i2candsmbussupport for thehome_assistantuser, to get things done quickly.Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.io#2797
Example entry for
configuration.yaml(if applicable):A more complex, and customised configuration could be:
Checklist:
If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
requirements_all.txtby runningscript/gen_requirements_all.py..coveragerc.