Package: python-openhab-item
Python openHAB ItemA simple module to representItemsfromopenHAB. There is a separate object for eachItem Type. The module can be used in conjunction with theREST APIofopenHAB.InstallationYou can install it by usingpip:python3 -m pip install python-openhab-itemUsageYou have to import eitherItemor one of theItemobjects:from openhab import Item, ColorItem, ContactItem, DateTimeItem, DimmerItem, GroupItem, ImageItem, LocationItem, NumberItem, PlayerItem, RollershutterItem, StringItem, SwitchItemBasic Item CreationYou can create anItemby using anItemobject like this:item = Item("Switch", "my_switch")So you need at least theItem Typeand thenameof yourItem. You can choose between followingItem Types:ColorContactDateTimeDimmerGroupImageLocationNumberPlayerRollershutterStringSwitchThe constructor will automatically check if you choosed a correctItem Type. Thetypeandnameattribute are checked if astris passed. Both are required. Alternatively you can run:item = Item(type="Switch", name="my_switch")Instead of creating anItemobject you can create an object for eachItem Type. You do not need to pass aparameterfor thetypeattribute, so only thenameis 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 arestate,tagsorgroups.Set StateIf you will set astateit will automatically validate if thestateis valid:switch = SwitchItem("my_switch", "ON")
switch2 = Item("Switch", "my_switch2", "ON")orswitch = SwitchItem(name="my_switch", state="ON")
switch2 = Item(type="Switch", name="my_switch2", state="ON")orswitch = SwitchItem("my_switch")
switch.setState("ON")
switch2 = Item("Switch", "my_switch2")
switch2.setState("ON")You can validate if astateis 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 thestatedoes not have to be astrif theItem Typeallows other values:number = NumberItem("my_number", 3.14)
number2 = NumberItem("my_number2", 21)Get StateFrom anItemobject you can logically also query what thestateis: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 eachItemyou can set atagor multiple tags. Therefore you need alistobject. As example thetagSwitchable:switch = SwitchItem("my_switch", "ON", ["Switchable"])
switch2 = SwitchItem(name="my_switch2", state="ON", tags=["Switchable"])
switch3 = SwitchItem(name="my_switch3")Set Group(s)AnItemcan be subordinated to one or moreGroup's. Therefore you will also need alistobject:switch = SwitchItem("my_switch", "ON", ["Switchable"], ["group1", "group2"])
switch2 = SwitchItem(name="my_switch2", state="ON", tags=["Switchable"], groups=["group1", "group2"])