How to Edit input on openHAB UI

I am new here and need some help.

How can input be edited in the openHAB UI yet - anyone got any bright ideas?

1 Like

It depends on the input :slight_smile: i.e. if you have a number, you could use a setpoint item to change it’s value, or maybe set up an item with buttons:
.items

Number Set_Value "Set Value" {autoupdate="false"}// proxy item
Number MyItem "My Item is [%s]"

.sitemap

Switch item=Set_Value mappings=[-10="-10",-1="-1",1="+1",10="+10"]

.rules

rule "Set the Value"
when
    Item Set_Value received command
then
    switch (receivedCommand) {
        case -10 : MyItem.sendCommand((MyItem.state as DecimalType)-10)
        case  -1 : MyItem.sendCommand((MyItem.state as DecimalType)-1)
        case   1 : MyItem.sendCommand((MyItem.state as DecimalType)+1)
        case  10 : MyItem.sendCommand((MyItem.state as DecimalType)+10)
        default  : logInfo("Set_Value","Wrong value: {}",receivedCommand.toString)
    }
end

This would result in an Item with four buttons. Every time you press one of these buttons, the value of MyItem will change accordingly.
There is no way to get a free input from the UI, though you could build a webpage with text input which will push it’s input through REST to openHAB, and then integrate this webpage with the webview widget to openHAB. (sure, a huge workaround.)

thanks

Thanks Udo.

I have an issue and getting this message:

Cannot cast org.openhab.core.types.UnDefType to
org.openhab.core.library.types.DecimalType

Probably issue with initialization. Any thoughts?

Ah, yes. You can catch this in different ways. The first option is, set MyItem to 0 (or any other start value) at startup:

rule "start openHAB"
when
    System started
then
    MyItem.postUpdate(0)
end

Or you can catch the Issue with this line between then and switch in the “set the value” rule:

if (!(MyItem.state instanceOf DecimalType)) MyItem.postUpdate(0)

The best Option probably would be to persist and restoreOnStartup MyItem with mapdb for example. (in addition to the second option, to initialize MyItem one-time.