Skip to main content

python library for accessing the openHAB REST API

Project description

Codacy badge Documentation Status pypi version travis-ci status

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

  • openHAB version 2

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

# fetch some group
lights_group = openhab.get_item('lights_group')

# send command to group
lights_group.on()

# send update to each member
for v in lights_group.members.values():
  v.update('OFF')

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 Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

python_openhab-2.14.0-py3-none-any.whl (23.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: python_openhab-2.14.0-py3-none-any.whl
  • Upload date:
  • Size: 23.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3

File hashes

Hashes for python_openhab-2.14.0-py3-none-any.whl
Algorithm Hash digest
SHA256 700b7067d2cfa9a633abfbf68af9fe07aac025d866e7d4258ca04578445dc7e6
MD5 a7e46eae182e00869db182b8c448418f
BLAKE2b-256 8f8751d54f15bf656499be9f02eb859861ec28390e0f24c0fda0067e402788cd

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