Max_G
(Max G)
1
- openHABian 3.3.0 on rPi4 with 4GB
I have recently migrated from OH1/2 to OH3. With almost 1,000 items, I wonder if there is a way to list all items that have a state of NULL.
I could check this now, to see what should be initialised and isn’t, and run this post a reboot to see what has no persisted value attached to it.
jimtng
(jimtng)
2
depends on your chosen scripting language.
In jruby:
logger.info items.reject(&:state?).map(&:name)
This will give you the list of items that are NULL or UNDEF
If you specifically want just NULL:
logger.info items.select(&:null?).map(&:name)
Or just UNDEF:
logger.info items.select(&:undef?).map(&:name)
rlkoshak
(Rich Koshak)
3
In Rules DSL:
import org.eclipse.smarthome.model.script.ScriptServiceUtil
...
// inside a rule
val allNullItems = ScriptServiceUtil.getItemRegsitry.getItems.filter[ i | i.state == NULL]
Nashorn JavaScript
var Collectors = Java.type("java.util.stream.Collectors");
var allNullItems = items.stream().filter(function(i) { return i.state == NULL; } ).collect(Collectors.toList());
JS Scripting
var allNullItems = items.getItems().filter((i) => { return i.state == "NULL"; });
1 Like
kobold
( kobold)
4
in openHAB 3.4.0y the import must be named
import org.openhab.core.model.script.ScriptServiceUtil
In the solution, there is a small error in the command “getItemRegistry” for the RuleDSL. It should be
val allNullItems = ScriptServiceUtil.getItemRegistry.getItems.filter[ i | i.state == NULL]