Hmerk - second Test - DO NOT INSTALL

Resources

uid: hmerk:actual_energy_consumption
label: Actual energy consumption
description: Updates Items holding information of actual energy consumption
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

@stefan.hoehn Could you please have a look at this template.
It creates a working script part, but the “since” definition is not shown in Blockly …

To be honest, I have no experience with templates. What I did though, I created a blockly rule and pasted your xml into the block part. This created the following blocks

and from there the following code was created:

items.getItem('{{groupItem}}_UsageToday').
  postUpdate((items.getItem('{{groupItem}}_MeterValue').
  persistence.deltaSince(time.ZonedDateTime.now().minusHours(1))?.numericState));
items.getItem('{{groupItem}}_UsageWeek').postUpdate((items.getItem('{{groupItem}}_MeterValue').persistence.deltaSince(time.ZonedDateTime.now().minusHours(1))?.numericState));
items.getItem('{{groupItem}}_UsageMonth').postUpdate((items.getItem('{{groupItem}}_MeterValue').persistence.deltaSince(time.ZonedDateTime.now().minusHours(1))?.numericState));
items.getItem('{{groupItem}}_UsageYear').postUpdate((items.getItem('{{groupItem}}_MeterValue').persistence.deltaSince(time.ZonedDateTime.now().minusHours(1))?.numericState));
items.getItem('{{groupItem}}_UsageBillingCycle').postUpdate((items.getItem('{{groupItem}}_MeterValue').persistence.deltaSince(time.ZonedDateTime.now().minusHours(1))?.numericState));

which seems to be correct, doesn’t it?

If you are using a template and it doesn’t work there, you probably have to file a bug because I first need to get acquainted how templates actually work to try to figure out what the issue is.

What I know is that behind the scenes, this is a complex block that uses so called mutators which dynamically decide what is allowed and what not, so it might go together with the issue you encounter.

Yes, the script code is correct, but the Blockly rendering isn’t. The “since” part is completely wrong (empty) and therefore not changeable.
This is, what it should look like:


I will open a detailed issue / bug report on git.

How about a making a joint call session?

Of course, when ???

We found the problem: one of the blocks had a wrong name: dayInfo instead of the new name dayInfoSince

Thanks for the joint session @stefan.hoehn !!

For others : we could identify the issue within the blockly code. The template was created before “dayInfo” was changed to “dayInfoSince”. After editing the test template, everything was fine.
I am going to edit my originnal templates to make them working again.

I will close this topic and remove the published tag.