Hi,
Since 4.0.0M3 (and now M4 as well), oh-repeater does not refresh when using the ‘key:’ parameter.
Previously, I had been using this technique to dynamically add and remove metadata and tags and add and remove groups etc.
In plain language - I send a string to an item via my widget, then parse that string for use in rules that add and remove tags and metadata etc, then the UI usually needs to update to reflect this change.
I had been using the key: parameter to refresh my oh-repeaters with the following:
key: =Math.random() + items.LightSystem_Config.state
This still seems to work with other components, but not the oh-repeater.
Maybe @florian-h05 and @JustinG have some input on this?
I use this for all sorts of tasks.
Some of my lighting pages show this
The widget for ‘Add Associated Motion Sensors’ looks like this:
uid: lightAssociatedSensors
tags: []
props:
parameters:
- description: The item as a text string
label: Item
name: item
required: false
- description: Tag to search for and repeat
label: Tag
name: searchForTag
required: false
type: TEXT
parameterGroups: []
timestamp: Dec 3, 2022, 9:27:51 PM
component: f7-page
config: {}
slots:
default:
- component: Label
config:
style:
font-weight: bold
margin: 16px
text: ='CHOOSE SENSORS TO TRIGGER ' + props.item.replaceAll("_", " ")
- component: f7-card
config:
style:
border-radius: 8px
slots:
default:
- component: f7-list
slots:
default:
- component: oh-repeater
config:
fetchMetadata: semantics, widgetOrder
for: item
itemTags: MotionSensor
key: =Math.random() + items.LightSystem_Config.state
sourceType: itemsWithTags
slots:
default:
- component: oh-list-item
config:
action: command
actionCommand: '=
(loop.item.tags.includes("AssociatedWith_" + props.item)) ? props.item + "," + loop.item.name + ",REMOVEMOTION" :
props.item + "," + loop.item.name + ",ADDMOTION"
'
actionItem: LightSystem_Config
noChevron: true
title: =loop.item.name.replaceAll("MotionLightSensor_Motion", "").replaceAll("_", " ")
slots:
after:
- component: f7-icon
config:
color: '=(loop.item.tags.includes("AssociatedWith_" + props.item)) ? "blue" : "gray"'
f7: checkmark
visible: '=(loop.item.tags.includes("AssociatedWith_" + props.item)) ? true : false'
This toggles between sending a string of “Light Name”, “Sensor Name”, and either the string “ADDMOTION” or “REMOVEMOTION” to the string item I call “LightSystem_Config”. All seperated by “,”.
The rule then takes this and either adds or removes tags from the appropriate sensor.
console.loggerName = 'org.openhab.LightingConfig';
rules.JSRule({
name: "Lighting config",
description: "Execute commands from UI",
triggers: [
triggers.ItemStateChangeTrigger('LightSystem_Config')
],
execute: (event) => {
// console.info("Received light config command: " + items.getItem(event.itemName).state)
const commandItem = items.getItem(event.itemName)
const commandParts = commandItem.state.split(',')
const lightName = commandParts[0]
const SensorName = commandParts[1]
const commandName = commandParts[2]
const Sensor = items.getItem(SensorName, true)
const assMotionSensorsGroup = items.getItem(lightName + "_AssociatedMotionSensors", true)
if (commandName == "ADDMOTION") {
console.info(commandName + " - " + SensorName + " to " + lightName)
Sensor.addTags("AssociatedWith_" + lightName)
Sensor.addGroups(assMotionSensorsGroup)
} else if (commandName == "REMOVEMOTION"){
console.info(commandName + " - " + SensorName + " from " + lightName)
Sensor.removeTags("AssociatedWith_" + lightName)
Sensor.removeGroups(assMotionSensorsGroup.name)
if (assMotionSensorsGroup.members.length == 0) {
assMotionSensorsGroup.postUpdate('NULL')
}
commandItem.sendCommand("waiting for next command")
}
})
The last command that sends “waiting for next command” to the string item not only clears the text field so it looks neat in the UI, but it triggers an update of the “LightSystem_Config” item, which is required to trigger an update/change for the oh-repeater UI after the tags and groups have been applied (key: =Math.random() + items.LightSystem_Config.state)