Definition of Items and rules after auto recognition

Hello everybody,
i am getting increasingly frustrated with the steep learning curve that I experience with OH2.
unfortunately I am yet to find a good tutorial that shows the first steps of programming or how to proceed once all things and items are recognized. the OH2-manual isn’t a good ressource for me, since most articles seem to imply or presuppose too much…

My goal - as stated in another post - would be to automatically lower my rollershutters after sunset and pull them up after sunrise. the rollershutter “Things” are online and can be operated via web ui.
What next?
Do I have to manually add a statement in the .items file? … how can I address the rollershutters in a rule similar like this:

rule "sunrise"
when
sun is up
then
rollershutter.sendcommand(up)
end

are there any rules templates or scripts that I can tinker with?

This can be done via astro binding:

http://docs.openhab.org/addons/bindings/astro/readme.html

rule "example trigger rule"
when
    Channel 'astro:sun:home:rise#event' triggered START 
then
    ...
end

This part depends on your hardware (which you did not mention). For example for the widely used Fibaro rollershutter switch it is possible to do it like

YourItemName.sendCommand(100) or
YourItemName.sendCommand(0) or
YourItemName.sendCommand(50) or
YourItemName.sendCommand(UP) or
YourItemName.sendCommand(DOWN)

Also take a look at

http://docs.openhab.org/configuration/rules-dsl.html

http://docs.openhab.org/configuration/rules-ng.html

1 Like

Thank you. I understood the “when” part.
I use EnOcean rollershutter switches that are bound to my Homematic CCU2.

I have read the documentation on rules over and over, however I don’t seem to grasp how a specific item can be addressed. The given examples are not helping.

So, can you please give me a hint, how to address my items (“YourItemName”).
Do I have to restart Openhab each time that I edit a rule?
Do I have to manually define the items or can I use the item name that was given via web interface?
I tried the latter to no avail:

file “rollershutter.rules”

rule "time test"
when
time cron "0 0 10 * * ?"
then
rollershutter1_li.sendcommand(UP)
end

Note that it should be sendCommand(UP) with a capital C.

Also, if you don’t know how to address your items, could you post a screenshot of your items list in paperui? (I guess that’s where you configured them?) And we can point in the right direction.

1 Like

You can find examples how to set up a rollershutter item via homematic binding here:


So it should look like

Rollershutter rollershutter1_li "rollershutter1_li [%d%%]" { channel="homematic:HM-LC-Bl1-FM:704745df:NEQ1688388:1#LEVEL" }

Of course you need to find the correct bridge, serial and channel number for your own rollershutter device …

No.

You can do both, whatever you prefer.

As a last step you need two rules, one for sunrise, one for sunset:

rule "rollershutter1_li open"
when
    Channel 'astro:sun:home:rise#event' triggered START 
then
    rollershutter1_li.sendCommand(0)
    logInfo("shuttertest","rollershutter1_li opened")
end

rule "rollershutter1_li close"
when
    Channel 'astro:sun:home:set#event' triggered START 
then
    rollershutter1_li.sendCommand(100)
    logInfo("shuttertest","rollershutter1_li closed")
end
2 Likes

Hi Mario,

You can create Items using PaperUI as well as define them in an .items file. For me only items defined in an .items-file were found from Eclipse SmartHome Designer. So I prefer defining the items there. But be aware that define the items manually in a file is more error-prone.

@sihui already showed how to define an Homematic Rollershutter-Item. Even if you define the item in a file, you can/should copy the connection-string from PaperUI. The following screenshot shows the channel of the Rollershutter-thing to control the Level.


Copy it using the red marked icon here or link it directly with PaperUI.

You address each item by its itemname. You can find it in PaperUI or as the 2nd entry of an item-definition in an items-file.

type itemname itemlabel <icon> (groups) { channel="..." }
Rollershutter AZRollo "Rollo [%s %%]" <blinds> { channel="homematic:HM-LC-Bl1PBU-FM:ccu:XXX1232112:1#LEVEL" }

So my name is AZRollo here.

In a rule you can listen to item-events in the when condition using:

  • Item itemname changed or
  • Item itemname received update or
  • Item itemname received update to ON or
  • Item itemname received command or
  • Item itemname received command ON

In the then part of the rule you use the itemname followed by a dot and a function, e.g.:

  • itemname.sendCommand(ON)
  • itemname.postUpdate(OFF)

No, you don’t. Each time an items-, rule-, sitemaps-, persistens-file gets a new timestamp, openHAB updates/reloads its loaded configuration. The items and rules and so on will be reinitialized and validated.

As i mentioned before, you can use the itemname from the web-UI, but the SmartHome-Designer I have did not know it. But openHAB knows it, when the rule is activated.

You always should have a look to the logtail (using port 9001). This will give you a good feedback if rules or item-definitions are correct.

Hope that general information helps. @sihui already gave a good answer for your special case, but your questions seamed to be more general, too.

Regards

Malte

2 Likes

When you define an Item you give it a Name.

Assuming you create an Item in a .items file, the name of the Item is the second word in the definition.

For example:

Contact vGarageOpener1 "Garage Door Opener 1 is [MAP(en.map):%s]"
  <garagedoor> (gDoorSensors,gDoorCounts)
  { mqtt="<[mosquitto:entry_sensors/main/garage/door1:state:default]" }

So, based on the Items Docuementaiton

itemtype itemname "labeltext [stateformat]" <iconname> (group1, group2, ...) ["tag1", "tag2", ...] {bindingconfig}

  • itemtype = Contact
  • itemname = vGargeOpener1
  • “labeltext [stateformat]” = “Garage Door Opener 1 is [MAP(en.map):%s]”
  • <icon> = <garagedoor>
  • groups = (gDoorSensors, gDoorCounts)
  • there are no tags
  • {bindingconfig} = { mqtt="<[mosquitto:entry_sensors/main/garage/door1:state:default]" }

To refer to an Item from anywhere within OH you use its itemname. So if I want to see if that garage door opener is open in a Rule I would:

if(vGarageOpener1.state == OPEN)

If you create your Items inside PaperUI, most of those fields are available in the Item creation page with the following differences:

  • you can only link PaperUI created Items to a Thing’s Channel
  • icon is “Category”
  • you cannot define tags

If you are using Simple mode, then the Items are created for you. The Item name will match the Thing ID.

So, if you have an Item named “MyRollershutter” you would

MyRollershutter.sendCommand(UP)

Note the case, case matters.

2 Likes

A big, big thank you for everyone. I think I slowly get a grasp of openhab’s internal workings… unfortunately, I am not at home currently. I will try out everything as soon as possible. thanks again.