Skip to main content

python library for accessing the openHAB REST API

Project description

Codacy badge Documentation Status pypi version

python library for accessing the openHAB REST API

This library allows for easily accessing the OpenHAB REST API. A number of features are implemented but not all, this is work in progress.

Requirements

  • python >= 3.5

  • python :: dateutil

  • python :: requests

  • python :: typing

Note on openHAB1:

The current version is focused on OpenHAB 2.x; OpenHAB 1.x might still work, though this is not tested. If you require older OpenHAB support, please use an older version of this library.

Installation

Install the latest version using pip:

pip install python-openhab

Example

Example usage of the library:

from openhab import openHAB

base_url = 'http://localhost:8080/rest'
openhab = OpenHAB(base_url)

# fetch all items
items = openhab.fetch_all_items()

sunset = items.get('Sunset')
print(sunset.state)

# fetch a single item
item = openhab.get_item('light_switch')

# turn a switch on
item.on()

# send a state update (this only update the state)
item.state = 'OFF'

# send a command
item.command('ON')

# check if item state is NULL
if item.state is None and item.is_state_null():
  pass

# check if item state is UNDEF
if item.state is None and item.is_state_undef():
  pass

Note on NULL and UNDEF

In OpenHAB items may have two states named NULL and UNDEF, which have distinct meanings but basically indicate that an item has no usable value. This library sets the state of an item, regardless of their OpenHAB value being NULL or UNDEF, to None. This in order to ease working with the library as we do cast certain types to native types.

In order to check if an item’s state is either NULL or UNDEF, you can use the helper functions:

item.is_state_null()
item.is_state_undef()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python-openhab-2.12.0.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

python_openhab-2.12.0-py3-none-any.whl (21.9 kB view details)

Uploaded Python 3

File details

Details for the file python-openhab-2.12.0.tar.gz.

File metadata

  • Download URL: python-openhab-2.12.0.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.41.0 CPython/3.8.0

File hashes

Hashes for python-openhab-2.12.0.tar.gz
Algorithm Hash digest
SHA256 dfd6409991b80399d26528034174a8eee684fe893f302df377e961d061daea5e
MD5 b7efab29bcdce11f32e8f4759738f145
BLAKE2b-256 f829444eb122f3c71ec55c2117e5ef0e221bc319ff631e5602e562b2e823540f

See more details on using hashes here.

File details

Details for the file python_openhab-2.12.0-py3-none-any.whl.

File metadata

  • Download URL: python_openhab-2.12.0-py3-none-any.whl
  • Upload date:
  • Size: 21.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.41.0 CPython/3.8.0

File hashes

Hashes for python_openhab-2.12.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7bb032d528811ad532d9d3f8264b6bc9200055e4e950fb59c176d47846fef231
MD5 a79b797fb97fa2e19e59634ed69ba247
BLAKE2b-256 6e0079bd4d02c2ea8efcce20de239186f5b8f036edb86d6feafe492054889b0e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page