Hey guys,
I would like to get the historic state of an item as text in the sitemap. E.G. energy consumption in the past month.
This is easy if you use a chart. But I want just a number. Have anybody an idea how to solve this? Ot do I need a rule and more items for this?
best regards
hmerk
(Hans-Jörg Merk)
May 14, 2025, 8:36am
2
You need an Item to show this value in the sitemap and a rule that does the calculation.
You might want to check the rule templates marketplace where I published two templates, one for actual energy consumption and one for historical.
Thanks @hmerk
This is a blocky rule right?
I want to do this as a rule with dsl code. As all other thinks.
So I tried to use your code. But I get an error in the log with my attempt.
configuration: {}
triggers:
- id: "1"
configuration:
time: 00:01
type: timer.TimeOfDayTrigger
conditions: []
actions:
- inputs: {}
id: "2"
configuration:
type: application/vnd.openhab.dsl.rule
script: >-
items.getItem(Haus_Ernergiezaehler_Hausstrom_Aktuelles_Jahr).postUpdate((items.getItem(Haus_Ernergiezaehler_Hausstrom).persistence.deltaSince(time.ZonedDateTime.now().minusDays(1),
'rrd4j')));
if (((time.ZonedDateTime.now()).dayOfYear()) == 1) {
items.getItem(Haus_Ernergiezaehler_Hausstrom_Aktuelles_Jahr).postUpdate((items.getItem(Haus_Ernergiezaehler_Hausstrom).persistence.deltaSince(time.ZonedDateTime.now().minusYears(1), 'rrd4j')));
}
type: script.ScriptAction
The error is:
2025-05-14 20:19:03.147 [ERROR] [.handler.AbstractScriptModuleHandler] - Script execution of rule with UID ‘Calculation_Haus_Ernergiezaehler_Hausstrom_Aktuelles_Jahr’ failed: if ((( ___ time.ZonedDateTime.now()).dayOfYear()) == 1) {
items.getItem(Haus_Ernergiezaehler_Hausstrom_Aktuelle ___ s_Jahr).postUpdate((items.getItem(Haus_Ernergiezaehler_Hausstrom).persist ___ ence.deltaSince(time.ZonedDateTime.now().minusYears(1), ‘rrd4j’)));
}
The method or field time is undefined; line 1, column 6, length 4
The method or field items is undefined; line 2, column 63, length 5
The method or field items is undefined; line 2, column 136, length 5
The method or field time is undefined; line 2, column 205, length 4
Do you have any suggestion where my mistake is?
Thank you for your help
hmerk
(Hans-Jörg Merk)
May 14, 2025, 6:57pm
4
Sorry, but I don’t use DSL Rules, so cannot tell the correct syntax. Blockly creates Javascript code.