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

New price calc #27

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions admin/index_m.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<html>

<head>

<meta charset="UTF-8">
<!-- Load ioBroker scripts and styles-->
<link rel="stylesheet" type="text/css" href="../../css/adapter.css" />
<link rel="stylesheet" type="text/css" href="../../lib/css/materialize.css">
Expand Down Expand Up @@ -67,7 +67,16 @@

<div class="row">
<div class="col s12 m4 l2">
<img src="awattar.png" class="logo">
<img src="awattar.png" class="logo"><br/><br/>
<b>ATTENTION:</b> the domain names matter!<br/>
e.g. <code>https://api.awattar<strong>.de</strong></code> and <code>https://api.awattar<strong>.at</strong></code> return different values!<br/><br/>
Formula for <code>net costs = marketvalue</code> (value from API)<br/>
Formula for <code>net full costs = (net costs + ( abs(net costs) * F ) + C )</code><br/>
Formula for <code>gross costs = ( net full costs ) * VAT</code><br/>
Formula for <code>total costs = gross costs + EXTRA</code><br/><br/>
Full formula:<br/>
<strong><code>total costs = (net costs + ( abs(net costs) * F ) + C ) * VAT + EXTRA</code></strong> <br/><br/>
Just set "F" or "C" to 0 if this is not part of your contract!
</div>
</div>
<div class="row">
Expand All @@ -94,10 +103,22 @@
<label for="MWstRate" class="translate">actual VAT rate (percent)</label>
</div>
</div>
<div class="row">
<div class="col s6 input-field">
<input type="text" class="value" id="absPriceFactor" />
<label for="absPriceFactor" class="translate">Factor (F) of the absolute value of the market price to be added to total price.</label>
</div>
</div>
<div class="row">
<div class="col s6 input-field">
<input type="text" class="value" id="constantCosts" />
<label for="constantCosts" class="translate">Constant (C) costs added per kWh (before VAT).</label>
</div>
</div>
<div class="row">
<div class="col s6 input-field">
<input type="text" class="value" id="WorkRate" />
<label for="WorkRate" class="translate">Arbeitspreis ( "Netznutzung" + "Umlagen, Abgaben, Steuern" + "Kosten für Ökostromzertifikate, Abrechnung und Vertrieb", incl. MWSt.)</label>
<label for="WorkRate" class="translate">Arbeitspreis (EXTRA) ( "Netznutzung" + "Umlagen, Abgaben, Steuern" + "Kosten für Ökostromzertifikate, Abrechnung und Vertrieb", incl. MWSt.)</label>
</div>
</div>
</div>
Expand Down
23 changes: 20 additions & 3 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ async function main() {
const mwst = parseInt(adapter.config.MWstRate);
const mwstRate = (mwst + 100) / 100;
const workRate = parseFloat(adapter.config.WorkRate);
const absPriceFactor = parseFloat(adapter.config.absPriceFactor);
const constantCosts = parseFloat(adapter.config.constantCosts);
const loadingThresholdStart = adapter.config.LoadingThresholdStart;
if (isNaN(parseInt(loadingThresholdStart))) {return adapter.log.error("loadingThresholdStart NaN")}
const loadingThresholdEnd = adapter.config.LoadingThresholdEnd;
Expand Down Expand Up @@ -250,6 +252,19 @@ async function main() {
native: {}
});

await adapter.setObjectNotExistsAsync(stateBaseName + "nettoFullPriceKwh", {
type: "state",
common: {
name: "Preis pro KWh (excl. MwSt., incl. Betreiberkosten)",
type: "number",
role: "value",
unit: "Cent / KWh",
read: true,
write: false
},
native: {}
});

await adapter.setObjectNotExistsAsync(stateBaseName + "bruttoPriceKwh", {
type: "state",
common: {
Expand Down Expand Up @@ -286,8 +301,9 @@ async function main() {
let endTime = end.toLocaleTimeString('de-DE');
let endDate = end.toLocaleDateString('de-DE');
let nettoPriceKwh = array[i].marketprice / 10; //price is in eur per MwH. Convert it in cent per KwH
let bruttoPriceKwh = nettoPriceKwh * mwstRate;
let toalPriceKwh = bruttoPriceKwh + workRate ;
let nettoFullPriceKwh = nettoPriceKwh + (Math.abs(nettoPriceKwh) * absPriceFactor) + constantCosts;
let bruttoPriceKwh = nettoFullPriceKwh * mwstRate;
let totalPriceKwh = bruttoPriceKwh + workRate ;

//write prices / timestamps to their data points
await Promise.all(
Expand All @@ -298,8 +314,9 @@ async function main() {
,adapter.setStateAsync(stateBaseName + "endTimestamp", endTs, true)
,adapter.setStateAsync(stateBaseName + "endDate", endDate, true)
,adapter.setStateAsync(stateBaseName + "nettoPriceKwh", nettoPriceKwh, true)
,adapter.setStateAsync(stateBaseName + "nettoFullPriceKwh", nettoFullPriceKwh, true)
,adapter.setStateAsync(stateBaseName + "bruttoPriceKwh", bruttoPriceKwh, true)
,adapter.setStateAsync(stateBaseName + "totalPriceKwh", toalPriceKwh, true)
,adapter.setStateAsync(stateBaseName + "totalPriceKwh", totalPriceKwh, true)
])
}

Expand Down
Loading