Is it possible to create a custom Item and link it to a Thing to provide custom functionality?

I have a z-wave dimmer that I’m using on my daughter’s reading lamp. It has a single item linked to it, which is the dimmer control.

I’d like to be able to add an additional on/off channel to it so I can add a timer rule to turn it off after a set number of minutes. Ideally, it would just appear as another on/off toggle on the Thing’s card in PaperUI.

Alternatively, is there a way to make a generic Thing as a button that could trigger the timer rule?

As a side note, I’m utilizing the Location value in my Things for grouping, and I’m not using a sitemap. I’m using the REST API to build a dashboard app that combines OpenHab and a few other home-related odds and ends, and the Location is all the granularity I need. If I can avoid having to generate and parse a sitemap, I’d love it :smiley:

Thanks in advance,
Nate

Some of this is OH2 specific and I’ve not yet transferred over. Soon…

But I think I can help.

First of all, as I understand it, within OH2, the Things represent the devices in the “real world”. But internally OH operates using Items which tells OH how to interact with the Things. Within PaperUI one provides a mapping between a Thing and an Item. But not all Things require Items and not all Items require a Thing. I also believe that one can define multiple Items for a single Thing (not positive on that though).

A Dimmer Item can receive ON/OFF commands in addition to PercentValues. In other words you can sendCommand(ON) and sendCommand(OFF) to a Dimmer Item. No need for a separate channel or a separate Item. Just send ON or OFF through the REST API and it should work.

Not a Thing but a Proxy Item. This is just an Item that doesn’t have a binding config and/or isn’t bound to a Thing. In this case you would just create a Switch Item unbound to anything and set up the rule to trigger on that “Proxy Item” receiving a command.

If you find that the Location value doesn’t provide enough granularity, you should look into using Groups. This is a more standard way to organize Items and an Item can be a member of more than one Group. While Groups can be used for sitemaps, they are most useful for organizing your Items and use within Rules.

And remember, Rules within OH2 primarily operate on Items, not Things. So your focus should be on creating Items, mapping them to Things, and defining the behaviors of Items.

If I’m wrong hopefully someone will step up and correct me.

Thanks for the reply, Rich! (Ironically, I’ve been reading through your Dash Button scripts…)

I think this is getting me in the right direction, especially with your explanation of Things vs Items. I need to focus more on the Items. If this is the case, the OH2 interfaces (PaperUI and Habmin2 especially) need to put more attention on the items than the Things. I’m unable to properly edit Items in Habmin, and can’t get to them at all in Paper – I think this is where my confusion comes from.

I’m looking for a switch that controls my timer function that’s attached to the Lamp Thing - I already do ON/OFF or percentages via REST API.

As for the Proxy Item, that’s exactly what I’m doing w/ my Dash Button, and it works perfectly. In this particular instance, though, I want it to appear with the Thing – but OH2’s Things and Items seem to be inaccessible for this sort of editing.

Unfortunately, this is the exact opposite of how OH2/PaperUI and Habmin address adding objects. :frowning:
It also doesn’t help that the REST API tells me that my items can’t be edited (unable to set groups or tags).

I’d like to avoid having to create all of my Items in the .items file, since OH2 does a good job of creating them to begin with.

I’m going to play with it some more tonight and see what I can find.

See this documentation if you haven’t already. It is a work in progress but being enhanced and added to every day.

http://docs.openhab.org/tutorials/

The Beginners section talks a lot about linking Things and Items in PaperUI. I think the key part is:

Note that you still need to define your items, sitemaps, persistence configurations and rules in the according configuration files (as done in openHAB 1). Such functionality will be added bit by bit to the Paper UI only.

So you will need to write your Items files by hand (preferably using Designer).

So this is where I start to get a little confused about what you are trying to do. First, realize that PaperUI is strictly intended as an administration UI, not the main user interface to your home automation. You have already said you want to write your own instead of using sitemaps, which is fine.

That being said, what more do you want in a switch than the ability to send ON and OFF? If you can send ON and OFF to a Dimmer, then a Dimmer is a switch. So I don’t understand what you mean by “switch that controls my timer function attached to the Lamp Thing”. A Timer is something that lives in rules. Timers are not associated with Things. Any “attachment” occurs by having the body of the Timer “sendCommand” or “postUpdate” to the Item linked to that Thing. So, in short:

  • You have a Dimmer Item linked to a Dimmer Thing
  • You have a Switch Item linked to nothing (proxy Item)
  • You have a Rule that triggers when the Switch Item receives a command which creates the Timer.

See my quote above. I’m afraid you will either have to create files or wait until PaperUI and/or Habmin2 catches up.