{
"info": {
"author": "Timo Furrer",
"author_email": "tuxtimo@gmail.com",
"bugtrack_url": null,
"classifiers": [
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Natural Language :: English",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: Implementation",
"Programming Language :: Python :: Implementation :: CPython",
"Topic :: Software Development :: Libraries :: Python Modules"
],
"description": "# W1ThermSensor\n[](https://gitter.im/timofurrer/w1thermsensor?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)\n> Get the temperature from your w1 therm sensor in a single line of code!
\n> It's designed to be used with the Rasperry Pi hardware but also works on a Beagle Bone and others.\n\n***\n\n[](https://travis-ci.org/timofurrer/w1thermsensor) [](http://codecov.io/github/timofurrer/w1thermsensor?branch=master) [](https://codeclimate.com/github/timofurrer/w1thermsensor) [](https://landscape.io/github/timofurrer/w1thermsensor/master) [](https://badge.fury.io/py/w1thermsensor) [](https://github.com/ambv/black)\n\n**Raspberry Pi:** this package is available in Raspbian as `python-w1thermsensor` and `python3-w1thermsensor`.\n\n## Supported devices\n\nThe following w1 therm sensor devices are supported:\n\n* DS18S20\n* DS1822\n* DS18B20\n* DS28EA00\n* DS1825/MAX31850K\n\n## Setup\n\nThe following hardware is needed:\n\n* w1 therm compatible sensor (some of them can be bought here: [Adafruit: DS18B20](https://www.adafruit.com/search?q=DS18B20))\n* wires to connect the sensor to your board (you might need a breadboard, too)\n* a board like the Raspberry Pi or the Beagle Bone)\n\nOn the Raspberry Pi, you will need to add `dtoverlay=w1-gpio\"` (for regular connection) or `dtoverlay=w1-gpio,pullup=\"y\"` (for parasitic connection) to your /boot/config.txt. The default data pin is GPIO4 (RaspPi connector pin 7), but that can be changed from 4 to `x` with `dtoverlay=w1-gpio,gpiopin=x`.\n\n## Installation\n\n### From PIP\n\nThis possibility is supported on all distributions:\n\n pip install w1thermsensor\n\n*Note: maybe root privileges are required*\n\n### On Raspbian using `apt-get`\n\nIf you are using the `w1thermsensor` module on a Rasperry Pi running Raspbian you can install it from the official repository:\n\n```bash\nsudo apt-get install python3-w1thermsensor\n```\n\nOr if you are still using Python 2:\n\n```bash\nsudo apt-get install python-w1thermsensor\n```\n\n**Note:** For older versions of this package you might get the following error: `ImportError: No module named 'pkg_resources'` which indicates that you need to install `python-setuptools` or `python3-setuptools` respectively.\n\n**Note 2:** The Python 2 package does **not** contain the CLI tool.\n\n### Manually build and install the debian package\n\n debuild -us -uc\n dpkg -i ../python3-w1thermsensor_*.deb\n\n## Usage as python package\n\nThe usage is very simple and the interface clean..\nAll examples are with the `DS18B20` sensor - It works the same way for the other supported devices.\n\n### Basic usage with one sensor (implicit)\n\n```python\nfrom w1thermsensor import W1ThermSensor\n\nsensor = W1ThermSensor()\ntemperature_in_celsius = sensor.get_temperature()\ntemperature_in_fahrenheit = sensor.get_temperature(W1ThermSensor.DEGREES_F)\ntemperature_in_all_units = sensor.get_temperatures([\n W1ThermSensor.DEGREES_C,\n W1ThermSensor.DEGREES_F,\n W1ThermSensor.KELVIN])\n```\n\nThe need kernel modules will be automatically loaded in the constructor of the `W1ThermSensor` class.
\nIf something went wrong an exception is raised.\n\n*The first found sensor will be taken*\n\n### Basic usage with one sensor (explicit)\n\nThe DS18B20 sensor with the ID `00000588806a` will be taken.\n\n```python\nfrom w1thermsensor import W1ThermSensor\n\nsensor = W1ThermSensor(W1ThermSensor.THERM_SENSOR_DS18B20, \"00000588806a\")\ntemperature_in_celsius = sensor.get_temperature()\n```\n\n### Multiple sensors\n\nWith the `get_available_sensors` class-method you can get the ids of all available sensors.\n\n```python\nfrom w1thermsensor import W1ThermSensor\n\nfor sensor in W1ThermSensor.get_available_sensors():\n print(\"Sensor %s has temperature %.2f\" % (sensor.id, sensor.get_temperature()))\n```\n\nOnly sensors of a specific therm sensor type:\n\n```python\nfrom w1thermsensor import W1ThermSensor\n\nfor sensor in W1ThermSensor.get_available_sensors([W1ThermSensor.THERM_SENSOR_DS18B20]):\n print(\"Sensor %s has temperature %.2f\" % (sensor.id, sensor.get_temperature()))\n```\n\n### Set sensor precision\n\nSome w1 therm sensors support changing the precision for the temperature reads.\n`w1thermsensor` enables to do so with the `W1ThermSensor.set_precision()` method:\n\n```python\nsensor = W1ThermSensor(W1ThermSensor.THERM_SENSOR_DS18B20, \"00000588806a\")\nsensor.set_precision(5)\n```\n\nIf the ``persist`` argument is set to ``False`` this value\nis \"only\" stored in the volatile SRAM, so it is reset when\nthe sensor gets power-cycled.\n\nIf the ``persist`` argument is set to ``True`` the current set\nprecision is stored into the EEPROM. Since the EEPROM has a limited\namount of writes (>50k), this command should be used wisely.\n\n```python\nsensor = W1ThermSensor(W1ThermSensor.THERM_SENSOR_DS18B20, \"00000588806a\")\nsensor.set_precision(5, persist=True)\n```\n\n**Note**: this is supported since Linux Kernel 4.7\n\n### Disable kernel module auto loading\n\nUpon import of the `w1thermsensor` package the `w1-therm` and `w1-gpio` kernel modules get loaded automatically.\nThis requires the python process to run as root. Sometimes that's not what you want, thus you can disable the auto loading\nand load the kernel module yourself prior to talk to your sensors with `w1thermsensor`.\n\nYou can disable the auto loading feature by setting the `W1THERMSENSOR_NO_KERNEL_MODULE` environment variable to `1`:\n\n```bash\n# set it globally for your shell so that sub-processes will inherit it.\nexport W1THERMSENSOR_NO_KERNEL_MODULE=1\n\n# set it just for your Python process\nW1THERMSENSOR_NO_KERNEL_MODULE=1 python my_awesome_thermsensor_script.py\n```\n\nEvery other values assigned to `W1THERMSENSOR_NO_KERNEL_MODULE` will case `w1thermsensor` to load the kernel modules.\n\n*Note: the examples above also apply for the CLI tool usage. See below.*\n\n## Usage as CLI tool\n\nThe w1thermsensor module can be used as CLI tool since version `0.3.0`.
\n*Please note that the CLI tool will only get installed with the Raspbian Python 3 package* (`sudo apt-get install python3-w1thermsensor`)\n\n### List sensors\n\nList all available sensors:\n\n```\n$ w1thermsensor ls\n$ w1thermsensor ls --json # show results in JSON format\n```\n\nList only sensors of a specific type:\n\n```\n$ w1thermsensor ls --type DS1822\n$ w1thermsensor ls --type DS1822 --type MAX31850K # specify multiple sensor types\n$ w1thermsensor ls --type DS1822 --json # show results in JSON format\n```\n\n### Show temperatures\n\nShow temperature of all available sensors: (Same synopsis as `ls`)\n\n```\n$ w1thermsensor all --type DS1822\n$ w1thermsensor all --type DS1822 --type MAX31850K # specify multiple sensor types\n$ w1thermsensor all --type DS1822 --json # show results in JSON format\n```\n\nShow temperature of a single sensor:\n\n```\n$ w1thermsensor get 1 # 1 is the id obtained by the ls command\n$ w1thermsensor get --hwid 00000588806a --type DS18B20\n$ w1thermsensor get 1 # show results in JSON format\n```\n\nShow temperature of a single sensor in the given precision\n\n```\n$ w1thermsensor get 1 --precision 10\n$ w1thermsensor get --hwid 00000588806a --type DS18B20 --precision 11\n```\n\n### Change temperature read precision and write to EEPROM\n\n```\n$ w1thermsensor precision 10 1\n$ w1thermsensor precision --hwid 00000588806a --type DS18B20 11\n```\n\n## Contribution\n\nI'm happy about all types of contributions to this project! :beers:\n\n***\n\n*
This project is published under [MIT](LICENSE).
A [Timo Furrer](https://tuxtimo.me) project.
- :tada: -