One more thing, I told earlier that we have the netting system in Finland and I have the hourly netted values (in kWh). In the Blockly you are calculating delta values but my netted values are already delta values so I guess I would need to calculate a sum in order to calculate daily/weekly/monthly values.
Found the bug within setting a wrong persistence service for the billing cycle value.
I think that does not matter.
The rules use the raw meter counter values and calculate the appropriate delta values. Nothing would need to be changed.
Edit: Might be that I doe not understand correct what you mean with netted values.
E.g. my meter delivers the usage value and, if I would have solar panels, production values at a different data point.
I am using the usage values from the meter.
The netted value is deducted from hourly consumption so the imported energy on my energy meter is not the actual value my electricity provider charges me. Somewhat difficult to explain so I need to make some tests with the netted values.
I have made some progress. I had wrong Item for the Consumption yesterday which was never populated. Now Consumption yesterday works.
Hmm. I’m not sure why my version isn’t working but your version is better anyway. I don’t use Blockly all the time so usually I just put together the blocks, scan the JS it produces and call it a day. I really should test it where I can.
@hmerk Can you please post the latest code or is the code updated in the first post? I was not able to see the code over the Martket Place, is this even possible.
Is there actually somthing like a Blockly to DSL converter, as I would need DSL code
Click save or hit ctrl-s to save the new rule based on the template.
Repeat 4-6 for Historical Energy Consumption.
Rule templates are a huge improvement over sharing blocks of code that end users need to copy/paste/edit to get working for both the developers and the end users. For example, as an end user you don’t even need to type in the names of the Items. You can select them from a list.
Just to elaborate, a rule created from a template is a rule like any other. It can be viewed and changed like any other UI created rule.
I don’t have the Items to generate @hmerk’s rules yet but I do have a bunch of others. Here’s what a rule created from my Delay Start [4.0.0.0;4.9.9.9] template looks like once I’ve created the rule:
Note I use pure JS Scripting. You’ll see Blockly if you click on the script action to edit it.
The whole rule in the code tab:
configuration:
pause: ""
rules:
- humidity_low_detect
- thing_status
triggers:
- id: "1"
configuration:
startlevel: 40
type: core.SystemStartlevelTrigger
- id: "2"
configuration:
startlevel: 70
type: core.SystemStartlevelTrigger
conditions: []
actions:
- inputs: {}
id: "3"
configuration:
type: application/javascript
script: >-
var {helpers} = require('openhab_rules_tools');
console.loggerName = 'org.openhab.automation.rules_tools.Delayed Start';
//osgi.getService('org.apache.karaf.log.core.LogService').setLevel(console.loggerName, 'DEBUG');
helpers.validateLibraries('4.1.0', '2.0.1');
// Properties
var disabledRules = '[hum-low-detect, sensor-status-detection, service-status-detectio, thing_status]'.replace('[','').replace(']', '').split(', ');
var delay = 'PT1M30S';
// First time the rule is called at runlevel 40 the flag will be initialized to false
var alreadyCalled = cache.private.get('flag', () => false);
var timerTime = (alreadyCalled) ? delay : 0; // run immediately the first run of the rule
var activity = (alreadyCalled) ? 'enabling' : 'disabling';
var when = (alreadyCalled) ? 'after ' + delay : 'immediately';
console.info('Delayed Start triggered, ' + activity + ' rules ' + when);
helpers.createTimer(timerTime, () => disabledRules.forEach(rule => {
console.info(activity, rule);
try {
rules.setEnabled(rule, alreadyCalled);
}
catch(e) {
console.error('Failed to enable/disable rule ' + rule + ': ' + e);
}
}), 'delayedStart');
cache.private.put('flag', true);
type: script.ScriptAction
Except for the configuration block at the top, this rule is indistinguishable from a rule created by hand in every meaningful way. The template gives you a complete rule and what you do with the rule once it’s created is up to you.
You haven’t filled in the Template Configuration. Both “Rules” is requires property. It won’t create the rule without all required properties filled in.
It should generate an error though instead of creating an empty rule. That’s a bug that needs to be filed.
In the mean time, make sure to fill in all the required properties for any rule you create from a template.
itemEnergyToday.postUpdate(itemEnergyReading.deltaSince(now.withHour(0).withMinute(0).withSecond(0), "jdbc") as Number)
itemEnergyThisWeek.postUpdate(itemEnergyReading.deltaSince(now.minusDays(now.dayOfWeek.getValue - 1).withHour(0).withMinute(0).withSecond(0), "jdbc") as Number)
itemEnergyThisMonth.postUpdate(itemEnergyReading.deltaSince(now.withDayOfMonth(1).withHour(0).withMinute(0).withSecond(0), "jdbc")as Number)
itemEnergyThisYear.postUpdate(itemEnergyReading.deltaSince(now.withMonth(1).withDayOfMonth(1).withHour(0).withMinute(0).withSecond(0), "jdbc") as Number)
Historical, but I have used deltaBetween().
itemEnergyYesterday.postUpdate(itemEnergyReading.deltaBetween(now.minusDays(1).withHour(0).withMinute(0).withSecond(0),now.withHour(0).withMinute(0).withSecond(0), "jdbc") as Number)
itemEnergyLastWeek.postUpdate(itemEnergyReading.deltaBetween(now.minusDays(now.dayOfWeek.getValue - 1).minusWeeks(1).withHour(0).withMinute(0).withSecond(0),now.minusDays(now.dayOfWeek.getValue - 1).withHour(0).withMinute(0).withSecond(0), "jdbc") as Number)
itemEnergyLastMonth.postUpdate(itemEnergyReading.deltaBetween(now.minusMonths(1).withDayOfMonth(1).withHour(0).withMinute(0).withSecond(0),now.withDayOfMonth(1).withHour(0).withMinute(0).withSecond(0), "jdbc") as Number)
itemEnergyLastYear.postUpdate(itemEnergyReading.deltaBetween(now.minusYears(1).withMonth(1).withDayOfMonth(1).withHour(0).withMinute(0).withSecond(0),now.withMonth(1).withDayOfMonth(1).withHour(0).withMinute(0).withSecond(0), "jdbc") as Number)
The only issue what have found is, that if you want to have ThisYear/LastYear data you also have to have energy readings in January.