2019-04-03 15:40:03 +00:00
|
|
|
"""Support for BME680 Sensor over SMBus."""
|
2018-01-23 07:51:52 +00:00
|
|
|
import logging
|
2019-10-15 11:39:51 +00:00
|
|
|
import threading
|
2020-02-13 21:57:07 +00:00
|
|
|
from time import monotonic, sleep
|
2018-01-23 07:51:52 +00:00
|
|
|
|
2019-10-15 11:39:51 +00:00
|
|
|
import bme680 # pylint: disable=import-error
|
2021-03-02 08:02:04 +00:00
|
|
|
from smbus import SMBus
|
2018-01-23 07:51:52 +00:00
|
|
|
import voluptuous as vol
|
|
|
|
|
2021-03-22 11:37:16 +00:00
|
|
|
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
|
2020-02-28 19:46:48 +00:00
|
|
|
from homeassistant.const import (
|
|
|
|
CONF_MONITORED_CONDITIONS,
|
|
|
|
CONF_NAME,
|
2020-09-05 19:09:14 +00:00
|
|
|
PERCENTAGE,
|
2020-02-28 19:46:48 +00:00
|
|
|
TEMP_FAHRENHEIT,
|
|
|
|
)
|
2018-01-23 07:51:52 +00:00
|
|
|
import homeassistant.helpers.config_validation as cv
|
|
|
|
from homeassistant.util.temperature import celsius_to_fahrenheit
|
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
CONF_I2C_ADDRESS = "i2c_address"
|
|
|
|
CONF_I2C_BUS = "i2c_bus"
|
|
|
|
CONF_OVERSAMPLING_TEMP = "oversampling_temperature"
|
|
|
|
CONF_OVERSAMPLING_PRES = "oversampling_pressure"
|
|
|
|
CONF_OVERSAMPLING_HUM = "oversampling_humidity"
|
|
|
|
CONF_FILTER_SIZE = "filter_size"
|
|
|
|
CONF_GAS_HEATER_TEMP = "gas_heater_temperature"
|
|
|
|
CONF_GAS_HEATER_DURATION = "gas_heater_duration"
|
|
|
|
CONF_AQ_BURN_IN_TIME = "aq_burn_in_time"
|
|
|
|
CONF_AQ_HUM_BASELINE = "aq_humidity_baseline"
|
|
|
|
CONF_AQ_HUM_WEIGHTING = "aq_humidity_bias"
|
|
|
|
CONF_TEMP_OFFSET = "temp_offset"
|
|
|
|
|
|
|
|
|
|
|
|
DEFAULT_NAME = "BME680 Sensor"
|
2018-01-23 07:51:52 +00:00
|
|
|
DEFAULT_I2C_ADDRESS = 0x77
|
|
|
|
DEFAULT_I2C_BUS = 1
|
|
|
|
DEFAULT_OVERSAMPLING_TEMP = 8 # Temperature oversampling x 8
|
|
|
|
DEFAULT_OVERSAMPLING_PRES = 4 # Pressure oversampling x 4
|
|
|
|
DEFAULT_OVERSAMPLING_HUM = 2 # Humidity oversampling x 2
|
|
|
|
DEFAULT_FILTER_SIZE = 3 # IIR Filter Size
|
|
|
|
DEFAULT_GAS_HEATER_TEMP = 320 # Temperature in celsius 200 - 400
|
|
|
|
DEFAULT_GAS_HEATER_DURATION = 150 # Heater duration in ms 1 - 4032
|
|
|
|
DEFAULT_AQ_BURN_IN_TIME = 300 # 300 second burn in time for AQ gas measurement
|
|
|
|
DEFAULT_AQ_HUM_BASELINE = 40 # 40%, an optimal indoor humidity.
|
|
|
|
DEFAULT_AQ_HUM_WEIGHTING = 25 # 25% Weighting of humidity to gas in AQ score
|
2019-01-02 18:02:29 +00:00
|
|
|
DEFAULT_TEMP_OFFSET = 0 # No calibration out of the box.
|
2018-01-23 07:51:52 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
SENSOR_TEMP = "temperature"
|
|
|
|
SENSOR_HUMID = "humidity"
|
|
|
|
SENSOR_PRESS = "pressure"
|
|
|
|
SENSOR_GAS = "gas"
|
|
|
|
SENSOR_AQ = "airquality"
|
2018-01-23 07:51:52 +00:00
|
|
|
SENSOR_TYPES = {
|
2019-07-31 19:25:30 +00:00
|
|
|
SENSOR_TEMP: ["Temperature", None],
|
2020-09-05 19:09:14 +00:00
|
|
|
SENSOR_HUMID: ["Humidity", PERCENTAGE],
|
2019-07-31 19:25:30 +00:00
|
|
|
SENSOR_PRESS: ["Pressure", "mb"],
|
|
|
|
SENSOR_GAS: ["Gas Resistance", "Ohms"],
|
2020-09-05 19:09:14 +00:00
|
|
|
SENSOR_AQ: ["Air Quality", PERCENTAGE],
|
2018-01-23 07:51:52 +00:00
|
|
|
}
|
|
|
|
DEFAULT_MONITORED = [SENSOR_TEMP, SENSOR_HUMID, SENSOR_PRESS, SENSOR_AQ]
|
2020-04-04 18:05:15 +00:00
|
|
|
OVERSAMPLING_VALUES = {0, 1, 2, 4, 8, 16}
|
|
|
|
FILTER_VALUES = {0, 1, 3, 7, 15, 31, 63, 127}
|
2018-01-23 07:51:52 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
|
|
|
{
|
|
|
|
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
|
|
|
vol.Optional(CONF_I2C_ADDRESS, default=DEFAULT_I2C_ADDRESS): cv.positive_int,
|
|
|
|
vol.Optional(CONF_MONITORED_CONDITIONS, default=DEFAULT_MONITORED): vol.All(
|
|
|
|
cv.ensure_list, [vol.In(SENSOR_TYPES)]
|
|
|
|
),
|
|
|
|
vol.Optional(CONF_I2C_BUS, default=DEFAULT_I2C_BUS): cv.positive_int,
|
|
|
|
vol.Optional(
|
|
|
|
CONF_OVERSAMPLING_TEMP, default=DEFAULT_OVERSAMPLING_TEMP
|
|
|
|
): vol.All(vol.Coerce(int), vol.In(OVERSAMPLING_VALUES)),
|
|
|
|
vol.Optional(
|
|
|
|
CONF_OVERSAMPLING_PRES, default=DEFAULT_OVERSAMPLING_PRES
|
|
|
|
): vol.All(vol.Coerce(int), vol.In(OVERSAMPLING_VALUES)),
|
|
|
|
vol.Optional(CONF_OVERSAMPLING_HUM, default=DEFAULT_OVERSAMPLING_HUM): vol.All(
|
|
|
|
vol.Coerce(int), vol.In(OVERSAMPLING_VALUES)
|
|
|
|
),
|
|
|
|
vol.Optional(CONF_FILTER_SIZE, default=DEFAULT_FILTER_SIZE): vol.All(
|
|
|
|
vol.Coerce(int), vol.In(FILTER_VALUES)
|
|
|
|
),
|
|
|
|
vol.Optional(CONF_GAS_HEATER_TEMP, default=DEFAULT_GAS_HEATER_TEMP): vol.All(
|
|
|
|
vol.Coerce(int), vol.Range(200, 400)
|
|
|
|
),
|
|
|
|
vol.Optional(
|
|
|
|
CONF_GAS_HEATER_DURATION, default=DEFAULT_GAS_HEATER_DURATION
|
|
|
|
): vol.All(vol.Coerce(int), vol.Range(1, 4032)),
|
|
|
|
vol.Optional(
|
|
|
|
CONF_AQ_BURN_IN_TIME, default=DEFAULT_AQ_BURN_IN_TIME
|
|
|
|
): cv.positive_int,
|
|
|
|
vol.Optional(CONF_AQ_HUM_BASELINE, default=DEFAULT_AQ_HUM_BASELINE): vol.All(
|
|
|
|
vol.Coerce(int), vol.Range(1, 100)
|
|
|
|
),
|
|
|
|
vol.Optional(CONF_AQ_HUM_WEIGHTING, default=DEFAULT_AQ_HUM_WEIGHTING): vol.All(
|
|
|
|
vol.Coerce(int), vol.Range(1, 100)
|
|
|
|
),
|
|
|
|
vol.Optional(CONF_TEMP_OFFSET, default=DEFAULT_TEMP_OFFSET): vol.All(
|
|
|
|
vol.Coerce(float), vol.Range(-100.0, 100.0)
|
|
|
|
),
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
2018-01-23 07:51:52 +00:00
|
|
|
"""Set up the BME680 sensor."""
|
|
|
|
SENSOR_TYPES[SENSOR_TEMP][1] = hass.config.units.temperature_unit
|
2020-04-09 07:26:06 +00:00
|
|
|
name = config[CONF_NAME]
|
2018-01-23 07:51:52 +00:00
|
|
|
|
2020-10-15 14:22:17 +00:00
|
|
|
sensor_handler = await hass.async_add_executor_job(_setup_bme680, config)
|
2018-01-23 07:51:52 +00:00
|
|
|
if sensor_handler is None:
|
2018-01-24 11:44:29 +00:00
|
|
|
return
|
2018-01-23 07:51:52 +00:00
|
|
|
|
|
|
|
dev = []
|
2018-01-24 11:44:29 +00:00
|
|
|
for variable in config[CONF_MONITORED_CONDITIONS]:
|
2019-07-31 19:25:30 +00:00
|
|
|
dev.append(
|
|
|
|
BME680Sensor(sensor_handler, variable, SENSOR_TYPES[variable][1], name)
|
|
|
|
)
|
2018-01-23 07:51:52 +00:00
|
|
|
|
2018-08-24 14:37:30 +00:00
|
|
|
async_add_entities(dev)
|
2018-01-24 11:44:29 +00:00
|
|
|
return
|
2018-01-23 07:51:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
def _setup_bme680(config):
|
|
|
|
"""Set up and configure the BME680 sensor."""
|
|
|
|
|
|
|
|
sensor_handler = None
|
|
|
|
sensor = None
|
|
|
|
try:
|
2020-04-09 07:26:06 +00:00
|
|
|
i2c_address = config[CONF_I2C_ADDRESS]
|
|
|
|
bus = SMBus(config[CONF_I2C_BUS])
|
2018-01-23 07:51:52 +00:00
|
|
|
sensor = bme680.BME680(i2c_address, bus)
|
|
|
|
|
|
|
|
# Configure Oversampling
|
|
|
|
os_lookup = {
|
|
|
|
0: bme680.OS_NONE,
|
|
|
|
1: bme680.OS_1X,
|
|
|
|
2: bme680.OS_2X,
|
|
|
|
4: bme680.OS_4X,
|
|
|
|
8: bme680.OS_8X,
|
2019-07-31 19:25:30 +00:00
|
|
|
16: bme680.OS_16X,
|
2018-01-23 07:51:52 +00:00
|
|
|
}
|
2020-04-09 07:26:06 +00:00
|
|
|
sensor.set_temperature_oversample(os_lookup[config[CONF_OVERSAMPLING_TEMP]])
|
|
|
|
sensor.set_temp_offset(config[CONF_TEMP_OFFSET])
|
|
|
|
sensor.set_humidity_oversample(os_lookup[config[CONF_OVERSAMPLING_HUM]])
|
|
|
|
sensor.set_pressure_oversample(os_lookup[config[CONF_OVERSAMPLING_PRES]])
|
2018-01-23 07:51:52 +00:00
|
|
|
|
|
|
|
# Configure IIR Filter
|
|
|
|
filter_lookup = {
|
|
|
|
0: bme680.FILTER_SIZE_0,
|
|
|
|
1: bme680.FILTER_SIZE_1,
|
|
|
|
3: bme680.FILTER_SIZE_3,
|
|
|
|
7: bme680.FILTER_SIZE_7,
|
|
|
|
15: bme680.FILTER_SIZE_15,
|
|
|
|
31: bme680.FILTER_SIZE_31,
|
|
|
|
63: bme680.FILTER_SIZE_63,
|
2019-07-31 19:25:30 +00:00
|
|
|
127: bme680.FILTER_SIZE_127,
|
2018-01-23 07:51:52 +00:00
|
|
|
}
|
2020-04-09 07:26:06 +00:00
|
|
|
sensor.set_filter(filter_lookup[config[CONF_FILTER_SIZE]])
|
2018-01-23 07:51:52 +00:00
|
|
|
|
|
|
|
# Configure the Gas Heater
|
|
|
|
if (
|
2019-07-31 19:25:30 +00:00
|
|
|
SENSOR_GAS in config[CONF_MONITORED_CONDITIONS]
|
|
|
|
or SENSOR_AQ in config[CONF_MONITORED_CONDITIONS]
|
2018-01-23 07:51:52 +00:00
|
|
|
):
|
|
|
|
sensor.set_gas_status(bme680.ENABLE_GAS_MEAS)
|
|
|
|
sensor.set_gas_heater_duration(config[CONF_GAS_HEATER_DURATION])
|
|
|
|
sensor.set_gas_heater_temperature(config[CONF_GAS_HEATER_TEMP])
|
|
|
|
sensor.select_gas_heater_profile(0)
|
|
|
|
else:
|
|
|
|
sensor.set_gas_status(bme680.DISABLE_GAS_MEAS)
|
2019-09-04 17:09:24 +00:00
|
|
|
except (RuntimeError, OSError):
|
2018-01-26 05:01:43 +00:00
|
|
|
_LOGGER.error("BME680 sensor not detected at 0x%02x", i2c_address)
|
2018-01-23 07:51:52 +00:00
|
|
|
return None
|
|
|
|
|
|
|
|
sensor_handler = BME680Handler(
|
|
|
|
sensor,
|
2019-07-31 19:25:30 +00:00
|
|
|
(
|
|
|
|
SENSOR_GAS in config[CONF_MONITORED_CONDITIONS]
|
|
|
|
or SENSOR_AQ in config[CONF_MONITORED_CONDITIONS]
|
|
|
|
),
|
2018-01-23 07:51:52 +00:00
|
|
|
config[CONF_AQ_BURN_IN_TIME],
|
|
|
|
config[CONF_AQ_HUM_BASELINE],
|
2019-07-31 19:25:30 +00:00
|
|
|
config[CONF_AQ_HUM_WEIGHTING],
|
2018-01-23 07:51:52 +00:00
|
|
|
)
|
|
|
|
sleep(0.5) # Wait for device to stabilize
|
|
|
|
if not sensor_handler.sensor_data.temperature:
|
|
|
|
_LOGGER.error("BME680 sensor failed to Initialize")
|
|
|
|
return None
|
|
|
|
|
|
|
|
return sensor_handler
|
|
|
|
|
|
|
|
|
|
|
|
class BME680Handler:
|
|
|
|
"""BME680 sensor working in i2C bus."""
|
|
|
|
|
|
|
|
class SensorData:
|
|
|
|
"""Sensor data representation."""
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
"""Initialize the sensor data object."""
|
|
|
|
self.temperature = None
|
|
|
|
self.humidity = None
|
|
|
|
self.pressure = None
|
|
|
|
self.gas_resistance = None
|
|
|
|
self.air_quality = None
|
|
|
|
|
|
|
|
def __init__(
|
2019-07-31 19:25:30 +00:00
|
|
|
self,
|
|
|
|
sensor,
|
|
|
|
gas_measurement=False,
|
|
|
|
burn_in_time=300,
|
|
|
|
hum_baseline=40,
|
|
|
|
hum_weighting=25,
|
2018-01-23 07:51:52 +00:00
|
|
|
):
|
|
|
|
"""Initialize the sensor handler."""
|
|
|
|
self.sensor_data = BME680Handler.SensorData()
|
|
|
|
self._sensor = sensor
|
|
|
|
self._gas_sensor_running = False
|
|
|
|
self._hum_baseline = hum_baseline
|
|
|
|
self._hum_weighting = hum_weighting
|
|
|
|
self._gas_baseline = None
|
|
|
|
|
|
|
|
if gas_measurement:
|
2019-07-31 19:25:30 +00:00
|
|
|
|
2018-01-23 07:51:52 +00:00
|
|
|
threading.Thread(
|
|
|
|
target=self._run_gas_sensor,
|
2019-07-31 19:25:30 +00:00
|
|
|
kwargs={"burn_in_time": burn_in_time},
|
|
|
|
name="BME680Handler_run_gas_sensor",
|
2018-01-23 07:51:52 +00:00
|
|
|
).start()
|
|
|
|
self.update(first_read=True)
|
|
|
|
|
|
|
|
def _run_gas_sensor(self, burn_in_time):
|
|
|
|
"""Calibrate the Air Quality Gas Baseline."""
|
2018-01-24 11:44:29 +00:00
|
|
|
if self._gas_sensor_running:
|
2018-01-23 07:51:52 +00:00
|
|
|
return
|
|
|
|
|
2018-01-24 11:44:29 +00:00
|
|
|
self._gas_sensor_running = True
|
|
|
|
|
2018-01-27 19:58:27 +00:00
|
|
|
# Pause to allow initial data read for device validation.
|
2018-01-24 11:44:29 +00:00
|
|
|
sleep(1)
|
|
|
|
|
2020-02-13 21:57:07 +00:00
|
|
|
start_time = monotonic()
|
|
|
|
curr_time = monotonic()
|
2018-01-24 11:44:29 +00:00
|
|
|
burn_in_data = []
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
_LOGGER.info(
|
|
|
|
"Beginning %d second gas sensor burn in for Air Quality", burn_in_time
|
|
|
|
)
|
2018-01-24 11:44:29 +00:00
|
|
|
while curr_time - start_time < burn_in_time:
|
2020-02-13 21:57:07 +00:00
|
|
|
curr_time = monotonic()
|
2019-07-31 19:25:30 +00:00
|
|
|
if self._sensor.get_sensor_data() and self._sensor.data.heat_stable:
|
2018-01-24 11:44:29 +00:00
|
|
|
gas_resistance = self._sensor.data.gas_resistance
|
|
|
|
burn_in_data.append(gas_resistance)
|
|
|
|
self.sensor_data.gas_resistance = gas_resistance
|
2019-07-31 19:25:30 +00:00
|
|
|
_LOGGER.debug(
|
|
|
|
"AQ Gas Resistance Baseline reading %2f Ohms", gas_resistance
|
|
|
|
)
|
2018-01-24 11:44:29 +00:00
|
|
|
sleep(1)
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
_LOGGER.debug(
|
|
|
|
"AQ Gas Resistance Burn In Data (Size: %d): \n\t%s",
|
|
|
|
len(burn_in_data),
|
|
|
|
burn_in_data,
|
|
|
|
)
|
2018-01-24 11:44:29 +00:00
|
|
|
self._gas_baseline = sum(burn_in_data[-50:]) / 50.0
|
|
|
|
_LOGGER.info("Completed gas sensor burn in for Air Quality")
|
|
|
|
_LOGGER.info("AQ Gas Resistance Baseline: %f", self._gas_baseline)
|
|
|
|
while True:
|
2019-07-31 19:25:30 +00:00
|
|
|
if self._sensor.get_sensor_data() and self._sensor.data.heat_stable:
|
|
|
|
self.sensor_data.gas_resistance = self._sensor.data.gas_resistance
|
2018-01-24 11:44:29 +00:00
|
|
|
self.sensor_data.air_quality = self._calculate_aq_score()
|
|
|
|
sleep(1)
|
|
|
|
|
2018-01-23 07:51:52 +00:00
|
|
|
def update(self, first_read=False):
|
|
|
|
"""Read sensor data."""
|
|
|
|
if first_read:
|
|
|
|
# Attempt first read, it almost always fails first attempt
|
|
|
|
self._sensor.get_sensor_data()
|
|
|
|
if self._sensor.get_sensor_data():
|
|
|
|
self.sensor_data.temperature = self._sensor.data.temperature
|
|
|
|
self.sensor_data.humidity = self._sensor.data.humidity
|
|
|
|
self.sensor_data.pressure = self._sensor.data.pressure
|
|
|
|
|
|
|
|
def _calculate_aq_score(self):
|
|
|
|
"""Calculate the Air Quality Score."""
|
|
|
|
hum_baseline = self._hum_baseline
|
|
|
|
hum_weighting = self._hum_weighting
|
|
|
|
gas_baseline = self._gas_baseline
|
|
|
|
|
|
|
|
gas_resistance = self.sensor_data.gas_resistance
|
|
|
|
gas_offset = gas_baseline - gas_resistance
|
|
|
|
|
|
|
|
hum = self.sensor_data.humidity
|
|
|
|
hum_offset = hum - hum_baseline
|
|
|
|
|
|
|
|
# Calculate hum_score as the distance from the hum_baseline.
|
|
|
|
if hum_offset > 0:
|
|
|
|
hum_score = (
|
2019-07-31 19:25:30 +00:00
|
|
|
(100 - hum_baseline - hum_offset) / (100 - hum_baseline) * hum_weighting
|
2018-01-23 07:51:52 +00:00
|
|
|
)
|
|
|
|
else:
|
2019-07-31 19:25:30 +00:00
|
|
|
hum_score = (hum_baseline + hum_offset) / hum_baseline * hum_weighting
|
2018-01-23 07:51:52 +00:00
|
|
|
|
|
|
|
# Calculate gas_score as the distance from the gas_baseline.
|
|
|
|
if gas_offset > 0:
|
|
|
|
gas_score = (gas_resistance / gas_baseline) * (100 - hum_weighting)
|
|
|
|
else:
|
|
|
|
gas_score = 100 - hum_weighting
|
|
|
|
|
|
|
|
# Calculate air quality score.
|
|
|
|
return hum_score + gas_score
|
|
|
|
|
|
|
|
|
2021-03-22 11:37:16 +00:00
|
|
|
class BME680Sensor(SensorEntity):
|
2018-01-23 07:51:52 +00:00
|
|
|
"""Implementation of the BME680 sensor."""
|
|
|
|
|
|
|
|
def __init__(self, bme680_client, sensor_type, temp_unit, name):
|
|
|
|
"""Initialize the sensor."""
|
|
|
|
self.client_name = name
|
|
|
|
self._name = SENSOR_TYPES[sensor_type][0]
|
|
|
|
self.bme680_client = bme680_client
|
|
|
|
self.temp_unit = temp_unit
|
|
|
|
self.type = sensor_type
|
|
|
|
self._state = None
|
|
|
|
self._unit_of_measurement = SENSOR_TYPES[sensor_type][1]
|
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
|
|
|
"""Return the name of the sensor."""
|
2019-09-03 15:09:59 +00:00
|
|
|
return f"{self.client_name} {self._name}"
|
2018-01-23 07:51:52 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def state(self):
|
|
|
|
"""Return the state of the sensor."""
|
|
|
|
return self._state
|
|
|
|
|
|
|
|
@property
|
|
|
|
def unit_of_measurement(self):
|
|
|
|
"""Return the unit of measurement of the sensor."""
|
|
|
|
return self._unit_of_measurement
|
|
|
|
|
2018-10-01 06:55:43 +00:00
|
|
|
async def async_update(self):
|
2018-01-23 07:51:52 +00:00
|
|
|
"""Get the latest data from the BME680 and update the states."""
|
2020-10-15 14:22:17 +00:00
|
|
|
await self.hass.async_add_executor_job(self.bme680_client.update)
|
2018-01-23 07:51:52 +00:00
|
|
|
if self.type == SENSOR_TEMP:
|
|
|
|
temperature = round(self.bme680_client.sensor_data.temperature, 1)
|
|
|
|
if self.temp_unit == TEMP_FAHRENHEIT:
|
|
|
|
temperature = round(celsius_to_fahrenheit(temperature), 1)
|
|
|
|
self._state = temperature
|
|
|
|
elif self.type == SENSOR_HUMID:
|
|
|
|
self._state = round(self.bme680_client.sensor_data.humidity, 1)
|
|
|
|
elif self.type == SENSOR_PRESS:
|
|
|
|
self._state = round(self.bme680_client.sensor_data.pressure, 1)
|
|
|
|
elif self.type == SENSOR_GAS:
|
2019-07-31 19:25:30 +00:00
|
|
|
self._state = int(round(self.bme680_client.sensor_data.gas_resistance, 0))
|
2018-01-23 07:51:52 +00:00
|
|
|
elif self.type == SENSOR_AQ:
|
|
|
|
aq_score = self.bme680_client.sensor_data.air_quality
|
|
|
|
if aq_score is not None:
|
|
|
|
self._state = round(aq_score, 1)
|