Design Pattern: Unbound Item (aka Virtual Item)

Tags: #<Tag:0x00007f0146be4e68> #<Tag:0x00007f0146be4b98>

(Rich Koshak) #1

Problem Statement

Sometimes one needs to create a flag, control, switch, or some other control that is not bound to a device or channel. For example, a Switch to override presence detection.


Create an Item that does not have a binding configuration.

Simple Example

Switch VirtualItem "label" <icon> (groups) // No binding config

See the Sensor Aggregation Design Pattern for a more complicated example. The Virtual Item is Override_Presence in that example.

Advantages and Limitations

Virtual Items are a good way to store state needed by rules and to provide a way to allow the user to modify the behavior of their rules by adjusting parameters stored in Virtual Items. Data stored in Virtual Items can also be persisted and restored on startup unlike global vars and vals.

Related Design Patterns

Help, I'm ready to give up
Hints to solve some scenarios in openHab (coming from homee)
HUE + HM-PB-2-FM + WebSwitch
Config & documentation
Comprehensive Wunderground using HTTP Binding Example
Energy harvesting
"disable" switch item
Design Pattern: Human Readable Names in Messages
Suggestion for controlling my underfloor heating, Roth Touchline
How to store additional info in ITEM?
Design Pattern: Associated Items
Sonos NotificationVolume no longer adjustable
Is it possible to enable/disable rules created textually via Paper UI?
Using HABMin rules in HABPanel
Absolute value of a decimal
Can't get rid of duplicate item
How to create a macro with OpenHab?
Design Pattern: Encoding and Accessing Values in Rules
How do I create groups and items in runtime mode, display them in the user´s interface (basic UI perhaps), and control their events (also in runtime)? Is it possible?
[SOLVED] Persistence query in habpanel
Best way to make long time macro
Design Pattern: Cascading Timers
(YvesHanoulle) #2

Data stored in Virtual Items can also be persisted and restored on startup unlike global vars and vals.

You might want to add how to do that.

I have figured out, by adding it to a group that was persisted and that group had restoreOnStartup in the .persiste file.

Yet it took me a long time to find that.