Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Persisted group items with base type Number:Dimension not restored correctly in persistence extensions #4254

Closed
mherwege opened this issue May 28, 2024 · 3 comments · Fixed by #4257
Labels
bug An unexpected problem or unintended behavior of the Core

Comments

@mherwege
Copy link
Contributor

mherwege commented May 28, 2024

I have a rule retrieving data from persistence and doing calculations in it. I was able to isolate it and here is a js rule (with a working and failing example), and the result in the log:

var lastUpdate = time.toZDT('2024-01-01 00:00:00')
console.info('last update: ' + lastUpdate);
console.info('EVMeterstand state: ' + items.getItem('EVMeterstand')?.state);
console.info('EVMeterstand numeric state: ' + items.getItem('EVMeterstand')?.numericState);
console.info('EVMeterstand historic state: ' + items.getItem('EVMeterstand').persistence.persistedState(lastUpdate, 'influxdb')?.state);
console.info('EVMeterstand numeric historic state: ' + items.getItem('EVMeterstand').persistence.persistedState(lastUpdate, 'influxdb')?.numericState);
console.info('EVMeterstand delta calculated: ' + (Quantity(items.getItem('EVMeterstand')?.state).subtract(Quantity(items.getItem('EVMeterstand').persistence.persistedState(lastUpdate, 'influxdb')?.state))));
console.info('EVMeterstand numeric delta calculated: ' + (items.getItem('EVMeterstand')?.numericState - items.getItem('EVMeterstand').persistence.persistedState(lastUpdate, 'influxdb')?.numericState));
console.info('EVMeterstand delta: ' + items.getItem('EVMeterstand').persistence.deltaSince(lastUpdate, 'influxdb')?.state);
console.info('EVMeterstand numeric delta: ' + items.getItem('EVMeterstand').persistence.deltaSince(lastUpdate, 'influxdb')?.numericState);
console.info('PVEmeter state: ' + items.getItem('PVEmeter')?.state);
console.info('PVEmeter numeric state: ' + items.getItem('PVEmeter')?.numericState);
console.info('PVEmeter historic state: ' + items.getItem('PVEmeter').persistence.persistedState(lastUpdate, 'influxdb')?.state);
console.info('PVEmeter numeric historic state: ' + items.getItem('PVEmeter').persistence.persistedState(lastUpdate, 'influxdb')?.numericState);
console.info('PVEmeter delta calculated: ' + (Quantity(items.getItem('PVEmeter')?.state).subtract(Quantity(items.getItem('PVEmeter').persistence.persistedState(lastUpdate, 'influxdb')?.state))));
console.info('PVEmeter numeric delta calculated: ' + (items.getItem('PVEmeter')?.numericState - items.getItem('PVEmeter').persistence.persistedState(lastUpdate, 'influxdb')?.numericState));
console.info('PVEmeter delta: ' + items.getItem('PVEmeter').persistence.deltaSince(lastUpdate, 'influxdb')?.state);
console.info('PVEmeter numetric delta: ' + items.getItem('PVEmeter').persistence.deltaSince(lastUpdate, 'influxdb')?.numericState);

Output:

==> /var/log/openhab/openhab.log <==
2024-05-28 17:05:16.005 [INFO ] [nhab.automation.script.ui.scratchpad] - last update: 2024-01-01T00:00+01:00[SYSTEM]
2024-05-28 17:05:16.007 [INFO ] [nhab.automation.script.ui.scratchpad] - EVMeterstand state: 5810.069 kWh
2024-05-28 17:05:16.009 [INFO ] [nhab.automation.script.ui.scratchpad] - EVMeterstand numeric state: 5810.069
2024-05-28 17:05:16.029 [INFO ] [nhab.automation.script.ui.scratchpad] - EVMeterstand historic state: 3907.714 kWh
2024-05-28 17:05:16.050 [INFO ] [nhab.automation.script.ui.scratchpad] - EVMeterstand numeric historic state: 3907.714
2024-05-28 17:05:16.070 [INFO ] [nhab.automation.script.ui.scratchpad] - EVMeterstand delta calculated: 1902.355 kWh
2024-05-28 17:05:16.091 [INFO ] [nhab.automation.script.ui.scratchpad] - EVMeterstand numeric delta calculated: 1902.3550000000005
2024-05-28 17:05:16.112 [INFO ] [nhab.automation.script.ui.scratchpad] - EVMeterstand delta: 1902.355 kWh
2024-05-28 17:05:16.132 [INFO ] [nhab.automation.script.ui.scratchpad] - EVMeterstand numeric delta: 1902.355
2024-05-28 17:05:16.133 [INFO ] [nhab.automation.script.ui.scratchpad] - PVEmeter state: 83936.139597840010000000000000000006714891167827200800000 kWh
2024-05-28 17:05:16.135 [INFO ] [nhab.automation.script.ui.scratchpad] - PVEmeter numeric state: 83936.13959784001
2024-05-28 17:05:16.213 [INFO ] [nhab.automation.script.ui.scratchpad] - PVEmeter historic state: 82105.31879144 kWh
2024-05-28 17:05:16.288 [INFO ] [nhab.automation.script.ui.scratchpad] - PVEmeter numeric historic state: 82105.31879144
2024-05-28 17:05:16.383 [INFO ] [nhab.automation.script.ui.scratchpad] - PVEmeter delta calculated: 1830.820806400010000000000000000000146465664512000800000 kWh
2024-05-28 17:05:16.459 [INFO ] [nhab.automation.script.ui.scratchpad] - PVEmeter numeric delta calculated: 1830.8208064000064
2024-05-28 17:05:16.541 [INFO ] [nhab.automation.script.ui.scratchpad] - PVEmeter delta: undefined
2024-05-28 17:05:16.628 [INFO ] [nhab.automation.script.ui.scratchpad] - PVEmeter numetric delta: undefined

Notice the js deltaSince call fails in the second example. The only reasonable explanation I have is that PVEmeter has too many positions and the calculation fails in the persistence extension.
There may be an error introduced with #3736. I worked through the code and I don't see an obvious reason there.
But I am also wondering if #4198 could have something to do with it.

This is on my production system, and I have not been able so far to replicate this in a development environment.

@mherwege mherwege added the bug An unexpected problem or unintended behavior of the Core label May 28, 2024
@mherwege mherwege changed the title BigDecimal with too many position breaks calculations in rule BigDecimal with too many position breaks persistence extension call May 28, 2024
@mherwege
Copy link
Contributor Author

mherwege commented May 29, 2024

I got a little bit further in my analysis. I converted the above rules to DSL to exclude the potential impact of javascript. I see exactly the same behaviour of the deltaSince calculation returning null.
I still don't have a clue why that happens and have not been able to reproduce in my development environment.

@mherwege
Copy link
Contributor Author

mherwege commented May 29, 2024

I wrote a specific test for this in the persistenceExtension, putting exactly the values I have in this failure in the test. The test passes without problem.
The only difference I can now see RPi vs Windows. I run my live system on an RPi4 with openhabian, 32-bit. Development is on Windows.
I can reproduce the issue on the RPi both with javascripting and rules DSL. I cannot reproduce it on my Windows development system.

@mherwege
Copy link
Contributor Author

I found the problem.

Persistence extension have an issue with GroupItems and QuantityTypes. A persisted GroupItem will not return the persisted value.

I am creating a fix.

@mherwege mherwege changed the title BigDecimal with too many position breaks persistence extension call Persisted group items with base type Number:Dimension not restored correctly in persistence extensions May 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An unexpected problem or unintended behavior of the Core
Projects
None yet
1 participant