Sorry Manfred,
I’ve send you in the wrong direction. The documents I referenced and the code I’ve given are intended for DSL scripts. For ECMA script, this is the right way to go:
'use strict';
var logger = Java.type("org.slf4j.LoggerFactory").getLogger("org.openhab.model.script.Rules.Experiments");
var PersistenceExtensions = Java.type("org.openhab.core.persistence.extensions.PersistenceExtensions");
var ZonedDateTime = Java.type("java.time.ZonedDateTime");
var myPersistentItem = ir.getItem("ZW_Switch_Kocher_Power");
logger.info("The pyload is {}", myPersistentItem);
var sinceDate = ZonedDateTime.now().minusHours(5);
var maximumValueSince = PersistenceExtensions.maximumSince(myPersistentItem, sinceDate);
logger.info("Historic item is {}", maximumValueSince);
logger.info("Item name is {}", maximumValueSince.name);
logger.info("Item state is {}", maximumValueSince.state);
I’ve tested the code with one of my items. The key here is to use the PersitenceExtension
, which is the javascript object to access historic data of items. The documentation I got from the JavaDoc pages found here:
As you can see, the historic state is an item with name, state and a timestamp.The state has the value, you got from the PersistenceExtension. In you case the maximumSice value.