Awattar: Add a ranking state for simple use in rules
Allows to do stuff when ranking indicates the current slots is in top x for the day. Also fixes a bug that the current value hasn't been taken into account when calculating averages/deviationsmaster
parent
74bda79d10
commit
3c0701100a
|
|
@ -17,6 +17,8 @@ In the following chart you can see an example of the market prices from -12 hour
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
Additionally, the plugin holds a rank for the current slot. 0 Indicates the cheapest slot of the interval [-12h `<` now `<` + 12h].
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
* aWattar "Hourly" energy tarif.
|
* aWattar "Hourly" energy tarif.
|
||||||
|
|
|
||||||
|
|
@ -153,25 +153,31 @@ void IntegrationPluginAwattar::processPriceData(Thing *thing, const QVariantMap
|
||||||
int deviation = 0;
|
int deviation = 0;
|
||||||
double maxPrice = -1000;
|
double maxPrice = -1000;
|
||||||
double minPrice = 1000;
|
double minPrice = 1000;
|
||||||
foreach (QVariant element, dataElements) {
|
QList<double> prices;
|
||||||
|
for (int i = 0; i < dataElements.count(); i++) {
|
||||||
|
QVariant element = dataElements.at(i);
|
||||||
QVariantMap elementMap = element.toMap();
|
QVariantMap elementMap = element.toMap();
|
||||||
QDateTime startTime = QDateTime::fromMSecsSinceEpoch(elementMap.value("start_timestamp").toLongLong());
|
QDateTime startTime = QDateTime::fromMSecsSinceEpoch(elementMap.value("start_timestamp").toLongLong());
|
||||||
QDateTime endTime = QDateTime::fromMSecsSinceEpoch(elementMap.value("end_timestamp").toLongLong());
|
QDateTime endTime = QDateTime::fromMSecsSinceEpoch(elementMap.value("end_timestamp").toLongLong());
|
||||||
double price = elementMap.value("marketprice").toDouble();
|
double price = elementMap.value("marketprice").toDouble();
|
||||||
|
|
||||||
// check interval [-12h < x < + 12h]
|
// check interval [-12h < x < + 12h]
|
||||||
if ((startTime >= currentTime.addSecs(-3600 * 12) && endTime <= currentTime ) ||
|
if (startTime >= currentTime.addSecs(-3600 * 12) && endTime <= currentTime.addSecs(3600 * 12)) {
|
||||||
(endTime <= currentTime.addSecs(3600 * 12) && startTime >= currentTime )) {
|
|
||||||
sum += price;
|
sum += price;
|
||||||
count++;
|
count++;
|
||||||
|
prices.append(price);
|
||||||
|
qCDebug(dcAwattar()) << "Adding price" << startTime.toString() << price;
|
||||||
|
|
||||||
if (price > maxPrice)
|
if (price > maxPrice)
|
||||||
maxPrice = price;
|
maxPrice = price;
|
||||||
|
|
||||||
if (price < minPrice)
|
if (price < minPrice)
|
||||||
minPrice = price;
|
minPrice = price;
|
||||||
|
} else {
|
||||||
|
qCDebug(dcAwattar()) << "Not adding price" << startTime.toString() << price;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (currentTime >= startTime && currentTime <= endTime) {
|
if (currentTime >= startTime && currentTime <= endTime) {
|
||||||
currentPrice = price;
|
currentPrice = price;
|
||||||
sum += price;
|
sum += price;
|
||||||
|
|
@ -188,6 +194,7 @@ void IntegrationPluginAwattar::processPriceData(Thing *thing, const QVariantMap
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// calculate averagePrice and mean deviation
|
// calculate averagePrice and mean deviation
|
||||||
averagePrice = sum / count;
|
averagePrice = sum / count;
|
||||||
|
|
||||||
|
|
@ -201,5 +208,14 @@ void IntegrationPluginAwattar::processPriceData(Thing *thing, const QVariantMap
|
||||||
thing->setStateValue(m_lowestPriceStateTypeIds.value(thing->thingClassId()), minPrice / 10.0);
|
thing->setStateValue(m_lowestPriceStateTypeIds.value(thing->thingClassId()), minPrice / 10.0);
|
||||||
thing->setStateValue(m_highestPriceStateTypeIds.value(thing->thingClassId()), maxPrice / 10.0);
|
thing->setStateValue(m_highestPriceStateTypeIds.value(thing->thingClassId()), maxPrice / 10.0);
|
||||||
thing->setStateValue(m_averageDeviationStateTypeIds.value(thing->thingClassId()), deviation);
|
thing->setStateValue(m_averageDeviationStateTypeIds.value(thing->thingClassId()), deviation);
|
||||||
|
|
||||||
|
qCDebug(dcAwattar()) << "AVG:" << averagePrice << "Min:" << minPrice << "Max:" << maxPrice << "Curr:" << currentPrice;
|
||||||
|
qSort(prices.begin(), prices.end());
|
||||||
|
int rank = prices.indexOf(currentPrice);
|
||||||
|
if (rank < 0) {
|
||||||
|
rank = 100;
|
||||||
|
}
|
||||||
|
thing->setStateValue("rank", rank);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,15 @@
|
||||||
"type": "double",
|
"type": "double",
|
||||||
"unit": "EuroCentPerKiloWattHour",
|
"unit": "EuroCentPerKiloWattHour",
|
||||||
"defaultValue": 0
|
"defaultValue": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "8af49ba8-0aba-4f09-ab11-533dcd19e873",
|
||||||
|
"name": "rank",
|
||||||
|
"displayName": "Current rank (lower is better)",
|
||||||
|
"type": "uint",
|
||||||
|
"minValue": 0,
|
||||||
|
"maxValue": 100,
|
||||||
|
"defaultValue": 100
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
@ -153,6 +162,15 @@
|
||||||
"type": "double",
|
"type": "double",
|
||||||
"unit": "EuroCentPerKiloWattHour",
|
"unit": "EuroCentPerKiloWattHour",
|
||||||
"defaultValue": 0
|
"defaultValue": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "f3a2a46f-e281-4f60-9d27-345264b67f9a",
|
||||||
|
"name": "rank",
|
||||||
|
"displayName": "Current rank (lower is better)",
|
||||||
|
"type": "uint",
|
||||||
|
"minValue": 0,
|
||||||
|
"maxValue": 100,
|
||||||
|
"defaultValue": 100
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue