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

Use Quantity types for historic state functions. #281

Closed
mherwege opened this issue Jul 27, 2023 · 3 comments
Closed

Use Quantity types for historic state functions. #281

mherwege opened this issue Jul 27, 2023 · 3 comments
Labels
enhancement New feature or request ohc / addon Needs to be fixed in openHAB Core or JS Scripting addon

Comments

@mherwege
Copy link
Contributor

I have following code (generated by Blockly, but that is not relevant in the context):

updateTime = items.getItem('PVEtotalGS1').history.lastUpdate( 'influxdb').plusMinutes(1);
prevTotalGS1 = items.getItem('PVEtotalGS1').history.historicState(updateTime, 'influxdb')?.state;
deltaGS2 = String(items.getItem('PVEtotalGS2').history.deltaSince(updateTime, 'influxdb')) + ' kWh';
totalGS1 = (Quantity(prevTotalGS1).add(Quantity(deltaGS2).multiply(Quantity(cache.shared.get('GS_RATIO')))));

PVETotalGS1 and PVETotalGS2 are both Number:Energy items.

for history.historicState a state is returned, which can then be used for Quantity calculations in line 4. history.deltaSince return a numeric (not a QuantityType), so I had to explicitely attach the unit. To be consistent, it would be more logical to return a Quantity Type instead for this function as well.

The same argument would apply to other history functions.

@mherwege mherwege added the enhancement New feature or request label Jul 27, 2023
@florian-h05
Copy link
Contributor

We only can return a Quantity or provide the unit, if openHAB core provides it, but it currently does not, see https://www.openhab.org/javadoc/latest/org/openhab/core/persistence/extensions/persistenceextensions.

@florian-h05 florian-h05 added the ohc / addon Needs to be fixed in openHAB Core or JS Scripting addon label Jul 27, 2023
@mherwege
Copy link
Contributor Author

Indeed. I will open a core issue.

@mherwege
Copy link
Contributor Author

Solved with #331

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request ohc / addon Needs to be fixed in openHAB Core or JS Scripting addon
Projects
None yet
Development

No branches or pull requests

2 participants