Git Product home page Git Product logo

homeassistant-airthings's People

Contributors

gkreitz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

homeassistant-airthings's Issues

VOC in ppm

Hi,

I think that the sensor actually delivers the values in units of ppb as opposed to ppm?

have modified this as well as a couple of other little icons in sensors.yaml

import logging
import struct
import datetime

from homeassistant.components.sensor import PLATFORM_SCHEMA
import homeassistant.helpers.config_validation as cv
import voluptuous as vol

from homeassistant.helpers.entity import Entity
from homeassistant.util import Throttle
from homeassistant.const import (TEMP_CELSIUS, DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_PRESSURE, STATE_UNKNOWN)

_LOGGER = logging.getLogger(__name__)

DOMAIN = 'airthings'
CONF_MAC = 'mac'

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
    vol.Required(CONF_MAC): cv.string,
})

MIN_TIME_BETWEEN_UPDATES = datetime.timedelta(minutes=15)
SENSOR_TYPES = [
    ['temperature', 'Temperature', TEMP_CELSIUS, None, DEVICE_CLASS_TEMPERATURE],
    ['co2', 'CO2', 'ppm', 'mdi:periodic-table-co2', None],
    ['pressure', 'Pressure', 'mbar', 'mdi:gauge', DEVICE_CLASS_PRESSURE],
    ['humidity', 'Humidity', '%', 'mdi:water-percent', DEVICE_CLASS_HUMIDITY],
    ['voc', 'VOC', 'ppb', 'mdi:biohazard', None],
    ['short_radon', 'Short-term Radon', 'Bq/m3', 'mdi:biohazard', None],
    ['long_radon', 'Long-term Radon', 'Bq/m3', 'mdi:biohazard', None],
]



def setup_platform(hass, config, add_devices, discovery_info=None):
    """Setup the sensor platform."""
    _LOGGER.debug("Starting airthings")
    reader = AirthingsWavePlusDataReader(config.get(CONF_MAC))
    add_devices([ AirthingsSensorEntity(reader, key,name,unit,icon,device_class) for [key, name, unit, icon, device_class] in SENSOR_TYPES])

class AirthingsWavePlusDataReader:
    def __init__(self, mac):
        self._mac = mac
        self._state = { }

    def get_data(self, key):
        if key in self._state:
            return self._state[key]
        return STATE_UNKNOWN

    @property
    def mac(self):
        return self._mac

    @Throttle(MIN_TIME_BETWEEN_UPDATES)
    def update(self):
        _LOGGER.debug("Airthings updating data")
        import pygatt
        from pygatt.backends import Characteristic
        adapter = pygatt.backends.GATTToolBackend()
        char = 'b42e2a68-ade7-11e4-89d3-123b93f75cba'
        try:
            # reset_on_start must be false - reset is hardcoded to do sudo, which does not exist in the hass.io Docker container.
            adapter.start(reset_on_start=False)
            device = adapter.connect(self._mac)
            # Unclear why this does not work. Seems broken in the command line tool too. Hopefully handle is stable...
            #value = device.char_read(char,timeout=10)
            value = device.char_read_handle('0x000d',timeout=10)
            (humidity, light, sh_rad, lo_rad, temp, pressure, co2, voc) = struct.unpack('<xbxbHHHHHHxxxx', value)
            self._state['humidity'] = humidity / 2.0
            self._state['light'] = light * 1.0
            self._state['short_radon'] = sh_rad
            self._state['long_radon'] = lo_rad
            self._state['temperature'] = temp / 100.
            self._state['pressure'] = pressure / 50.
            self._state['co2'] = co2 * 1.
            self._state['voc'] = voc * 1.
        finally:
            adapter.stop()

class AirthingsSensorEntity(Entity):
    """Representation of a Sensor."""

    def __init__(self, reader, key, name, unit, icon, device_class):
        """Initialize the sensor."""
        self._reader = reader
        self._key = key
        self._name = name
        self._unit = unit
        self._icon = icon
        self._device_class = device_class

    @property
    def name(self):
        """Return the name of the sensor."""
        return 'Airthings {}'.format(self._name)

    @property
    def icon(self):
        """Return the icon of the sensor."""
        return self._icon

    @property
    def device_class(self):
        """Return the icon of the sensor."""
        return self._device_class

    @property
    def state(self):
        """Return the state of the sensor."""
        return self._reader.get_data(self._key)

    @property
    def unit_of_measurement(self):
        """Return the unit of measurement."""
        return self._unit

    @property
    def unique_id(self):
        return '{}-{}'.format(self._reader.mac, self._name)

    def update(self):
        """Fetch new state data for the sensor.

        This is the only method that should fetch new data for Home Assistant.
        """
        self._reader.update()

Add support for the HACS repository?

Hi gkreitz

First of all, thanks for a great module for HA and AirThings Wave Plus. Works like a charm.

Is it possible to add support for the HACS repository? Like having a hacs.json?

{
    "name": "Airthings Wave Plus",
    "domains": ["sensor", "binary_sensor"],
    "homeassistant": "0.105",
    "render_readme": true
}

Let me hear your thoughts.

Thanks!

Humidity is displayedas -'ve value

Love the plugin d appreciate you may no longer be workin on it.

For some reason, allmradings are fine except humifity which is displayed as a - value.

Are you seeing this?

Thanks,

Raspberry Pi 3 Airthings stop working after 7 hours

Helle thank you very much for making this component. I have been using it for a few days and noticed that it stops getting data from the device after about 7 hours. I am running hassos 3.5 home assistant 0.102.3 on a raspberry Pi 3B and this is the same issue that I had with the Xiaomi BLE Temperature/Humidity sensor and the Mi Flora plant sensor for a long time. Cant remember when this started to become a problem for those components but it used to be stable and lots of other people have the same problem. As this was working and suddenly 2 BLE components stopped working I suspect the problem was caused by hassos, Hassio or home assistant but I dont have the skills to find out where the problem is and since lots of people have BLE trouble also with BLE tracker for long time and that it not yet resolved I guess it is complicated. But I have seen that somebody has been able to fix this with a custom component: https://github.com/custom-components/sensor.mitemp_bt. Is there any chance that somebody with the right skills could do a similar fix for this component.
home-assistant/core#24313

Regards

Henning

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.