Energy Card

OK, thanks.

It seems that I still get the same error messages in the OH log for both rules and I don’t see the Blockly blocks in the Actual energy consumption rule. At first I deleted both rules, uninstalled the Marketplace add-ons and restarted OH. I then installed both add-on from the marketplace and created new rules. Somehow it seems that the add-ons were not perhaps updated when I tried to recreate new rules.

I saw earlier that you configured rrd4j as persistence, but always asked if influxDB would be supported.
If you use influxDB, please configure persistence to „default“ and try again.
When you uninstall the template through addon store and reinstall add them again, the latest version gets pulled from the marketplace, so you have the actual ones.

@rlkoshak do you have an idea what could be wrong ?
If I add both templates from the marketplace, I can add new rules from them and they are working fine….

Nice card. Just to share how some HA folks are approaching this

Besides KW consumption there’s also cost calculation.

Perhaps I wasn’t quite clear. I use rrd4j as a default service and I persist manually some Items to influxDB.

It seems that the history rule works now (after deleting the rule and add-on) but I still get an error message for the Daily usage rule:

2023-11-06 14:48:33.558 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID '9c3fb9bcb7' failed: org.graalvm.polyglot.PolyglotException: SyntaxError: <eval>:6:0 Expected eof but found }
}
^

I don’t see the Blockly blocks either.

Could be a missing dependeny still.
please install this blockly extension

That did the trick. Now I can see the Blockly blocks in the Edit script page. Many thanks for your help.

1 Like

Thanks for your feedback and sorry for the inconvenience.
I am new to rule templates, that’s why I forget about the dependency…
I will update the template post so that nobody else falls into that trap…

Edit: done
@rlkoshak We solved it :wink:

You are referring to both Actual energy consumption [4.0.0.0;4.9.9.9] and Historical energy consumption [4.0.0.0;4.9.9.9], correct?

I can install them without error.

Looking at the historical rule it looks reasonable.

I don’t have all these Items so I can’t create an instance of the rule that makes sense in my system right now (I do have an energy meter so stay tuned) but looking at the JS code in the template the only thing that stands out is that first line doesn’t actually do anything:

items.getItem('{{energyUseageDaily}}').postUpdate((items.getItem('{{energyCounter}}').history.deltaSince(time.ZonedDateTime.now().minusDays(1), '{{persistenceService}}')));

It pulls the deltaSince but doesn’t save it to a variable so it’s kind of a noop.

But the rest of the rule looks OK so it should be fine as written.

The actual energy rule might have a problem. The last line of the script action seems to have an unmatched closing }. But it’s not entirely clear that’s really the case and how that happened at all using Blockly in the first place.

I see that you got it to work so that } is a mystery.

Note that in OH 4 most of those blocks are now implemented by the base Blockly under the Dates and Times category. The blocks are implemented slightly differently but if you used those users of your templates wouldn’t need to install the separate library.

Thanks for your feedback.
I tried to get rid of that dependency, but could not find the correct block. Can you please point me to which one you are referring to ?

No, it updates the daily usage Item….

@rlkoshak

Found it, will change the template tonight….

You are right. It’s early here, need more coffee.

midnight today:

The temporal stuff is a little tricky. See https://www.youtube.com/watch?v=KwhYKy1_qVk&t=375s.

The now.minus days of the week is a little tricky in that you’ll have to make two “copies”.

Day of month and day or year follow the same pattern. Just change the property in that block as appropriate.

I’m just way behind. :wink: Gotta love these almost in time replies. :smiley:

1 Like

Thank’s Rich, but this one is not working.

2023-11-06 23:18:57.752 [ERROR] [b.automation.script.javascript.stack] - Failed to execute script:
org.graalvm.polyglot.PolyglotException: TypeError: Cannot read property "value" from undefined
	at <js>.:program(<eval>:4) ~[?:?]
	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) [bundleFile:?]
	at org.openhab.core.automation.internal.RuleEngineImpl.executeActions(RuleEngineImpl.java:1188) [bundleFile:?]
	at org.openhab.core.automation.internal.RuleEngineImpl.runRule(RuleEngineImpl.java:997) [bundleFile:?]
	at org.openhab.core.automation.internal.TriggerHandlerCallbackImpl$TriggerData.run(TriggerHandlerCallbackImpl.java:87) [bundleFile:?]
	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) [?:?]
2023-11-06 23:18:57.757 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'energyUsageActual' failed: org.graalvm.polyglot.PolyglotException: TypeError: Cannot read property "value" from undefined

Start of Month and Year are working with the following

Edit : Got it working, it is easier than I thought :wink:

1 Like

@STSC @nikos7179 @jlikonen
I have updated the marketplace templace to remove the external dependency, please try the new version.

@rlkoshak Thanks Rich for your excellent help !!!

I updated the marketplace templates and both Edit script pages show the Blockly block. I have a small glitch, though. Some of the Items show “NULL” (see the screencopy) and this has been the case since I installed the widget.

Näyttökuva 2023-11-07 063025

I checked that e.g. the Item for Consumption Actual Month is “NULL”.

This is really nice widget and I’m going to adapt it to my other purposes.

Please note that the weekly/monthly/yearly Items get updated only at the first of a week/month/year, so you won’t see any values until then.
Your missing billing cycle value looks like a bug/issue. Anything in the logs? Did you set the DateTime Item correct?

This is a really simple but informative widget, I have modified it for my gas- and watermeter to have them shown with the same look and feel…

OK, thanks. I understand that to get the monthly/yearly values I need to wait until next month/year but Yesterday’s value is also null.

My Item for billing cycle start is 2023-01-01T00:00:00.000+0200. So I wonder whether this is wrong.

Do you have a meter value from that day and time ? If not, no delta can be calculated…

Yes, I have a energy meter reading for that date/time. There are no error/warning messages in the log. I think I need to look at your code and see how the billing cycle is handled.