semanticHomeMenu actual consumptions [4.0.0.0;4.9.9.9]

This rule template is a simplified version of my already published 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:actual_consumption
label: semanticHomeMenu Actual Consumption
description: semanticHomeMenu Rule Template for actual 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:
      itemName: "{{groupItem}}_MeterValue"
    type: core.ItemStateChangeTrigger
conditions: []
actions:
  - inputs: {}
    id: "2"
    configuration:
      blockSource: <xml xmlns="https://developers.google.com/blockly/xml"><block
        type="oh_event" id="wR2@!=5jfQG3|Tnh{+~x" x="-18" y="-712"><field
        name="eventType">postUpdate</field><value name="value"><shadow
        type="text" id="jWgD4t7.O;)]3OP#c3_R"><field
        name="TEXT">value</field></shadow><block type="oh_get_persistvalue"
        id="o{T16a(Kz8%H}OiFX!92"><field
        name="methodName">deltaSince</field><value name="itemName"><shadow
        type="oh_item" id=";^(0GHJN+qNYn[-TH#fs"><mutation itemName="MyItem"
        itemLabel="MyItem"></mutation><field
        name="itemName">MyItem</field></shadow><block type="oh_item"
        id="Tzh_y}fz^X{LSYcL)1:A"><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="4Ip6?cO^P}fVH,;U(Ig1"><field
        name="persistence">default</field></shadow><block
        type="oh_persistence_dropdown" id="6jc}NQ;mmWl:(zG!(jGl"><field
        name="persistence">{{persistenceService}}</field></block></value><value
        name="dayInfoSince"><block type="oh_zdt_amend"
        id="iD,W+1Cif+R+$PB{G9C4"><mutation items="3"></mutation><field
        name="operation">with</field><value name="baseZdt"><shadow type="oh_zdt"
        id=".}/;k[$7Zc)QZ#L7]?N^"><field
        name="day">2023-11-06</field></shadow><block type="oh_zdt_now"
        id="/1C:nps2x$!r8vhRP|j#"></block></value><value name="ADD0"><block
        type="oh_zdt_temporal_unit" id="8-|B:O|.DMk.L})K80LD"><mutation
        blockType="3"></mutation><field
        name="value">0</field></block></value><value name="ADD1"><block
        type="oh_zdt_temporal_unit" id="RKZtxH:+496e2$dQ!%8M"><mutation
        blockType="4"></mutation><field
        name="value">0</field></block></value><value name="ADD2"><block
        type="oh_zdt_temporal_unit" id="@5]mF~iAPG:(bp:p[G$W"><mutation
        blockType="5"></mutation><field
        name="value">0</field></block></value></block></value></block></value><value
        name="itemName"><shadow type="oh_item"
        id="Pt$^PEJnHsZ}1wO!(iS%"><mutation itemName="MyItem"
        itemLabel="MyItem"></mutation><field
        name="itemName">MyItem</field></shadow><block type="oh_item"
        id="+h(C{ZBBbQbWF0}5O-T("><mutation
        itemName="{{groupItem}}_UsageToday" itemLabel="Usage
        Today"></mutation><field
        name="itemName">'{{groupItem}}_UsageToday'</field></block></value><next><block
        type="oh_event" id="i.q{)XrqTs1%hj:3tW1h"><field
        name="eventType">postUpdate</field><value name="value"><shadow
        type="text" id="jWgD4t7.O;)]3OP#c3_R"><field
        name="TEXT">value</field></shadow><block type="oh_get_persistvalue"
        id="~Fs,0-d,f:r)/)Po0fzF"><field
        name="methodName">deltaSince</field><value name="itemName"><shadow
        type="oh_item" id="eV4}S-t^%::[S(zE:Xlf"><mutation itemName="MyItem"
        itemLabel="MyItem"></mutation><field
        name="itemName">MyItem</field></shadow><block type="oh_item"
        id="SOrpMoT6[8q]knugKx_q"><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="4Ip6?cO^P}fVH,;U(Ig1"><field
        name="persistence">default</field></shadow><block
        type="oh_persistence_dropdown" id="FDP+td7ya7ZJiW/APx7q"><field
        name="persistence">{{persistenceService}}</field></block></value><value
        name="dayInfoSince"><block type="oh_zdt_amend"
        id="2*j}a1;J+ahW).NAc-?_"><mutation items="3"></mutation><field
        name="operation">with</field><value name="baseZdt"><shadow type="oh_zdt"
        id=".}/;k[$7Zc)QZ#L7]?N^"><field
        name="day">2023-11-06</field></shadow><block type="oh_zdt_plusminus"
        id="(kYEPjaai#6;X6p|dxJ4"><field name="plusminus">minus</field><field
        name="period">Days</field><value name="offset"><shadow
        type="math_number" id="-yJ-wrzk}kF?MBl$=Q.v"><field
        name="NUM">0</field></shadow><block type="math_arithmetic"
        id="(oeV|D]OsZCU.`m@)]1p"><field name="OP">MINUS</field><value
        name="A"><shadow type="math_number" id="Fx+Cu7o^MycxpT3jxx+."><field
        name="NUM">1</field></shadow><block type="oh_get_zdt_part"
        id="UZhn],`Suu4@iT2SSiQ!"><field
        name="temporalPart">getDayOfWeek</field><value name="zdt"><block
        type="oh_zdt_now"
        id="kC94|*Hu27vkg)had{QI"></block></value></block></value><value
        name="B"><shadow type="math_number" id=";|j$B7k0jnnHvH@b+~C?"><field
        name="NUM">1</field></shadow></value></block></value></block></value><value
        name="ADD0"><block type="oh_zdt_temporal_unit"
        id="7%H@giD-Uh9,|po3cj2A"><mutation blockType="3"></mutation><field
        name="value">0</field></block></value><value name="ADD1"><block
        type="oh_zdt_temporal_unit" id="dk:_xU=_y{Mk5ff;-[sF"><mutation
        blockType="4"></mutation><field
        name="value">0</field></block></value><value name="ADD2"><block
        type="oh_zdt_temporal_unit" id="}Py6_2W%?tn{lc||R#:D"><mutation
        blockType="5"></mutation><field
        name="value">0</field></block></value></block></value></block></value><value
        name="itemName"><shadow type="oh_item"
        id="Pt$^PEJnHsZ}1wO!(iS%"><mutation itemName="MyItem"
        itemLabel="MyItem"></mutation><field
        name="itemName">MyItem</field></shadow><block type="oh_item"
        id="U^2/Ta?7FbQCrVTT$/6:"><mutation
        itemName="{{groupItem}}_UsageWeek" itemLabel="Usage
        Week"></mutation><field
        name="itemName">'{{groupItem}}_UsageWeek'</field></block></value><next><block
        type="oh_event" id="ekS[%nx~(};zhL!aj3cq"><field
        name="eventType">postUpdate</field><value name="value"><shadow
        type="text" id="jWgD4t7.O;)]3OP#c3_R"><field
        name="TEXT">value</field></shadow><block type="oh_get_persistvalue"
        id="iLkwL4E;@rmKIiZ6qll*"><field
        name="methodName">deltaSince</field><value name="itemName"><shadow
        type="oh_item" id="eV4}S-t^%::[S(zE:Xlf"><mutation itemName="MyItem"
        itemLabel="MyItem"></mutation><field
        name="itemName">MyItem</field></shadow><block type="oh_item"
        id="X2hEF34^7YJOSj0$`K@r"><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="4Ip6?cO^P}fVH,;U(Ig1"><field
        name="persistence">default</field></shadow><block
        type="oh_persistence_dropdown" id="MP#fhHAZvlfF6G`(xA,U"><field
        name="persistence">{{persistenceService}}</field></block></value><value
        name="dayInfoSince"><block type="oh_zdt_amend"
        id="QkmniLh_:l9caOngKc%-"><mutation items="4"></mutation><field
        name="operation">with</field><value name="baseZdt"><shadow type="oh_zdt"
        id=".}/;k[$7Zc)QZ#L7]?N^"><field
        name="day">2023-11-06</field></shadow><block type="oh_zdt_now"
        id="Kb02Z)*92(+@lOWZOvh0"></block></value><value name="ADD0"><block
        type="oh_zdt_temporal_unit" id="H*pv,lD0=!UbXKZdp`[e"><mutation
        blockType="2"></mutation><field
        name="value">1</field></block></value><value name="ADD1"><block
        type="oh_zdt_temporal_unit" id="shEpFhjO1]LDVk{kWlv4"><mutation
        blockType="3"></mutation><field
        name="value">0</field></block></value><value name="ADD2"><block
        type="oh_zdt_temporal_unit" id="2Qm(5K)P]t|PFTNFDHtE"><mutation
        blockType="4"></mutation><field
        name="value">0</field></block></value><value name="ADD3"><block
        type="oh_zdt_temporal_unit" id="YPczNi4E!2m`Zm]0eEDm"><mutation
        blockType="5"></mutation><field
        name="value">0</field></block></value></block></value></block></value><value
        name="itemName"><shadow type="oh_item"
        id="Pt$^PEJnHsZ}1wO!(iS%"><mutation itemName="MyItem"
        itemLabel="MyItem"></mutation><field
        name="itemName">MyItem</field></shadow><block type="oh_item"
        id="Q7zR(dyrQ!pqzAIc8v?j"><mutation
        itemName="{{groupItem}}_UsageMonth" itemLabel="Usage
        Month"></mutation><field
        name="itemName">'{{groupItem}}_UsageMonth'</field></block></value><next><block
        type="oh_event" id=";{L95656B0OHC6ZIf9Qn"><field
        name="eventType">postUpdate</field><value name="value"><shadow
        type="text" id="jWgD4t7.O;)]3OP#c3_R"><field
        name="TEXT">value</field></shadow><block type="oh_get_persistvalue"
        id="KW|1F}!ZJpL#aZem8%[s"><field
        name="methodName">deltaSince</field><value name="itemName"><shadow
        type="oh_item" id="eV4}S-t^%::[S(zE:Xlf"><mutation itemName="MyItem"
        itemLabel="MyItem"></mutation><field
        name="itemName">MyItem</field></shadow><block type="oh_item"
        id="d[6-:!?sti()whBdPIm6"><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="4Ip6?cO^P}fVH,;U(Ig1"><field
        name="persistence">default</field></shadow><block
        type="oh_persistence_dropdown" id="ZD^J(z8(zg7JMpLh4Lx2"><field
        name="persistence">{{persistenceService}}</field></block></value><value
        name="dayInfoSince"><block type="oh_zdt_amend"
        id="?[9oT3IE:*L+{@F~$(/i"><mutation items="5"></mutation><field
        name="operation">with</field><value name="baseZdt"><shadow type="oh_zdt"
        id=".}/;k[$7Zc)QZ#L7]?N^"><field
        name="day">2023-11-06</field></shadow><block type="oh_zdt_now"
        id="z|ebTzv5!aK$J=6?Qjk("></block></value><value name="ADD0"><block
        type="oh_zdt_temporal_unit" id="Em1+}@#N3RS)w1.2ZN!Z"><mutation
        blockType="1"></mutation><field
        name="value">1</field></block></value><value name="ADD1"><block
        type="oh_zdt_temporal_unit" id="(Lk8ACz!])CM0H[HZODa"><mutation
        blockType="2"></mutation><field
        name="value">1</field></block></value><value name="ADD2"><block
        type="oh_zdt_temporal_unit" id="Vp+el6m7t4$S#Z.m97XJ"><mutation
        blockType="3"></mutation><field
        name="value">0</field></block></value><value name="ADD3"><block
        type="oh_zdt_temporal_unit" id="Nmp.vDAE!1zJI-r!LW+."><mutation
        blockType="4"></mutation><field
        name="value">0</field></block></value><value name="ADD4"><block
        type="oh_zdt_temporal_unit" id="9,z(iAJd=|VL98uHq$_,"><mutation
        blockType="5"></mutation><field
        name="value">0</field></block></value></block></value></block></value><value
        name="itemName"><shadow type="oh_item"
        id="Pt$^PEJnHsZ}1wO!(iS%"><mutation itemName="MyItem"
        itemLabel="MyItem"></mutation><field
        name="itemName">MyItem</field></shadow><block type="oh_item"
        id="n0#(pT9Uj$D.G9qpYSf@"><mutation
        itemName="{{groupItem}}_UsageYear" itemLabel="Usage
        Year"></mutation><field
        name="itemName">'{{groupItem}}_UsageYear}}'</field></block></value><next><block
        type="oh_event" id="c)`^`GpeCp)rQf3{pKLq"><field
        name="eventType">postUpdate</field><value name="value"><shadow
        type="text" id="jWgD4t7.O;)]3OP#c3_R"><field
        name="TEXT">value</field></shadow><block type="oh_get_persistvalue"
        id="~/A/N.nVj]EIak,;a#LL"><field
        name="methodName">deltaSince</field><value name="itemName"><shadow
        type="oh_item" id="eV4}S-t^%::[S(zE:Xlf"><mutation itemName="MyItem"
        itemLabel="MyItem"></mutation><field
        name="itemName">MyItem</field></shadow><block type="oh_item"
        id="MeG%yL]#$Poq~}yMXxi;"><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="4Ip6?cO^P}fVH,;U(Ig1"><field
        name="persistence">default</field></shadow><block
        type="oh_persistence_dropdown" id="2hPNgWokiMplnWPc@fDy"><field
        name="persistence">{{persistenceService}}</field></block></value><value
        name="dayInfoSince"><block type="oh_zdt_fromText"
        id="Yi{o9`Uv!L[sTXWKzH%s"><value name="day"><shadow type="text"
        id="%HAh{g{;*ad]1^jZVpn("><field
        name="TEXT">2023-08-19</field></shadow><block type="oh_getitem_state"
        id="#SNHcwEDkwgxVvQEncs+"><value name="itemName"><shadow type="oh_item"
        id="`)F90,]i,zF0!^MTlPjh"><mutation itemName="MyItem"
        itemLabel="MyItem"></mutation><field
        name="itemName">MyItem</field></shadow><block type="oh_item"
        id="Qa|FV[|k3D.`.c}b7|CX"><mutation
        itemName="{{groupItem}}_ReadingDate" itemLabel="Start date of billing period"></mutation><field
        name="itemName">'{{groupItem}}_ReadingDate'</field></block></value></block></value></block></value></block></value><value
        name="itemName"><shadow type="oh_item"
        id="Pt$^PEJnHsZ}1wO!(iS%"><mutation itemName="MyItem"
        itemLabel="MyItem"></mutation><field
        name="itemName">MyItem</field></shadow><block type="oh_item"
        id="QCMA}5ELYGMsf6F4c4yu"><mutation
        itemName="{{groupItem}}_UsageBillingCycle"
        itemLabel="Usage in actual billing period"></mutation><field
        name="itemName">'{{groupItem}}_UsageBillingCycle'</field></block></value></block></next></block></next></block></next></block></next></block></xml>
      type: application/javascript
      script: >
        items.getItem('{{groupItem}}'+'_UsageToday').postUpdate((items.getItem('{{groupItem}}'+'_MeterValue').persistence.deltaSince((time.ZonedDateTime.now()).withHour(0).withMinute(0).withSecond(0),
        '{{persistenceService}}')?.numericState));

        items.getItem('{{groupItem}}'+'_UsageWeek').postUpdate((items.getItem('{{groupItem}}'+'_MeterValue').persistence.deltaSince(time.ZonedDateTime.now().minusDays((((time.ZonedDateTime.now()).dayOfWeek().value()) - 1)).withHour(0).withMinute(0).withSecond(0), '{{persistenceService}}')?.numericState));

        items.getItem('{{groupItem}}'+'_UsageMonth').postUpdate((items.getItem('{{groupItem}}'+'_MeterValue').persistence.deltaSince((time.ZonedDateTime.now()).withDayOfMonth(1).withHour(0).withMinute(0).withSecond(0), '{{persistenceService}}')?.numericState));

        items.getItem('{{groupItem}}'+'_UsageYear').postUpdate((items.getItem('{{groupItem}}'+'_MeterValue').persistence.deltaSince((time.ZonedDateTime.now()).withMonth(1).withDayOfMonth(1).withHour(0).withMinute(0).withSecond(0), '{{persistenceService}}')?.numericState));

        items.getItem('{{groupItem}}'+'_UsageBillingCycle').postUpdate((items.getItem('{{groupItem}}'+'_MeterValue').persistence.deltaSince(time.toZDT(items.getItem('{{groupItem}}'+'_ReadingDate').state), '{{persistenceService}}')?.numericState));
    type: script.ScriptAction