OH 3 Tips and Tricks

Im also doing the same as you, where you add the thing, then add the eqipment/point to the model.
This creates items, even if you have already linked another item to the thing.

Therefore you will double up on items.

One thing im struggling with.
I have hundreds of rules. that work off fake items, such as a keypad item. then on my sitemap i have mappings 0-9 to make it look like a keypad. Then a rule that when buttons are pressed, adds the number to a string to get a passcode.
If this passcode is correct, then when i press ARM or DISARM it will change the status of my alarm.
How can i do the same thing in the new setup?

rule "keypad"
when
	Item AlarmKeypad received command
then


if (alarmTimer.state = ON)
	{
	alarmTimer.sendCommand(OFF)
	Unlocked.postUpdate(OFF)
	}
	
if (receivedCommand == "11")
	{
	code.postUpdate("")
	keypadTimer.sendCommand(OFF)
	AlarmKeypad.postUpdate("")
	KeypadString.postUpdate("")
	}



	




	
if (receivedCommand != "" || receivedCommand != "11")
{	
		code.postUpdate(code.state.toString + AlarmKeypad.state.toString)
		KeypadString.postUpdate(code.state)	
		keypadTimer.sendCommand(ON)
		
		if (code.state == "XXXX")
			{
			Unlocked.postUpdate(ON)
			alarmTimer.sendCommand(ON)	
			}
}





end

You can pick and choose which Channels get linked. It should be rare that you have the same Channel linked to more than one Item. So why add the equipment from Thing if the Items already exist and are linked?

because lets say i do it in this order

  1. create item from old 2.5 version using text files

  2. install yamaha binding

  3. link yamaha_volume item to yamaha binding volume channel.

  4. add the yamaha volume channel to model.

This then creates another item.

Ah, another “let’s run a tight ship here” thread. We both know they don’t work :wink:
Sacrasm aside, good initiative!

3 Likes

Well yes, it is called “Create Equipment from Thing”. That’s why I wrote that whole "Buying in Bulk (Items Part 2). You would never want to do it the way you describe.

If you imported them from your old .items files or some other text file, it is your responsibility to set the tags and Group membership on those Items so they fit into the model. That’s acutally a quite tedious job which is why I don’t do that any more. I only ever create the Items using “Create Equipment from Thing”. I never import from my old .items files any more.

So the steps are either:

  1. create item from old 2.5 version using text files
  2. install yamaha binding
  3. link yahama_volume item to yahama binding volume channel
  4. Create a Group Item called Yahama with the proper Equipment Tag.
  5. Add the Yahama Group to the proper Location Group
  6. Add the yahama_volume Item to the Yahama Group
  7. Set the Point and Property tags on the yahama_volume Item
  8. repeat 6-7 for all the remaining yahama Items.

Or the steps are:

  1. Install the Yahama Item
  2. click on the location in the Model where the Yahama equipment belongs
  3. click on “Create Equipment from Thing”
  4. Set the Equipment name and category and semsantic tag
  5. Select the Channels to create Items for and set the Item names, categories, and Point tags and Properties

You would never do both.

Yep, but at least I have an excuse to say “sorry, please post another thread.” :smiley: But I’ve no expectation it’ll work either.

1 Like

Yep, thats what i was getting at.
ive since learnt the same. best to create items when adding them to the model. Instead of before hand. As you have mentioned already.

Ive since gone through and removed about 370 items and am starting again.

Thanks for the tips in this thread. Surely they will come in handy

If the item is able to report its state (e.g. a zwave device) always use autoupdate=off.
It makes the rules work much more consistently and leads to way less errors.

1 Like

I am trying to update properties of existing items using JSON, like you suggest:

This working great with one item, but when I try update many items at once using “PUT /items” from API I am getting error:

`Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2

Can some one provide an example of correct JSON formatted text for 2 items?
Thanks!

Unfortunately it’s not always obvious which bindings and devices support that. I’ll want to add some advice on how to tell. But that’s a good one.

It also also reminds me of some tips about persistence I should include.

Thanks!

The internet was to do it one Item at a time. So paste the one example, edit it, submit it, edit for the next one, submit, and repeat.

That’s more straight forward and less pronevtob error.

You can submit more than one at a time, but you’ll need to format the entries as a JSON array, as the error indicates. I think an array starts with [ and each entry is separated by a comma, ending with ].

Pay attention to the schema down in the docs. it tells you what the JSON needs to be format wise.

1 Like

Isn’t that the default? I haven’t set autoupdate at all on any of my Items, I thought that was the same thing as manually setting it to off?

Not quite

I would advise understanding what autoupdate is for before blanket disabling it. It’s default enabled for a reason.
The explanation in Rich’s original post is a good starting point.

1 Like

When working with a few items from the semantic model, use the Pinned Objects in the developer sidebar so it is easy to access them without navigating the tree.

1 Like

Thanks to Rich for these tips and JustinG for this post Solved: Mass change for multiple items possible?

Here’s how I copy things (including channels) and copy items (including metadata) via OH3 UI. This works well for e.g. the KNX binding, which does not support discovery, yet. It is not as fast as copying and modifying text files, but works well for me.

Copy things

  • Create all things via UI (only basic settings, no channels)
  • Create all channels for one specific type (e.g. HVAC, lighting, blinds) of thing
  • Go to Code of thing
  • Copy channel configuration to editor of your choice
  • Do a search and replace in the channel configuration
  • Paste channel configuration to the other things

Copy items (including metadata)

Copy items

  • Go to API Explorer Administration → Developer Tools
  • Do a GET items with itemname
  • If you want to copy multiple items, it is easier to create a group (item) first. Then enter group name as itemname
  • Supply the relevant metadata when GETTING, if you want to copy it. (e.g. stateDescripton, widget, listWidget, widgetOrder, …)
  • Copy JSON response to editor of your choice
  • Do a search and replace in the editor (keep editor open for copying metadata)
  • Do a PUT items with the JSON (metadata will not be copied in this step)
  • Check the response, if all items have been created successfully

Copy metadata of items

Link channels

Best regards
Fritz

Can you provide an example of how you add the autoupdate=off to a item?
I know how it’s done using the UI but the items in the UI won’t allow you to view the code.

It’s Item Metadata.

Navigate to the Item. Click on “ADD METADATA” and choose “Auto-update” from the list of well-known namespaces.

Example:

Switch Garage_Gate {channel="xxx", autoupdate="false"}

See here:

1 Like

Is there an option to perform live update for a chart by setting “refresh” as in OH3. So far I could not figure out a way to get a chart to display in real time (automatic refresh) in OH3. I’ve tried to enter refresh manually in the chart code but I could not see any effect. Is it supported in OH3?

Thanks @Fritz for your great copy solution. Through this I don’t have to click 4 identical shellies, connected via mqtt, with 12 channels for each.

Only one hint for the put action, if you use a group-item.

You get all linked members in the output and can search/replace. But the PUT items action will only create the one outer item from the pasted json, not the members :frowning:

For this my workaround was:

  • copy all member objects from replaced json
  • paste it (with last comma) above of the line “members”: [
  • paste the whole json between the square brackets of the PUT items json

So you can create all items of this group with one json.