Simple Form to Update Item State through Sitemap (needs Webserver with php)

Hi all,

maybe there is already a solution in place but I did not find it through googling or in the forum.
And maybe someone is looking for a quite similar solution to be able to update the state of items manually, why I want to share the below. I’m happy for any comments or further ideas/ thoughts to improve.

Reason behind I did this: I use Items for monitoring purposes (like my Gas or Electricity Meters) and afterwards to visualize in Grafana. Sometimes I need to adjust the value manually due to several reasons (ESP or OpenHAB offline (during updates/ configuration puporses etc.).

What I did to reach my goal:

  1. set up a WebServer like Apache including php (e.g. on a different machine or if you’re experienced to install on your OpenHAB-machine and use a different port). Maybe the php support for CometVisu is doing the trick as well? I did not test because I’m already running Apache with php on a different machine.

  2. amend the attached php-file to your installation and upload to your webserver:
    adjustitem.php.txt (4.0 KB) (remove the “.txt”-Extension before uploading on your webserver).

a) change the Openhab-URL ($ohurl) to your installation
b) change “ITEM1” to the Item-Name respective -Label (in ITEM1-Label). You can reduce or extent as you wish as shown below.

$ohurl = "http://<OPENHAB-IP:PORT>/rest/items/";

function ItemList()
{
?>
<select name="item" id="item">
        <option class="text" value="">---</option>
        <option class="text" value="<ITEM1>"><ITEM1-Label></option>
        <option class="text" value="<ITEM2>"><ITEM2-Label></option>
        <option class="text" value="<ITEM3>"><ITEM3-Label></option>
        <option class="text" value="<ITEM4>"><ITEM4-Label></option>
        <option class="text" value="<ITEM5>"><ITEM5-Label></option>
</select>
  1. Create/ amend your Sitemap to include the webview as shown below; change IP and Path to meet your configuration.

Webview icon=none url="http://<WEBSERVER-IP>/<PATH>/adjustitem.php" height=3

I created the php-page very minimalistic in purpose not to need too much space.
I know this is only a small one and maybe there are better aproaches (and definitely this one can be extended massively if needed), but I always tried to find a small and easy solution for this need. Now as I took the time (and not being much experienced neither in php or curl), I’m quite happy with the result.

Maybe it’ll help someone of you guys.

Cheers,
Matze.

This is possible out of the box in OH 3 by setting the default card widget. See OH 3 Examples: How to boot strap the state of an Item

I don’t think this is necessary. I think you can use a plain old html file with some simple JavaScript and a form to achieve the same result and then eliminate the dependency on an external server. See OAuth2 using just OH Rules and myopenhab.org for a partial example.

1 Like

Hi Rich,

cool, good to know as I’m starting migrating my stuff to OH3 soon.

JavaScript is a good idea as well but I’m absolutely inexperienced with JavaScript but a least a little bit in php why I decided to take this way. But definitely there’s different ways to reach that goal.

Many thanks for your comments and best,
Matthias.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.