Skip to main content

A simple class to represent items from openHAB. There is a separate object for each item type. The class can be used in conjunction with the REST API of openHAB.

Project description

Python openHAB Item

A simple module to represent Items from openHAB. There is a separate object for each Item Type. The module can be used in conjunction with the REST API of openHAB.

Installation

You can install it by using pip:

python3 -m pip install python-openhab-item

Usage

You have to import either Item or one of the Item objects:

from openhab import Item, ColorItem, ContactItem, DateTimeItem, DimmerItem, GroupItem, ImageItem, LocationItem, NumberItem, PlayerItem, RollershutterItem, StringItem, SwitchItem

Basic Item Creation

You can create an Item by using an Item object like this:

item = Item("Switch", "my_switch")

So you need at least the Item Type and the name of your Item. You can choose between following Item Types:

  • Color
  • Contact
  • DateTime
  • Dimmer
  • Group
  • Image
  • Location
  • Number
  • Player
  • Rollershutter
  • String
  • Switch

The constructor will automatically check if you choosed a correct Item Type. The type and name attribute are checked if a str is passed. Both are required. Alternatively you can run:

item = Item(type="Switch", name="my_switch")

Instead of creating an Item object you can create an object for each Item Type. You do not need to pass a parameter for the type attribute, so only the name is required:

color = ColorItem("my_color")
contact = ContactItem("my_contact")
datetime = DateTimeItem("my_datetime")
dimmer = DimmerItem("my_dimmer")
group = GroupItem("my_group")
image = ImageItem("my_image")
location = LocationItem("my_location")
number = NumberItem("my_number")
player = PlayerItem("my_player")
rollershutter = RollershutterItem("my_rollershutter")
string = StringItem("my_string")
switch = SwitchItem("my_switch")

Optional attributes are state, tags or groups.

Set State

If you will set a state it will automatically validate if the state is valid:

switch = SwitchItem("my_switch", "ON")
switch2 = Item("Switch", "my_switch2", "ON")

or

switch = SwitchItem(name="my_switch", state="ON")
switch2 = Item(type="Switch", name="my_switch2", state="ON")

or

switch = SwitchItem("my_switch")
switch.setState("ON")
switch2 = Item("Switch", "my_switch2")
switch2.setState("ON")

You can validate if a state is correct before you set it, so your program doesn't abort because of an error message:

switch = SwitchItem("my_switch")

if switch.validate("ON"):
    switch.setState("ON")

And of course the state does not have to be a str if the Item Type allows other values:

number = NumberItem("my_number", 3.14)
number2 = NumberItem("my_number2", 21)

Get State

From an Item object you can logically also query what the state is:

switch = SwitchItem("my_switch", "ON")
switch_state = switch.getState()
print(switch_state)

number = NumberItem("my_number", 3.14)
number_state = number.getState()
print(number_state)

Set Tag(s)

To each Item you can set a tag or multiple tags. Therefore you need a list object. As example the tag Switchable:

switch = SwitchItem("my_switch", "ON", ["Switchable"])
switch2 = SwitchItem(name="my_switch2", state="ON", tags=["Switchable"])
switch3 = SwitchItem(name="my_switch3")

Set Group(s)

An Item can be subordinated to one or more Group's. Therefore you will also need a list object:

switch = SwitchItem("my_switch", "ON", ["Switchable"], ["group1", "group2"])
switch2 = SwitchItem(name="my_switch2", state="ON", tags=["Switchable"], groups=["group1", "group2"])

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

If you're not sure about the file name format, learn more about wheel file names.

python_openhab_item-1.0.0-py3-none-any.whl (12.4 kB view details)

Uploaded Python 3

File details

Details for the file python_openhab_item-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for python_openhab_item-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 054d9155f18673e9874836c7dd3792c7bd511c76cfebbd240dd9982ca452e8ee
MD5 7615c9d0ff184930fcf3feb1d89ac69f
BLAKE2b-256 10c4c1dc8924693e6b86b589f2a3305f4c8ab9522f049dd8e8fd222b8023ac66

See more details on using hashes here.

Supported by

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