Hi All
I used the following rule in OH2.5 for my alarm Pin Number input.
It appears that it no longer works and I cannot work out why for the life of me:
import org.openhab.core.model.script.ScriptServiceUtil
var registry = ScriptServiceUtil.getItemRegistry()
rule "Pin Input"
when
Item Pin_Number_Input received update
then
var update = Pin_Number_Input.state.toString()
if (update == "") return;
logDebug("Pin_Input", "{}: {}", Pin_Number_Input.name, update)
var target = registry.get(Pin_Number_Input.label)
if (target !== null) {
var text = target.state.toString()
if (text == "" || text == "NULL") text = "_"
else if (!text.contains("_")) text += "_"
if (update.length() == 1) {
text = text.replaceFirst("_", update + "_")
}
else if (update == "DELETE") {
text = text.replaceFirst("._", "_")
}
else if (update == "DONE") {
text = text.replaceFirst("_", "")
createTimer(now.plusSeconds(10), [
Pin_Number.postUpdate("_")
// Pin_Number_Input.postUpdate("")
])
}
//text = text.substring(0, 1).toUpperCase() + text.substring(1).toLowerCase().replace(" ", " ").split(" ").reduce([capitalized, word | capitalized + " " + word.substring(0, 1).toUpperCase() + word.substring(1)])
if (text.contains("_")) target.postUpdate(text)
else target.sendCommand(text.trim())
logInfo("", "EnteredPin " + Pin_Number.state )
}
// createTimer(now.plusSeconds(10), [
// Pin_Number.postUpdate("")
// Pin_Number_Input.postUpdate("")
// ])
end
Looks to me like the line:
text = text.replaceFirst("_", update + "_")
May be the culprit as I am not seeing the Pin_Number_Input getting the concatenated input. It just stays on the single “key” pressed.
Any suggestions for a Non Coder?
Thanks
Mark