Is it possible to make a custom widget with oh-repeater to have one oh-list-item for each string?
As you sure can see i wanted to use semicolon as delimiter → Changing the string by adding more strings, divided by “;” shall automatically add oh-list-items to the widget
I thought may could use the .spllit(";") operation to generate an array from this string directly within the widget definition
Your array is actually probably working just fine. I have widgets where I use split() for exactly this purpose in a repeater. I suspect the problem is that your widget is not rendering properly because your YAML isn’t quite lined up right.
The slots for the oh-list-card should be in line with the config and everything below that should move in one indent accordingly:
Now i have changed the value of lTim_Str to “day1;day2;day3”
→ So i should generate 3 list-items because of the three strings inbetween the semicolons, but it generates only one
You also have an error in how you are using the items object. There are two ways to reference the various items available in that object. One is a direct reference to the key in the object that is the item’s name; this way doesn’t use any quotes:
items.exactItemName.state
The second way uses brackets for an indirect reference which allows you to reference keys using string variables or other indirect methods. That means, however, that if you are going to use the item name within the brackets you have to put that item name within quotes to make it a string:
items["exactItemName"].state
So you either need to put quotes around lTim_Str in the two places where it is inside the brackets or just use the direct method.
So to finish this up,
with great help from @JustinG i got the first part of my todo-widget for “house tasks” done.
Purpose is, that i have arrays for
Timestamp (in front of -)
Topic (Badges)
Bandge-Colors
Text (after -)
Item, storing which line was klicked → the clicked one can thenn be deleted via the red button
In the background also custom action shall be settable to maybe direcly get to the relevant site for each message
This way every function can create messages which are important and they can be handled.
Number of Tasks is flexible, due to the fact, that the information is stored in Semicolon-separated Strings
I just wanted to leave the now partially done code for others, trying to do similar things
NOTE: For loop.int_idx the behaviour for index 0 was strange → I had to catch this one by using the syntax actionCommand: '=(loop.int_idx == "") ? "0" : loop.int_idx'
OK so now just the last update:
I now changed this Widget to be a List/Card “House Tasks and Notifications” Widget
Here a short overview
Features, the cards can be handled:
Set Title
Set Topic (Badge)
Set Color (Badge + Icon)
Set Icon
Set footer = Time, related to the task
Set Action
For Action to set there are possibilties
Set no action → Blue Button will not be shown
Set action → Various actions possible (command, navigate, etc.)
Over all:
This is the way i wanted a Task-System for the house to be
Each Source-Rule/Function can attach new Strings to the current Items and this automatically creates a new Task widget with super individual configuration possibilities
Examples:
Error in the system → Action button shall navigate to a page of openHAB 3 UI
Im not a very advanced user so there will surely be things i did not code in a perfect way → If someone sees optimization possibilities → Feel free to let me know
For me this is a custom Task-function i love because everyone in the house can see and manage these tasks and i dont need a external service for it.
I will also integrate a push-notification through the app, in case a new message is added.
// ========================================================
// LOGGING TASKS
// ========================================================
rule "Logging Task Delete"
when
Item lDel_Num changed
then
// If a valid item number to delete was set
if (lDel_Num.state >= 0){
logInfo("LOGGINGTASK", "Task #" + lDel_Num.state +" erased")
// Declarate temp Strings
var String lTim_Str_tmp = ""
var String lTop_Str_tmp = ""
var String lCol_Str_tmp = ""
var String lTxt_Str_tmp = ""
var String lIco_Str_tmp = ""
var String lAct_Str_tmp = ""
var String lActCom_Str_tmp = ""
var String lActItm_Str_tmp = ""
var String lActTar_Str_tmp = ""
var String lActTxt_Str_tmp = ""
// Get number of items
var Number len = lTxt_Str.state.toString.split(";").length
// Set numerator
var Number i = 0
// Loop through elements
while (i< len) {
// Do not copy the part which is to delete
if (lDel_Num.state as Number != i){
// Copy Task if it shall not be deleted
lTim_Str_tmp = lTim_Str_tmp + lTim_Str.state.toString.split(";").get(i.intValue).toString + ";"
lTop_Str_tmp = lTop_Str_tmp + lTop_Str.state.toString.split(";").get(i.intValue).toString + ";"
lCol_Str_tmp = lCol_Str_tmp + lCol_Str.state.toString.split(";").get(i.intValue).toString + ";"
lTxt_Str_tmp = lTxt_Str_tmp + lTxt_Str.state.toString.split(";").get(i.intValue).toString + ";"
lIco_Str_tmp = lIco_Str_tmp + lIco_Str.state.toString.split(";").get(i.intValue).toString + ";"
lAct_Str_tmp = lAct_Str_tmp + lAct_Str.state.toString.split(";").get(i.intValue).toString + ";"
lActCom_Str_tmp = lActCom_Str_tmp + lActCom_Str.state.toString.split(";").get(i.intValue).toString + ";"
lActItm_Str_tmp = lActItm_Str_tmp + lActItm_Str.state.toString.split(";").get(i.intValue).toString + ";"
lActTar_Str_tmp = lActTar_Str_tmp + lActTar_Str.state.toString.split(";").get(i.intValue).toString + ";"
lActTxt_Str_tmp = lActTxt_Str_tmp + lActTxt_Str.state.toString.split(";").get(i.intValue).toString + ";"
}
logInfo("LOGGINGTASK", lTim_Str_tmp)
// Increase numerator
i = i + 1
}
// Update Log Items
lTim_Str.sendCommand(lTim_Str_tmp)
lTop_Str.sendCommand(lTop_Str_tmp)
lCol_Str.sendCommand(lCol_Str_tmp)
lTxt_Str.sendCommand(lTxt_Str_tmp)
lIco_Str.sendCommand(lIco_Str_tmp)
lAct_Str.sendCommand(lAct_Str_tmp)
lActCom_Str.sendCommand(lActCom_Str_tmp)
lActItm_Str.sendCommand(lActItm_Str_tmp)
lActTar_Str.sendCommand(lActTar_Str_tmp)
lActTxt_Str.sendCommand(lActTxt_Str_tmp)
// Reset Delete Indicator
lDel_Num.sendCommand(-1)
}
end
rule "Logging Task Test"
when
Item tTst_Swt changed from OFF to ON
then
// Define Dummy Arrays
val String aTim = "21.05.2021;Dienstag;Mittwoch;"
val String aTop = "Fehler;Abfall;Wetter;"
val String aTxt = "Heizung - Kreislauf 1 Druck zu hoch;Biomüll;Gewitter;"
val String aCol = "red;green;yellow;"
val String aAct = "navigate;NULL;navigate;"
val String aActCom = "NULL;NULL;NULL;"
val String aActItm = "NULL;NULL;NULL;"
val String aActTar = "page:buero;NULL;page:buero;"
val String aActTxt = "Detail;NULL;Gehe zu weather.com;"
val String aIco = "f7:exclamationmark_circle_fill;f7:archivebox;f7:cloud;"
// Set Values
lTim_Str.sendCommand(aTim)
lTop_Str.sendCommand(aTop)
lTxt_Str.sendCommand(aTxt)
lCol_Str.sendCommand(aCol)
lAct_Str.sendCommand(aAct)
lActCom_Str.sendCommand(aActCom)
lActItm_Str.sendCommand(aActItm)
lActTxt_Str.sendCommand(aActTxt)
lIco_Str.sendCommand(aIco)
lActTar_Str.sendCommand(aActTar)
lDel_Num.sendCommand(-1)
end