This rule template is a simplified version of my already published historical energy consumption template.
Simplified means, you only need to configure the equipment group item for your meter, no matter what meter type it is. You just need to follow the naming guidelines already used within the semanticHomeMenu.
There will also be a widget to be used within the semanticHomeMenu project.
Language: Blockly/JS Scripting
Changelog
Version 0.1
- initial release
Resources
uid: hmerk:historical_consumption
label: semanticHomeMenu Historical Consumption
description: semanticHomeMenu Rule Template for historical consumption calculations
configDescriptions:
- name: persistenceService
type: TEXT
context: text
label: Persistence Service
description: Persistence service used to store information
limitToOptions: true
options:
- label: default
value: default
- label: RRD4J
value: rrd4j
- label: MapDB
value: mapdb
required: true
- name: groupItem
type: TEXT
context: item
label: Equipment Group Item
description: Equipment Group Item
required: true
triggers:
- id: "1"
configuration:
cronExpression: 1 0 0 * * ? *
type: timer.GenericCronTrigger
conditions: []
actions:
- inputs: {}
id: "2"
configuration:
blockSource: <xml xmlns="https://developers.google.com/blockly/xml"><block
type="oh_event" id="DcoZNq7swfEZoj)0Ua]X" x="-820" y="-416"><field
name="eventType">postUpdate</field><value name="value"><shadow
type="text" id="#(yQc8CV:OKPW@[kDmLq"><field
name="TEXT">value</field></shadow><block type="oh_get_persistvalue"
id="QcdG@s#+KDDo52O!ai.+"><field
name="methodName">deltaSince</field><value name="itemName"><shadow
type="oh_item" id="Py}?{~?.icb-QZU-}e|%"><mutation itemName="MyItem"
itemLabel="MyItem"></mutation><field
name="itemName">MyItem</field></shadow><block type="oh_item"
id="{c|-MK@dbovJXw#OdoU%"><mutation
itemName="{{groupItem}}_MeterValue" itemLabel="Meter
Value"></mutation><field
name="itemName">'{{groupItem}}_MeterValue'</field></block></value><value
name="persistenceName"><shadow type="oh_persistence_dropdown"
id="a|^dX_MtavSf1=2cxeGW"><field
name="persistence">default</field></shadow><block
type="oh_persistence_dropdown" id="u.6YT}kCv9:!jJLX)Ha|"><field
name="persistence">rrd4j</field></block></value><value
name="dayInfoSince"><block type="oh_zdt_plusminus"
id="[bDW~ua-t]1?8nutF9y!"><field name="plusminus">minus</field><field
name="period">Days</field><value name="offset"><shadow
type="math_number" id="{sVjuwBlf6dS!(gW*BYk"><field
name="NUM">0</field></shadow><block type="math_number"
id="WSiMw);T_W7KBh@4-u_L"><field
name="NUM">1</field></block></value></block></value></block></value><value
name="itemName"><shadow type="oh_item"
id="NPb)7;I@d$=vPq^*MJ)`"><mutation itemName="MyItem"
itemLabel="MyItem"></mutation><field
name="itemName">MyItem</field></shadow><block type="oh_item"
id="a8-G;5w)iG|(X+LUPFbs"><mutation
itemName="{{groupItem}}_UsageDaily" itemLabel="Usage
Daily"></mutation><field
name="itemName">'{{groupItem}}_UsageDaily'</field></block></value><next><block
type="controls_if" id="0?4$NID6H0C9A#:}wuQ!"><value name="IF0"><block
type="logic_compare" id="U6pYz7%x*I#a`^Y!pGY~"><field
name="OP">EQ</field><value name="A"><block type="oh_get_zdt_part"
id="RR$AD9u6D!yHL3_n!WXk"><field
name="temporalPart">getDayOfWeek</field><value name="zdt"><block
type="oh_zdt_now"
id="nYo=K+nRS]V%g#,Pi;t/"></block></value></block></value><value
name="B"><block type="math_number" id="9%MBAcAkS:LmTC52RXu*"><field
name="NUM">1</field></block></value></block></value><statement
name="DO0"><block type="oh_event" id="{8[5EibFv*n^xlsfU_9r"><field
name="eventType">postUpdate</field><value name="value"><shadow
type="text" id="#(yQc8CV:OKPW@[kDmLq"><field
name="TEXT">value</field></shadow><block type="oh_get_persistvalue"
id="%EWS?a0ed.^2W%u0r/4T"><field
name="methodName">deltaSince</field><value name="itemName"><shadow
type="oh_item" id="4~Z=Bm{5152mLS;7$5k}"><mutation itemName="MyItem"
itemLabel="MyItem"></mutation><field
name="itemName">MyItem</field></shadow><block type="oh_item"
id="|D|At2K+fPXe#|m]z}MD"><mutation
itemName="{{groupItem}}_MeterValue" itemLabel="Meter
Value"></mutation><field
name="itemName">'{{groupItem}}_MeterValue'</field></block></value><value
name="persistenceName"><shadow type="oh_persistence_dropdown"
id="a|^dX_MtavSf1=2cxeGW"><field
name="persistence">default</field></shadow><block
type="oh_persistence_dropdown" id="O_c{pjiLi0O6(c+/5ug5"><field
name="persistence">rrd4j</field></block></value><value
name="dayInfoSince"><block type="oh_zdt_plusminus"
id="y[1(nPz]4`Nk7Kq#pVMS"><field name="plusminus">minus</field><field
name="period">Weeks</field><value name="offset"><shadow
type="math_number" id="%ENY;4,LF9~rYdncN*J."><field
name="NUM">0</field></shadow><block type="math_number"
id="n};3a{3CvDCE)8$V]V9%"><field
name="NUM">1</field></block></value></block></value></block></value><value
name="itemName"><shadow type="oh_item"
id="#fQEeLvX$:+Ok0s-_ndA"><mutation itemName="MyItem"
itemLabel="MyItem"></mutation><field
name="itemName">MyItem</field></shadow><block type="oh_item"
id="4TyCQX|zx,QZlhsj[R4d"><mutation
itemName="{{groupItem}}_UsageWeekly" itemLabel="Usage
Weekly"></mutation><field
name="itemName">'{{groupItem}}_UsageWeekly'</field></block></value><next><block
type="controls_if" id="|NWnM*J!|AH9]Zfa[w-m"><value name="IF0"><block
type="logic_compare" id="[E}0z@95rr_-(^9a##Iq"><field
name="OP">EQ</field><value name="A"><block type="oh_get_zdt_part"
id="(hY?hpqJyp,-~lbvVgB]"><field
name="temporalPart">getDayOfMonth</field><value name="zdt"><block
type="oh_zdt_now"
id="(Dm;y)NZo`dU-VwwNI,q"></block></value></block></value><value
name="B"><block type="math_number" id="i{%ezg~{d;[v`o^#g[L,"><field
name="NUM">1</field></block></value></block></value><statement
name="DO0"><block type="oh_event" id=",%4=aUR`Dp;lZk[vS=iI"><field
name="eventType">postUpdate</field><value name="value"><shadow
type="text" id="#(yQc8CV:OKPW@[kDmLq"><field
name="TEXT">value</field></shadow><block type="oh_get_persistvalue"
id="*}wUT?2YIi{%UWLFF)R["><field
name="methodName">deltaSince</field><value name="itemName"><shadow
type="oh_item" id="E16,H4)4DqzApG}4|Mrm"><mutation itemName="MyItem"
itemLabel="MyItem"></mutation><field
name="itemName">MyItem</field></shadow><block type="oh_item"
id="1u;KZKQ;4ytz0hKJT;/f"><mutation
itemName="{{groupItem}}_MeterValue" itemLabel="Meter
Value"></mutation><field
name="itemName">'{{groupItem}}_MeterValue'</field></block></value><value
name="persistenceName"><shadow type="oh_persistence_dropdown"
id="a|^dX_MtavSf1=2cxeGW"><field
name="persistence">default</field></shadow><block
type="oh_persistence_dropdown" id="`w~opwkei^7CIB3FrO+."><field
name="persistence">rrd4j</field></block></value><value
name="dayInfoSince"><block type="oh_zdt_plusminus"
id="Z?~MSD!-em3!8FSpdz8c"><field name="plusminus">minus</field><field
name="period">Months</field><value name="offset"><shadow
type="math_number" id="#+a!N7#(|H6,-X8@ROJU"><field
name="NUM">0</field></shadow><block type="math_number"
id=")^WuCM:FMVt1,K*X5STB"><field
name="NUM">1</field></block></value></block></value></block></value><value
name="itemName"><shadow type="oh_item"
id="u9c,ktf{y}x6}w%8#jj~"><mutation itemName="MyItem"
itemLabel="MyItem"></mutation><field
name="itemName">MyItem</field></shadow><block type="oh_item"
id="Sc9a}rvsYblGZ4/n@Rs]"><mutation
itemName="{{groupItem}}_UsageMonthly" itemLabel="Usage
Monthly"></mutation><field
name="itemName">'{{groupItem}}_UsageMonthly'</field></block></value><next><block
type="controls_if" id="Z|(jQNM~N;sjEs_9,OD,"><value name="IF0"><block
type="logic_compare" id="~BC$sP`2wv49=P@wbIQl"><field
name="OP">EQ</field><value name="A"><block type="oh_get_zdt_part"
id="%X4Q/;r!xG,lPkC3i,~E"><field
name="temporalPart">getDayOfYear</field><value name="zdt"><block
type="oh_zdt_now"
id="1/mF/jsRwX7L}-V/eu8#"></block></value></block></value><value
name="B"><block type="math_number" id="C8-sV|{33~aWV%c8.]5|"><field
name="NUM">1</field></block></value></block></value><statement
name="DO0"><block type="oh_event" id="ThuO;#wF9bwNr`GCc#zC"><field
name="eventType">postUpdate</field><value name="value"><shadow
type="text" id="#(yQc8CV:OKPW@[kDmLq"><field
name="TEXT">value</field></shadow><block type="oh_get_persistvalue"
id="e!g~$Qww)$==?dC|Ph?."><field
name="methodName">deltaSince</field><value name="itemName"><shadow
type="oh_item" id="E16,H4)4DqzApG}4|Mrm"><mutation itemName="MyItem"
itemLabel="MyItem"></mutation><field
name="itemName">MyItem</field></shadow><block type="oh_item"
id="#($cP7M_#{wMbxt.#k[b"><mutation
itemName="{{groupItem}}_MeterValue" itemLabel="Meter
Value"></mutation><field
name="itemName">'{{groupItem}}_MeterValue'</field></block></value><value
name="persistenceName"><shadow type="oh_persistence_dropdown"
id="a|^dX_MtavSf1=2cxeGW"><field
name="persistence">default</field></shadow><block
type="oh_persistence_dropdown" id="3A$FKU5,%6(lF$U]q[Sr"><field
name="persistence">rrd4j</field></block></value><value
name="dayInfoSince"><block type="oh_zdt_plusminus"
id="Sy2=fJPU]:hwbCwD+B|Y"><field name="plusminus">minus</field><field
name="period">Years</field><value name="offset"><shadow
type="math_number" id="#+a!N7#(|H6,-X8@ROJU"><field
name="NUM">0</field></shadow><block type="math_number"
id="?n62/(a806h70QpkWW+2"><field
name="NUM">1</field></block></value></block></value></block></value><value
name="itemName"><shadow type="oh_item"
id="u9c,ktf{y}x6}w%8#jj~"><mutation itemName="MyItem"
itemLabel="MyItem"></mutation><field
name="itemName">MyItem</field></shadow><block type="oh_item"
id="?(##OvabvK76gTfk7(Q2"><mutation
itemName="{{groupItem}}_UsageYearly" itemLabel="Usage
Yearly"></mutation><field
name="itemName">'{{groupItem}}_UsageYearly'</field></block></value></block></statement></block></next></block></next></block></next></block></xml>
type: application/javascript
script: >
items.getItem('{{energyUsageDaily}}').postUpdate((items.getItem('{{groupItem}}'+'_MeterValue').persistence.deltaSince(time.ZonedDateTime.now().minusDays(1),
'{{persistenceService}}')));
if (((time.ZonedDateTime.now()).dayOfWeek().value()) == 1) {
items.getItem('{{energyUsageWeekly}}').postUpdate((items.getItem('{{groupItem}}'+'_MeterValue').persistence.deltaSince(time.ZonedDateTime.now().minusWeeks(1), '{{persistenceService}}')));
}
if (((time.ZonedDateTime.now()).dayOfMonth()) == 1) {
items.getItem('{{energyUsageMonthly}}').postUpdate((items.getItem('{{groupItem}}'+'_MeterValue').persistence.deltaSince(time.ZonedDateTime.now().minusMonths(1), '{{persistenceService}}')));
}
if (((time.ZonedDateTime.now()).dayOfYear()) == 1) {
items.getItem('{{energyUsageYearly}}').postUpdate((items.getItem('{{groupItem}}'+'_MeterValue').persistence.deltaSince(time.ZonedDateTime.now().minusYears(1), '{{persistenceService}}')));
}
type: script.ScriptAction