Simple question: create a static string item


I feel like I am missing a very basic piece of information, but is it possible to create a String item that is simply a static value, initialized in the .items file?

Something like this:

String BLE_mac_address (Bedroom) {"EF:0D:55:64:66:4F"}

I want to do it in the .items file so that I can define the devices in one place. Is there a good way to do this?

Then, when I write a rule, I can reference the mac address like so:
var mac = BLE_mac_address.state

In a similar vein, can I have a string item which gets its value from a mySQL datebase? This would similarly solve my problem.

You can create a static variable in your rules-file:
val mac = "EF:0D:55:64:66:4F"
and access it later directly.
Just declare it on the very top directly after your imports and before the first rule.

No, you will have to initialize it from a rule.

For example:

rule "Started"
    System started

If you have persistence setup with restoreOnStartup, you only need this rule the first time the Item gets set.

I strongly believe it is better to put even static values like this in Items rather than as vals in the Rules, though @Spaceman_Spiff’s approach is equally as valid. I just like the idea that these states get saved to Persistence, are available across my rules files, it standardizes how values are accessed, and if you name them right and put them in groups you can look them up by name (for example, construct the name of a parameter based on the name of another Item that triggered a rule) which allows for consolidation of rules.