Creating a User-Editable Value in openHAB

Hey everyone, I wanted to share my experience with creating a user-editable value in openHAB. I’ve been working on a project where I need to monitor the temperature from a sensor and set a custom threshold that users can adjust. Here’s how I tackled it!

The Goal:
I wanted a persistent number called TempLimit that users could edit via the Basic UI. This value would be used in rules to trigger actions when the temperature exceeds it. The challenge was ensuring the value was both editable and persistent across restarts.

The Solution:
After some research, I discovered that using a Number item along with the Map persistence service was the way to go. Here’s how I set it up:

  1. Item Configuration:
    I created a Number item in my items file:
    plaintext
    Number TempLimit “Temperature Limit [%.1f °C]” (gTemp)

This makes the item visible and editable in the Basic UI.

  1. Persistence:
    To ensure the value persists, I added the following to my persistence.xml:
    xml


    /etc/openhab/persistence/map.db

And linked the item in my persistence.cfg:
plaintext
TempLimit : strategy = everyChange, file = map

  1. User Interface:
    I added the TempLimit item to my Basic UI page. Now, users can easily adjust the value without needing admin access!

  2. Rule Integration:
    I used the TempLimit value in my rules to trigger actions when the temperature exceeds it:
    plaintext
    if (TemperatureSensor.state > TempLimit.state) {
    // Trigger action here
    }

Outcome:
This setup works perfectly! The TempLimit value is now user-editable, persistent, and integrates seamlessly with my rules. It’s been a great way to make my system more adaptable to different user needs.

Tips for Others:

  • If you’re unsure about persistence, start with Map as it’s simple and effective.
  • Always test your setup by restarting openHAB to ensure values persist.
  • Consider adding validation to prevent users from setting unrealistic values.

I hope this helps someone looking to add more interactivity to their openHAB setup! Let me know if you have questions or other creative uses for user-editable values. :blush: