Energy Card

Hello,

I’m looking for an energy card, which is showing the following.

  • Power Usage in Watt
  • Consmption Yesterday in kWh
  • Consumption This Year in kWh
  • Consumption Last Year in kWh

This shall be used not only for the energy meter of the house, but also for washing machines, dryer,…

Did anybody already create something like this?
Otherwise I think I would use something like a temperatur card and modify it. Thanks!

I have created something for our UI project, will post the code later


If you click on it, you will find the details….

This is exactly what I’m looking for. :grinning:
It would be great if you could share the code!

I will try to post it today, needs some cleaning as all Items are hardcoded for my needs.

I’m also interested in this. I’m using influxdb to persist my energy meter data so can your code read data from influxdb.

No, the widget just shows several Items. Calculation is done with some Blockly rules, actually using RRD4J persisted values from my installation…

As promised…
EnergyCard

Widget Code
uid: EnergyCard
tags: []
props:
  parameters:
    - context: Text
      default: Smartmeter
      description: Title of the card
      label: Title
      name: title
      required: false
      type: TEXT
    - context: item
      description: Energy Meter Counter Value
      label: Energy Meter Counter Value
      name: energyCounter
      required: true
      type: TEXT
    - context: item
      description: Actual Power Usage
      label: Actual Power Usage
      name: actualPowerUseage
      required: true
      type: TEXT
    - context: item
      description: Energy Consumption Today
      label: Energy Consumption Today
      name: energyUseageToday
      required: true
      type: TEXT
    - context: item
      description: Energy Consumption Yesterday
      label: Energy Consumption Yesterday
      name: energyUseageDaily
      required: true
      type: TEXT
    - context: item
      description: Energy Consumption Actual Week
      label: Energy Consumption Actual Week
      name: energyUseageWeek
      required: true
      type: TEXT
    - context: item
      description: Energy Consumption Last Week
      label: Energy Consumption Last Week
      name: energyUseageWeekly
      required: true
      type: TEXT
    - context: item
      description: Energy Consumption Actual Month
      label: Energy Consumption Actual Month
      name: energyUseageMonth
      required: true
      type: TEXT
    - context: item
      description: Energy Consumption Last Month
      label: Energy Consumption Last Month
      name: energyUseageMonthly
      required: true
      type: TEXT
    - context: item
      description: Energy Consumption Actual Year
      label: Energy Consumption Actual Year
      name: energyUseageYear
      required: true
      type: TEXT
    - context: item
      description: Energy Consumption Billing Cycle
      label: Energy Consumption Billing Cycle
      name: energyUseageBillingCycle
      required: true
      type: TEXT
timestamp: Nov 3, 2023, 11:18:44 PM
component: f7-card
config:
  style:
    --f7-card-header-border-color: transparent
    background: =themeOptions.dark=="light" ? "white"
    border-radius: 10px
    margin-left: 5px
    margin-right: 5px
slots:
  default:
    - component: f7-card-content
      config:
        style:
          height: auto
      slots:
        default:
          - component: f7-list
            config:
              accordionList: true
              mediaList: true
            slots:
              default:
                - component: oh-list-item
                  config:
                    accordionList: true
                    after: =@(props.actualPowerUseage)
                    icon: iconify:ic:outline-electric-meter
                    iconColor: gray
                    mediaList: true
                    style:
                      --f7-list-item-after-font-size: 16px
                      --f7-list-item-after-text-color: "=themeOptions.dark === 'dark' ? 'rgb(180,180,180)' : 'rgb(80,80,80)'"
                    subtitle: '=" Consumption Today : "+ @(props.energyUseageToday)'
                    title: =props.title
                  slots:
                    accordion:
                      - component: f7-list
                        config:
                          mediaList: true
                        slots:
                          default:
                            - component: oh-list-item
                              config:
                                after: =@(props.energyCounter)
                                style:
                                  --f7-list-item-after-font-size: 15px
                                  --f7-list-item-after-text-color: "=themeOptions.dark === 'dark' ? 'rgb(180,180,180)' : 'rgb(100,100,100)'"
                                  --f7-list-item-subtitle-font-size: 14px
                                  --f7-list-item-subtitle-text-color: "=themeOptions.dark === 'dark' ? 'rgb(180,180,180)' : 'rgb(100,100,100)'"
                                  --f7-list-item-title-font-size: 15px
                                  --f7-list-item-title-text-color: "=themeOptions.dark === 'dark' ? 'rgb(180,180,180)' : 'rgb(100,100,100)'"
                                title: Counter Value
                            - component: oh-list-item
                              config:
                                after: =@(props.energyUseageDaily)
                                style:
                                  --f7-list-item-after-font-size: 15px
                                  --f7-list-item-after-text-color: "=themeOptions.dark === 'dark' ? 'rgb(180,180,180)' : 'rgb(100,100,100)'"
                                  --f7-list-item-subtitle-font-size: 14px
                                  --f7-list-item-subtitle-text-color: "=themeOptions.dark === 'dark' ? 'rgb(180,180,180)' : 'rgb(100,100,100)'"
                                  --f7-list-item-title-font-size: 15px
                                  --f7-list-item-title-text-color: "=themeOptions.dark === 'dark' ? 'rgb(180,180,180)' : 'rgb(100,100,100)'"
                                title: Consumption Yesterday
                            - component: oh-list-item
                              config:
                                after: =@(props.energyUseageWeek)
                                style:
                                  --f7-list-item-after-font-size: 15px
                                  --f7-list-item-after-text-color: "=themeOptions.dark === 'dark' ? 'rgb(180,180,180)' : 'rgb(100,100,100)'"
                                  --f7-list-item-subtitle-font-size: 14px
                                  --f7-list-item-subtitle-text-color: "=themeOptions.dark === 'dark' ? 'rgb(180,180,180)' : 'rgb(100,100,100)'"
                                  --f7-list-item-title-font-size: 15px
                                  --f7-list-item-title-text-color: "=themeOptions.dark === 'dark' ? 'rgb(180,180,180)' : 'rgb(100,100,100)'"
                                subtitle: '="Last Week: "+@(props.energyUseageWeekly)'
                                title: Consumption Actual Week
                            - component: oh-list-item
                              config:
                                after: =@(props.energyUseageMonth)
                                style:
                                  --f7-list-item-after-font-size: 15px
                                  --f7-list-item-after-text-color: "=themeOptions.dark === 'dark' ? 'rgb(180,180,180)' : 'rgb(100,100,100)'"
                                  --f7-list-item-subtitle-font-size: 14px
                                  --f7-list-item-subtitle-text-color: "=themeOptions.dark === 'dark' ? 'rgb(180,180,180)' : 'rgb(100,100,100)'"
                                  --f7-list-item-title-font-size: 15px
                                  --f7-list-item-title-text-color: "=themeOptions.dark === 'dark' ? 'rgb(180,180,180)' : 'rgb(100,100,100)'"
                                subtitle: '="Last Month: " + @(props.energyUseageMonthly)'
                                title: Consumption Actual Month
                            - component: oh-list-item
                              config:
                                after: =@(props.energyUseageYear)
                                style:
                                  --f7-list-item-after-font-size: 15px
                                  --f7-list-item-after-text-color: "=themeOptions.dark === 'dark' ? 'rgb(180,180,180)' : 'rgb(100,100,100)'"
                                  --f7-list-item-subtitle-font-size: 14px
                                  --f7-list-item-subtitle-text-color: "=themeOptions.dark === 'dark' ? 'rgb(180,180,180)' : 'rgb(100,100,100)'"
                                  --f7-list-item-title-font-size: 15px
                                  --f7-list-item-title-text-color: "=themeOptions.dark === 'dark' ? 'rgb(180,180,180)' : 'rgb(100,100,100)'"
                                subtitle: '="Actual Billing Cycle: " + @(props.energyUseageBillingCycle)'
                                title: Consumption Actual Year

This also needs two rules to update Items and/or calculate their state from peristed values.
All Items and the persistence service used have to be adopted to your own needs…

Rules Code
configuration: {}
triggers:
  - id: "1"
    configuration:
      itemName: ElectricityMeter_energy180
    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="-14" y="-145"><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="ElectricityMeter_energy180" itemLabel="Energie Gesamt"></mutation><field name="itemName">ElectricityMeter_energy180</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">rrd4j</field></block></value><value name="dayInfo"><block type="deibich:blockly:dateTime_zdt_set_time_with_fields" id="BXkQhKmnZ}Ye]N,[/KuW"><field name="HOURS">0</field><field name="MINUTES">0</field><field name="SECONDS">0</field><value name="DATE"><shadow type="oh_zdt" id="-YwB#{75n6x@v:LZ_wRf"><field name="day">2023-08-20</field></shadow><block type="oh_zdt_now" id="?M%+fG)$eQATRt1NyDX{"></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="ElectricityMeter_energyUsageToday" itemLabel="Energieverbrauch Heute"></mutation><field name="itemName">ElectricityMeter_energyUsageToday</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="ElectricityMeter_energy180" itemLabel="Energie Gesamt"></mutation><field name="itemName">ElectricityMeter_energy180</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">rrd4j</field></block></value><value name="dayInfo"><block type="deibich:blockly:dateTime_zdt_set_time_with_fields" id="H1?zJ%xWP(djG9331v=o"><field name="HOURS">0</field><field name="MINUTES">0</field><field name="SECONDS">0</field><value name="DATE"><shadow type="oh_zdt" id="-YwB#{75n6x@v:LZ_wRf"><field name="day">2023-08-20</field></shadow><block type="oh_zdt_plusminus" id="3CAJ%?j`%-`S(cs646d^"><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="-hadISd2nVwTrE0S+dqb"><field name="OP">MINUS</field><value name="A"><shadow type="math_number" id="}uT^gKPy.r__jTDW@tye"><field name="NUM">1</field></shadow><block type="oh_get_zdt_part" id="6D`|~dy77.lp8moxom7@"><field name="temporalPart">getDayOfWeek</field><value name="zdt"><block type="oh_zdt_now" id="?/[,lh[c8pq@]{#vNLIq"></block></value></block></value><value name="B"><shadow type="math_number" id="8-H0GA(SID)LfG)nFQ)x"><field name="NUM">1</field></shadow></value></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="U^2/Ta?7FbQCrVTT$/6:"><mutation itemName="ElectricityMeter_energyUsageWeek" itemLabel="Energieverbrauch Woche"></mutation><field name="itemName">ElectricityMeter_energyUsageWeek</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="ElectricityMeter_energy180" itemLabel="Energie Gesamt"></mutation><field name="itemName">ElectricityMeter_energy180</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">rrd4j</field></block></value><value name="dayInfo"><block type="deibich:blockly:dateTime_zdt_set_time_with_fields" id="Eu`Ge?Xs@@UdL=#r~vIp"><field name="HOURS">0</field><field name="MINUTES">0</field><field name="SECONDS">0</field><value name="DATE"><shadow type="oh_zdt" id="-YwB#{75n6x@v:LZ_wRf"><field name="day">2023-08-20</field></shadow><block type="oh_zdt_plusminus" id=".wyGf7(:ck4^fV]mPZ~I"><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="#Bag6+_vL=*lvOBmxxHm"><field name="OP">MINUS</field><value name="A"><shadow type="math_number" id="}uT^gKPy.r__jTDW@tye"><field name="NUM">1</field></shadow><block type="oh_get_zdt_part" id="MJ=s3o9zRWUwl3L478-%"><field name="temporalPart">getDayOfMonth</field><value name="zdt"><block type="oh_zdt_now" id="]gJ{KIp%t+llJE:Neh_z"></block></value></block></value><value name="B"><shadow type="math_number" id="9uwi/uaZ5-rxJEwn(Zg="><field name="NUM">1</field></shadow></value></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="Q7zR(dyrQ!pqzAIc8v?j"><mutation itemName="ElectricityMeter_energyUsageMonth" itemLabel="Energieverbrauch Monat"></mutation><field name="itemName">ElectricityMeter_energyUsageMonth</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="ElectricityMeter_energy180" itemLabel="Energie Gesamt"></mutation><field name="itemName">ElectricityMeter_energy180</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">rrd4j</field></block></value><value name="dayInfo"><block type="deibich:blockly:dateTime_zdt_set_time_with_fields" id="E4[}=fSeiaFbher(C?/e"><field name="HOURS">0</field><field name="MINUTES">0</field><field name="SECONDS">0</field><value name="DATE"><shadow type="oh_zdt" id="-YwB#{75n6x@v:LZ_wRf"><field name="day">2023-08-20</field></shadow><block type="oh_zdt_plusminus" id="#WP9ziro@OOi[)3xvs,|"><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="8i5+AXmgX#^-F89,Lu]X"><field name="OP">MINUS</field><value name="A"><shadow type="math_number" id="}uT^gKPy.r__jTDW@tye"><field name="NUM">1</field></shadow><block type="oh_get_zdt_part" id=".7VS+[H|NoEI$`bO;E=y"><field name="temporalPart">getDayOfYear</field><value name="zdt"><block type="oh_zdt_now" id="dJW)ytlA,R%lc9(0T+jy"></block></value></block></value><value name="B"><shadow type="math_number" id="Bi)-*(@7#0:8^dFK%PRR"><field name="NUM">1</field></shadow></value></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="n0#(pT9Uj$D.G9qpYSf@"><mutation itemName="ElectricityMeter_energyUsageYear" itemLabel="Energieverbrauch Jahr"></mutation><field name="itemName">ElectricityMeter_energyUsageYear</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="ElectricityMeter_energy180" itemLabel="Energie Gesamt"></mutation><field name="itemName">ElectricityMeter_energy180</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">rrd4j</field></block></value><value name="dayInfo"><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="ElectricityMeter_lastReading" itemLabel="Energieverbrauch Ablesedatum"></mutation><field name="itemName">ElectricityMeter_lastReading</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="ElectricityMeter_energyUsagePeriod" itemLabel="Energieverbrauch Periode"></mutation><field name="itemName">ElectricityMeter_energyUsagePeriod</field></block></value><next><block type="controls_if" id="/j*}b.(ZeI=_tC-otP[S"><value name="IF0"><block type="logic_compare" id="#;6wvoGsWi%+Q)QzCVL|"><field name="OP">EQ</field><value name="A"><block type="oh_zdt_toText" id="L)?pberGBJ,Dsg9V)gl("><field name="withtime">asOHTime</field><value name="date"><shadow type="oh_zdt" id=")eCC#^LvsN;S?Y8D~V+?"><field name="day">2023-09-03</field></shadow><block type="oh_zdt_now" id="._G]KdO|Xj,mb+;2@g#:"></block></value></block></value><value name="B"><block type="text" id="*(ZRhuuD{OCD3HTX=Xua"><field name="TEXT">00:00:00</field></block></value></block></value></block></next></block></next></block></next></block></next></block></next></block></xml>
      type: application/javascript
      script: >
        items.getItem('ElectricityMeter_energyUsageToday').postUpdate((items.getItem('ElectricityMeter_energy180').history.deltaSince(time.ZonedDateTime.now().withHour(0).withMinute(0).withSecond(0), 'rrd4j')));

        items.getItem('ElectricityMeter_energyUsageWeek').postUpdate((items.getItem('ElectricityMeter_energy180').history.deltaSince(time.ZonedDateTime.now().minusDays((((time.ZonedDateTime.now()).dayOfWeek().value()) - 1)).withHour(0).withMinute(0).withSecond(0), 'rrd4j')));

        items.getItem('ElectricityMeter_energyUsageMonth').postUpdate((items.getItem('ElectricityMeter_energy180').history.deltaSince(time.ZonedDateTime.now().minusDays((((time.ZonedDateTime.now()).dayOfMonth()) - 1)).withHour(0).withMinute(0).withSecond(0), 'rrd4j')));

        items.getItem('ElectricityMeter_energyUsageYear').postUpdate((items.getItem('ElectricityMeter_energy180').history.deltaSince(time.ZonedDateTime.now().minusDays((((time.ZonedDateTime.now()).dayOfYear()) - 1)).withHour(0).withMinute(0).withSecond(0), 'rrd4j')));

        items.getItem('ElectricityMeter_energyUsagePeriod').postUpdate((items.getItem('ElectricityMeter_energy180').history.deltaSince(time.toZDT(items.getItem('ElectricityMeter_lastReading').state), 'rrd4j')));

        if (((time.ZonedDateTime.now()).format(time.DateTimeFormatter.ofPattern('yyyy-MM-dd\'T\'HH:mm:ss.SSSZ'))) == '00:00:00') {

        }
    type: script.ScriptAction

You also need an Item holding the date wenn you new billing cycle started (ElectricityMeter_lastReading) !!!

Rules Code
configuration: {}
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="ElectricityMeter_energy180" itemLabel="Energie
        Gesamt"></mutation><field
        name="itemName">ElectricityMeter_energy180</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="dayInfo"><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="ElectricityMeter_energyUsageDaily" itemLabel="Energieverbrauch
        Täglich"></mutation><field
        name="itemName">ElectricityMeter_energyUsageDaily</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="ElectricityMeter_energy180" itemLabel="Energie
        Gesamt"></mutation><field
        name="itemName">ElectricityMeter_energy180</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="dayInfo"><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="ElectricityMeter_energyUsageWeekly"
        itemLabel="Energieverbrauch Wöchentlich"></mutation><field
        name="itemName">ElectricityMeter_energyUsageWeekly</field></block></value></block></statement><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="ElectricityMeter_energy180" itemLabel="Energie
        Gesamt"></mutation><field
        name="itemName">ElectricityMeter_energy180</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="dayInfo"><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="ElectricityMeter_energyUsageMonthly"
        itemLabel="Energieverbrauch Monatlich"></mutation><field
        name="itemName">ElectricityMeter_energyUsageMonthly</field></block></value></block></statement><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="ElectricityMeter_energy180" itemLabel="Energie
        Gesamt"></mutation><field
        name="itemName">ElectricityMeter_energy180</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="dayInfo"><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="ElectricityMeter_energyUsageYearly"
        itemLabel="Energieverbrauch Jährlich"></mutation><field
        name="itemName">ElectricityMeter_energyUsageYearly</field></block></value></block></statement></block></next></block></next></block></next></block></xml>
      type: application/javascript
      script: >
        items.getItem('ElectricityMeter_energyUsageDaily').postUpdate((items.getItem('ElectricityMeter_energy180').history.deltaSince(time.ZonedDateTime.now().minusDays(1),
        'rrd4j')));

        if (((time.ZonedDateTime.now()).dayOfWeek().value()) == 1) {
          items.getItem('ElectricityMeter_energyUsageWeekly').postUpdate((items.getItem('ElectricityMeter_energy180').history.deltaSince(time.ZonedDateTime.now().minusWeeks(1), 'rrd4j')));
        }

        if (((time.ZonedDateTime.now()).dayOfMonth()) == 1) {
          items.getItem('ElectricityMeter_energyUsageMonthly').postUpdate((items.getItem('ElectricityMeter_energy180').history.deltaSince(time.ZonedDateTime.now().minusMonths(1), 'rrd4j')));
        }

        if (((time.ZonedDateTime.now()).dayOfYear()) == 1) {
          items.getItem('ElectricityMeter_energyUsageYearly').postUpdate((items.getItem('ElectricityMeter_energy180').history.deltaSince(time.ZonedDateTime.now().minusYears(1), 'rrd4j')));
        }
    type: script.ScriptAction
2 Likes

Many thanks for the codes. I changed ElectricityMeter_energy180 to my own Item in both rules. I have following error messages in the OH4.0.3 log:

2023-11-04 07:28:48.665 [ERROR] [b.automation.script.javascript.stack] - Failed to execute script:
org.graalvm.polyglot.PolyglotException: SyntaxError: <eval>:3:6 Expected ; but found :
  - id: "1"
      ^
<eval>:9:10 Expected ; but found :
  - inputs: {}
          ^
<eval>:12:19 Expected an operand but found <
      blockSource: <xml xmlns="https://developers.google.com/blockly/xml"><block type="oh_event" id="wR2@!=5jfQG3|Tnh{+~x" x="-14" y="-145"><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="ABB_A43_imp_energy" itemLabel="Energie Gesamt"></mutation><field name="itemName">ABB_A43_imp_energy</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">rrd4j</field></block></value><value name="dayInfo"><block type="deibich:blockly:dateTime_zdt_set_time_with_fields" id="BXkQhKmnZ}Ye]N,[/KuW"><field name="HOURS">0</field><field name="MINUTES">0</field><field name="SECONDS">0</field><value name="DATE"><shadow type="oh_zdt" id="-YwB#{75n6x@v:LZ_wRf"><field name="day">2023-08-20</field></shadow><block type="oh_zdt_now" id="?M%+fG)$eQATRt1NyDX{"></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="ElectricityMeter_energyUsageToday" itemLabel="Energieverbrauch Heute"></mutation><field name="itemName">ElectricityMeter_energyUsageToday</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="ABB_A43_imp_energy" itemLabel="Energie Gesamt"></mutation><field name="itemName">ABB_A43_imp_energy</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">rrd4j</field></block></value><value name="dayInfo"><block type="deibich:blockly:dateTime_zdt_set_time_with_fields" id="H1?zJ%xWP(djG9331v=o"><field name="HOURS">0</field><field name="MINUTES">0</field><field name="SECONDS">0</field><value name="DATE"><shadow type="oh_zdt" id="-YwB#{75n6x@v:LZ_wRf"><field name="day">2023-08-20</field></shadow><block type="oh_zdt_plusminus" id="3CAJ%?j`%-`S(cs646d^"><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="-hadISd2nVwTrE0S+dqb"><field name="OP">MINUS</field><value name="A"><shadow type="math_number" id="}uT^gKPy.r__jTDW@tye"><field name="NUM">1</field></shadow><block type="oh_get_zdt_part" id="6D`|~dy77.lp8moxom7@"><field name="temporalPart">getDayOfWeek</field><value name="zdt"><block type="oh_zdt_now" id="?/[,lh[c8pq@]{#vNLIq"></block></value></block></value><value name="B"><shadow type="math_number" id="8-H0GA(SID)LfG)nFQ)x"><field name="NUM">1</field></shadow></value></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="U^2/Ta?7FbQCrVTT$/6:"><mutation itemName="ElectricityMeter_energyUsageWeek" itemLabel="Energieverbrauch Woche"></mutation><field name="itemName">ElectricityMeter_energyUsageWeek</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="ABB_A43_imp_energy" itemLabel="Energie Gesamt"></mutation><field name="itemName">ABB_A43_imp_energy</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">rrd4j</field></block></value><value name="dayInfo"><block type="deibich:blockly:dateTime_zdt_set_time_with_fields" id="Eu`Ge?Xs@@UdL=#r~vIp"><field name="HOURS">0</field><field name="MINUTES">0</field><field name="SECONDS">0</field><value name="DATE"><shadow type="oh_zdt" id="-YwB#{75n6x@v:LZ_wRf"><field name="day">2023-08-20</field></shadow><block type="oh_zdt_plusminus" id=".wyGf7(:ck4^fV]mPZ~I"><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="#Bag6+_vL=*lvOBmxxHm"><field name="OP">MINUS</field><value name="A"><shadow type="math_number" id="}uT^gKPy.r__jTDW@tye"><field name="NUM">1</field></shadow><block type="oh_get_zdt_part" id="MJ=s3o9zRWUwl3L478-%"><field name="temporalPart">getDayOfMonth</field><value name="zdt"><block type="oh_zdt_now" id="]gJ{KIp%t+llJE:Neh_z"></block></value></block></value><value name="B"><shadow type="math_number" id="9uwi/uaZ5-rxJEwn(Zg="><field name="NUM">1</field></shadow></value></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="Q7zR(dyrQ!pqzAIc8v?j"><mutation itemName="ElectricityMeter_energyUsageMonth" itemLabel="Energieverbrauch Monat"></mutation><field name="itemName">ElectricityMeter_energyUsageMonth</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="ABB_A43_imp_energy" itemLabel="Energie Gesamt"></mutation><field name="itemName">ABB_A43_imp_energy</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">rrd4j</field></block></value><value name="dayInfo"><block type="deibich:blockly:dateTime_zdt_set_time_with_fields" id="E4[}=fSeiaFbher(C?/e"><field name="HOURS">0</field><field name="MINUTES">0</field><field name="SECONDS">0</field><value name="DATE"><shadow type="oh_zdt" id="-YwB#{75n6x@v:LZ_wRf"><field name="day">2023-08-20</field></shadow><block type="oh_zdt_plusminus" id="#WP9ziro@OOi[)3xvs,|"><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="8i5+AXmgX#^-F89,Lu]X"><field name="OP">MINUS</field><value name="A"><shadow type="math_number" id="}uT^gKPy.r__jTDW@tye"><field name="NUM">1</field></shadow><block type="oh_get_zdt_part" id=".7VS+[H|NoEI$`bO;E=y"><field name="temporalPart">getDayOfYear</field><value name="zdt"><block type="oh_zdt_now" id="dJW)ytlA,R%lc9(0T+jy"></block></value></block></value><value name="B"><shadow type="math_number" id="Bi)-*(@7#0:8^dFK%PRR"><field name="NUM">1</field></shadow></value></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="n0#(pT9Uj$D.G9qpYSf@"><mutation itemName="ElectricityMeter_energyUsageYear" itemLabel="Energieverbrauch Jahr"></mutation><field name="itemName">ElectricityMeter_energyUsageYear</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="ABB_A43_imp_energy" itemLabel="Energie Gesamt"></mutation><field name="itemName">ABB_A43_imp_energy</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">rrd4j</field></block></value><value name="dayInfo"><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="ElectricityMeter_lastReading" itemLabel="Energieverbrauch Ablesedatum"></mutation><field name="itemName">ElectricityMeter_lastReading</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="ElectricityMeter_energyUsagePeriod" itemLabel="Energieverbrauch Periode"></mutation><field name="itemName">ElectricityMeter_energyUsagePeriod</field></block></value><next><block type="controls_if" id="/j*}b.(ZeI=_tC-otP[S"><value name="IF0"><block type="logic_compare" id="#;6wvoGsWi%+Q)QzCVL|"><field name="OP">EQ</field><value name="A"><block type="oh_zdt_toText" id="L)?pberGBJ,Dsg9V)gl("><field name="withtime">asOHTime</field><value name="date"><shadow type="oh_zdt" id=")eCC#^LvsN;S?Y8D~V+?"><field name="day">2023-09-03</field></shadow><block type="oh_zdt_now" id="._G]KdO|Xj,mb+;2@g#:"></block></value></block></value><value name="B"><block type="text" id="*(ZRhuuD{OCD3HTX=Xua"><field name="TEXT">00:00:00</field></block></value></block></value></block></next></block></next></block></next></block></next></block></next></block></xml>
                   ^
<eval>:14:14 Expected an operand but found >
      script: >
              ^

	at org.graalvm.polyglot.Context.eval(Context.java:399) ~[?:?]
	at com.oracle.truffle.js.scriptengine.GraalJSScriptEngine.eval(GraalJSScriptEngine.java:458) ~[?:?]
	at com.oracle.truffle.js.scriptengine.GraalJSScriptEngine.eval(GraalJSScriptEngine.java:426) ~[?:?]
	at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:262) ~[java.scripting:?]
	at org.openhab.automation.jsscripting.internal.scriptengine.DelegatingScriptEngineWithInvocableAndAutocloseable.eval(DelegatingScriptEngineWithInvocableAndAutocloseable.java:53) ~[?:?]
	at org.openhab.automation.jsscripting.internal.scriptengine.InvocationInterceptingScriptEngineWithInvocableAndAutoCloseable.eval(InvocationInterceptingScriptEngineWithInvocableAndAutoCloseable.java:78) ~[?:?]
	at org.openhab.automation.jsscripting.internal.scriptengine.DelegatingScriptEngineWithInvocableAndAutocloseable.eval(DelegatingScriptEngineWithInvocableAndAutocloseable.java:53) ~[?:?]
	at org.openhab.automation.jsscripting.internal.scriptengine.InvocationInterceptingScriptEngineWithInvocableAndAutoCloseable.eval(InvocationInterceptingScriptEngineWithInvocableAndAutoCloseable.java:78) ~[?:?]
	at org.openhab.core.automation.module.script.internal.handler.ScriptActionHandler.lambda$0(ScriptActionHandler.java:71) ~[?:?]
	at java.util.Optional.ifPresent(Optional.java:178) ~[?:?]
	at org.openhab.core.automation.module.script.internal.handler.ScriptActionHandler.execute(ScriptActionHandler.java:68) ~[?:?]
	at org.openhab.core.automation.internal.RuleEngineImpl.executeActions(RuleEngineImpl.java:1188) ~[?:?]
	at org.openhab.core.automation.internal.RuleEngineImpl.runRule(RuleEngineImpl.java:997) ~[?:?]
	at org.openhab.core.automation.internal.TriggerHandlerCallbackImpl$TriggerData.run(TriggerHandlerCallbackImpl.java:87) ~[?:?]
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539) ~[?:?]
	at java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[?:?]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304) ~[?:?]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) ~[?:?]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) ~[?:?]
	at java.lang.Thread.run(Thread.java:833) ~[?:?]

So it seems that I’m missing something. Do I need to change e.g. in line

items.getItem('ElectricityMeter_energyUsageToday').postUpdate((items.getItem('ElectricityMeter_energy180').history.deltaSince(time.ZonedDateTime.now().withHour(0).withMinute(0).withSecond(0), 'rrd4j')));

ElectricityMeter_energyUsageToday to something else?

Did you change the persistence service ?
Forgot to mention that, will update original post.

Thanks for the widget! It’s really great! :grinning:
How do you actually get the energy data. I think you use the Smartmeter binding. Do you read the SML data over the serial port every 3s. Can Openhab handle this amount of data?

I have a Tasmota WiFi reader attached to my smartmeter which post every change over MQTT. Frequency of updates is less than every 3 seconds, so yes, openHAB can handle this amount of information.

Yes, I have correct persistence. I think my problem is due to a wrong syntax. I have Javascript installed and I copied your codes to the Rule editor. When I open the script it shows ECMAScript. Is this correct?

Please see here

Sorry, did not see this on my phone. Of course, All Items need to be changed to the equivalent Items in your installation. You still try to use „my“ items, which your openHAB cannot find.

OK, many thanks. So, there are quite many things which I need to change and I want to get this widget working.

1 Like

The widget itself can be configured through the UI. You need to change the Rules to your config.

I have configured the widget through the UI and edited the rules but I think there are some syntax problems still:

2023-11-04 13:30:23.852 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'ABB_A43_status' failed: org.graalvm.polyglot.PolyglotException: SyntaxError: <eval>:3:6 Expected ; but found :
  - id: "1"
      ^
<eval>:9:10 Expected ; but found :
  - inputs: null
          ^
<eval>:12:19 Expected an operand but found <

Hmm, strange. I will try to convert it to a rule template tonight and post an update. You then can install the rule from the addon store and configure it via UI.

Could you please go to the code tab of your rule and post your content, so I can compare it with mine.

BTW, what openHAB version do you use?

This is the Rule I’m using:

configuration: {}
triggers:
  - id: "1"
    configuration:
      itemName: ABB_A43_imp_energy
    type: core.ItemStateUpdateTrigger
conditions: []
actions:
  - inputs: {}
    id: "2"
    configuration:
      type: application/javascript
      script: >-
        configuration: {}

        triggers:
          - id: "1"
            configuration:
              itemName: ABB_A43_imp_energy
            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="-14" y="-145"><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="ABB_A43_imp_energy" itemLabel="Energie Gesamt"></mutation><field name="itemName">ABB_A43_imp_energy</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">rrd4j</field></block></value><value name="dayInfo"><block type="deibich:blockly:dateTime_zdt_set_time_with_fields" id="BXkQhKmnZ}Ye]N,[/KuW"><field name="HOURS">0</field><field name="MINUTES">0</field><field name="SECONDS">0</field><value name="DATE"><shadow type="oh_zdt" id="-YwB#{75n6x@v:LZ_wRf"><field name="day">2023-08-20</field></shadow><block type="oh_zdt_now" id="?M%+fG)$eQATRt1NyDX{"></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="ElectricityMeter_energyUsageToday" itemLabel="Energieverbrauch Heute"></mutation><field name="itemName">ElectricityMeter_energyUsageToday</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="ABB_A43_imp_energy" itemLabel="Energie Gesamt"></mutation><field name="itemName">ABB_A43_imp_energy</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">rrd4j</field></block></value><value name="dayInfo"><block type="deibich:blockly:dateTime_zdt_set_time_with_fields" id="H1?zJ%xWP(djG9331v=o"><field name="HOURS">0</field><field name="MINUTES">0</field><field name="SECONDS">0</field><value name="DATE"><shadow type="oh_zdt" id="-YwB#{75n6x@v:LZ_wRf"><field name="day">2023-08-20</field></shadow><block type="oh_zdt_plusminus" id="3CAJ%?j`%-`S(cs646d^"><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="-hadISd2nVwTrE0S+dqb"><field name="OP">MINUS</field><value name="A"><shadow type="math_number" id="}uT^gKPy.r__jTDW@tye"><field name="NUM">1</field></shadow><block type="oh_get_zdt_part" id="6D`|~dy77.lp8moxom7@"><field name="temporalPart">getDayOfWeek</field><value name="zdt"><block type="oh_zdt_now" id="?/[,lh[c8pq@]{#vNLIq"></block></value></block></value><value name="B"><shadow type="math_number" id="8-H0GA(SID)LfG)nFQ)x"><field name="NUM">1</field></shadow></value></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="U^2/Ta?7FbQCrVTT$/6:"><mutation itemName="ElectricityMeter_energyUsageWeek" itemLabel="Energieverbrauch Woche"></mutation><field name="itemName">ElectricityMeter_energyUsageWeek</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="ABB_A43_imp_energy" itemLabel="Energie Gesamt"></mutation><field name="itemName">ABB_A43_imp_energy</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">rrd4j</field></block></value><value name="dayInfo"><block type="deibich:blockly:dateTime_zdt_set_time_with_fields" id="Eu`Ge?Xs@@UdL=#r~vIp"><field name="HOURS">0</field><field name="MINUTES">0</field><field name="SECONDS">0</field><value name="DATE"><shadow type="oh_zdt" id="-YwB#{75n6x@v:LZ_wRf"><field name="day">2023-08-20</field></shadow><block type="oh_zdt_plusminus" id=".wyGf7(:ck4^fV]mPZ~I"><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="#Bag6+_vL=*lvOBmxxHm"><field name="OP">MINUS</field><value name="A"><shadow type="math_number" id="}uT^gKPy.r__jTDW@tye"><field name="NUM">1</field></shadow><block type="oh_get_zdt_part" id="MJ=s3o9zRWUwl3L478-%"><field name="temporalPart">getDayOfMonth</field><value name="zdt"><block type="oh_zdt_now" id="]gJ{KIp%t+llJE:Neh_z"></block></value></block></value><value name="B"><shadow type="math_number" id="9uwi/uaZ5-rxJEwn(Zg="><field name="NUM">1</field></shadow></value></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="Q7zR(dyrQ!pqzAIc8v?j"><mutation itemName="ElectricityMeter_energyUsageMonth" itemLabel="Energieverbrauch Monat"></mutation><field name="itemName">ElectricityMeter_energyUsageMonth</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="ABB_A43_imp_energy" itemLabel="Energie Gesamt"></mutation><field name="itemName">ABB_A43_imp_energy</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">rrd4j</field></block></value><value name="dayInfo"><block type="deibich:blockly:dateTime_zdt_set_time_with_fields" id="E4[}=fSeiaFbher(C?/e"><field name="HOURS">0</field><field name="MINUTES">0</field><field name="SECONDS">0</field><value name="DATE"><shadow type="oh_zdt" id="-YwB#{75n6x@v:LZ_wRf"><field name="day">2023-08-20</field></shadow><block type="oh_zdt_plusminus" id="#WP9ziro@OOi[)3xvs,|"><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="8i5+AXmgX#^-F89,Lu]X"><field name="OP">MINUS</field><value name="A"><shadow type="math_number" id="}uT^gKPy.r__jTDW@tye"><field name="NUM">1</field></shadow><block type="oh_get_zdt_part" id=".7VS+[H|NoEI$`bO;E=y"><field name="temporalPart">getDayOfYear</field><value name="zdt"><block type="oh_zdt_now" id="dJW)ytlA,R%lc9(0T+jy"></block></value></block></value><value name="B"><shadow type="math_number" id="Bi)-*(@7#0:8^dFK%PRR"><field name="NUM">1</field></shadow></value></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="n0#(pT9Uj$D.G9qpYSf@"><mutation itemName="ElectricityMeter_energyUsageYear" itemLabel="Energieverbrauch Jahr"></mutation><field name="itemName">ElectricityMeter_energyUsageYear</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="ABB_A43_imp_energy" itemLabel="Energie Gesamt"></mutation><field name="itemName">ABB_A43_imp_energy</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">rrd4j</field></block></value><value name="dayInfo"><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="ElectricityMeter_lastReading" itemLabel="Energieverbrauch Ablesedatum"></mutation><field name="itemName">ElectricityMeter_lastReading</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="ElectricityMeter_energyUsagePeriod" itemLabel="Energieverbrauch Periode"></mutation><field name="itemName">ElectricityMeter_energyUsagePeriod</field></block></value><next><block type="controls_if" id="/j*}b.(ZeI=_tC-otP[S"><value name="IF0"><block type="logic_compare" id="#;6wvoGsWi%+Q)QzCVL|"><field name="OP">EQ</field><value name="A"><block type="oh_zdt_toText" id="L)?pberGBJ,Dsg9V)gl("><field name="withtime">asOHTime</field><value name="date"><shadow type="oh_zdt" id=")eCC#^LvsN;S?Y8D~V+?"><field name="day">2023-09-03</field></shadow><block type="oh_zdt_now" id="._G]KdO|Xj,mb+;2@g#:"></block></value></block></value><value name="B"><block type="text" id="*(ZRhuuD{OCD3HTX=Xua"><field name="TEXT">00:00:00</field></block></value></block></value></block></next></block></next></block></next></block></next></block></next></block></xml>
              type: application/javascript
              script: >
                items.getItem('ABB_A43_energy_consumption_today').postUpdate((items.getItem('ABB_A43_imp_energy').history.deltaSince(time.ZonedDateTime.now().withHour(0).withMinute(0).withSecond(0), 'rrd4j')));

                items.getItem('ABB_A43_energy_consumption_actual_week').postUpdate((items.getItem('ABB_A43_imp_energy').history.deltaSince(time.ZonedDateTime.now().minusDays((((time.ZonedDateTime.now()).dayOfWeek().value()) - 1)).withHour(0).withMinute(0).withSecond(0), 'rrd4j')));

                items.getItem('ABB_A43_energy_consumption_actual_month').postUpdate((items.getItem('ABB_A43_imp_energy').history.deltaSince(time.ZonedDateTime.now().minusDays((((time.ZonedDateTime.now()).dayOfMonth()) - 1)).withHour(0).withMinute(0).withSecond(0), 'rrd4j')));

                items.getItem('ABB_A43_energy_consumption_actual_year').postUpdate((items.getItem('ABB_A43_imp_energy').history.deltaSince(time.ZonedDateTime.now().minusDays((((time.ZonedDateTime.now()).dayOfYear()) - 1)).withHour(0).withMinute(0).withSecond(0), 'rrd4j')));

                items.getItem('ABB_A43_energyUsagePeriod').postUpdate((items.getItem('ABB_A43_imp_energy').history.deltaSince(time.toZDT(items.getItem('ABB_A43_lastReading').state), 'rrd4j')));

                if (((time.ZonedDateTime.now()).format(time.DateTimeFormatter.ofPattern('yyyy-MM-dd\'T\'HH:mm:ss.SSSZ'))) == '00:00:00') {

                }
            type: script.ScriptAction
    type: script.ScriptAction

I’m running OH4.0.3 and using JavaScript Scripting.