aWATTar: Add support for aWATTar Germany.

master
Michael Zanetti 2020-03-20 00:54:04 +01:00
parent ac6dcf0765
commit 76811c0207
4 changed files with 131 additions and 27 deletions

View File

@ -1,8 +1,14 @@
# aWATTar
This plugin allows to receive the current energy market price from the [aWATTar GmbH](https://www.awattar.com/).
In order to use this plugin you need to enter the access token from your energy provider. You can find more
information about you accesstoken [here](https://www.awattar.com/api-unser-datenfeed).
This plugin allows to receive the current energy market price from the aWATTar GmbH.
* [aWATTar Austria](https://www.awattar.com)
* [aWATTar Germany](https://www.awattar.de)
The Austrian edition of aWATTar requires to enter the access token from your energy provider.
You can find more information about you accesstoken [here](https://www.awattar.com/api-unser-datenfeed).
The German servers do not require a token at this point.
## Available data
@ -17,11 +23,3 @@ price is above the average, if the deviation is negative, the current price is b
![aWATTar graph](https://raw.githubusercontent.com/guh/nymea-plugins/master/awattar/docs/images/awattar-graph.png "aWATTar graph")
# Heat pump
Information about the smart grid modes can be found [here](https://www.waermepumpe.de/sg-ready/).
In order to interact with the heat pump (SG-ready), this plugin creates a CoAP connection to the server running on the
6LoWPAN bridge. The server IPv6 can be configured in the plugin configuration. Once the connection is established, the
plugin searches for 6LoWPAN neighbors in the network.

View File

@ -40,6 +40,29 @@
IntegrationPluginAwattar::IntegrationPluginAwattar()
{
m_serverUrls[awattarATThingClassId] = "https://api.awattar.com/v1/marketdata";
m_serverUrls[awattarDEThingClassId] = "https://api.awattar.de/v1/marketdata";
m_connectedStateTypeIds[awattarATThingClassId] = awattarATConnectedStateTypeId;
m_connectedStateTypeIds[awattarDEThingClassId] = awattarDEConnectedStateTypeId;
m_currentMarketPriceStateTypeIds[awattarATThingClassId] = awattarATCurrentMarketPriceStateTypeId;
m_currentMarketPriceStateTypeIds[awattarDEThingClassId] = awattarDECurrentMarketPriceStateTypeId;
m_validUntilStateTypeIds[awattarATThingClassId] = awattarATValidUntilStateTypeId;
m_validUntilStateTypeIds[awattarDEThingClassId] = awattarDEValidUntilStateTypeId;
m_averagePriceStateTypeIds[awattarATThingClassId] = awattarATAveragePriceStateTypeId;
m_averagePriceStateTypeIds[awattarDEThingClassId] = awattarDEAveragePriceStateTypeId;
m_lowestPriceStateTypeIds[awattarATThingClassId] = awattarATLowestPriceStateTypeId;
m_lowestPriceStateTypeIds[awattarDEThingClassId] = awattarDELowestPriceStateTypeId;
m_highestPriceStateTypeIds[awattarATThingClassId] = awattarATHighestPriceStateTypeId;
m_highestPriceStateTypeIds[awattarDEThingClassId] = awattarDEHighestPriceStateTypeId;
m_averageDeviationStateTypeIds[awattarATThingClassId] = awattarATAverageDeviationStateTypeId;
m_averageDeviationStateTypeIds[awattarDEThingClassId] = awattarDEAverageDeviationStateTypeId;
}
IntegrationPluginAwattar::~IntegrationPluginAwattar()
@ -116,7 +139,7 @@ void IntegrationPluginAwattar::requestPriceData(Thing* thing, ThingSetupInfo *se
QByteArray data = QString(token + ":").toUtf8().toBase64();
QString header = "Basic " + data;
QNetworkRequest request(QUrl("https://api.awattar.com/v1/marketdata"));
QNetworkRequest request(QUrl(m_serverUrls.value(thing->thingClassId())));
request.setRawHeader("Authorization", header.toLocal8Bit());
request.setSslConfiguration(QSslConfiguration::defaultConfiguration());
QNetworkReply *reply = hardwareManager()->networkManager()->get(request);
@ -130,7 +153,7 @@ void IntegrationPluginAwattar::requestPriceData(Thing* thing, ThingSetupInfo *se
if (setup) {
setup->finish(Thing::ThingErrorHardwareFailure, QT_TR_NOOP("Error getting data from server."));
} else {
thing->setStateValue(awattarConnectedStateTypeId, false);
thing->setStateValue(m_connectedStateTypeIds.value(thing->thingClassId()), false);
}
return;
}
@ -142,7 +165,7 @@ void IntegrationPluginAwattar::requestPriceData(Thing* thing, ThingSetupInfo *se
if (setup) {
setup->finish(Thing::ThingErrorHardwareFailure, QT_TR_NOOP("The server returned unexpected data."));
} else {
thing->setStateValue(awattarConnectedStateTypeId, false);
thing->setStateValue(m_connectedStateTypeIds.value(thing->thingClassId()), false);
}
return;
}
@ -151,7 +174,7 @@ void IntegrationPluginAwattar::requestPriceData(Thing* thing, ThingSetupInfo *se
setup->finish(Thing::ThingErrorNoError);
}
thing->setStateValue(awattarConnectedStateTypeId, true);
thing->setStateValue(m_connectedStateTypeIds.value(thing->thingClassId()), true);
processPriceData(thing, jsonDoc.toVariant().toMap());
});
@ -200,8 +223,8 @@ void IntegrationPluginAwattar::processPriceData(Thing *thing, const QVariantMap
if (price < minPrice)
minPrice = price;
thing->setStateValue(awattarCurrentMarketPriceStateTypeId, currentPrice / 10.0);
thing->setStateValue(awattarValidUntilStateTypeId, endTime.toLocalTime().toTime_t());
thing->setStateValue(m_currentMarketPriceStateTypeIds.value(thing->thingClassId()), currentPrice / 10.0);
thing->setStateValue(m_validUntilStateTypeIds.value(thing->thingClassId()), endTime.toLocalTime().toTime_t());
}
}
@ -214,9 +237,9 @@ void IntegrationPluginAwattar::processPriceData(Thing *thing, const QVariantMap
deviation = qRound(-100 * (averagePrice - currentPrice) / (maxPrice - averagePrice));
}
thing->setStateValue(awattarAveragePriceStateTypeId, averagePrice / 10.0);
thing->setStateValue(awattarLowestPriceStateTypeId, minPrice / 10.0);
thing->setStateValue(awattarHighestPriceStateTypeId, maxPrice / 10.0);
thing->setStateValue(awattarAverageDeviationStateTypeId, deviation);
thing->setStateValue(m_averagePriceStateTypeIds.value(thing->thingClassId()), averagePrice / 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_averageDeviationStateTypeIds.value(thing->thingClassId()), deviation);
}

View File

@ -57,13 +57,22 @@ public:
void setupThing(ThingSetupInfo *info) override;
void thingRemoved(Thing *thing) override;
private:
PluginTimer *m_pluginTimer = nullptr;
private slots:
void onPluginTimer();
void requestPriceData(Thing* thing, ThingSetupInfo *setup = nullptr);
void processPriceData(Thing *thing, const QVariantMap &data);
private:
PluginTimer *m_pluginTimer = nullptr;
QHash<ThingClassId, QString> m_serverUrls;
QHash<ThingClassId, StateTypeId> m_connectedStateTypeIds;
QHash<ThingClassId, StateTypeId> m_currentMarketPriceStateTypeIds;
QHash<ThingClassId, StateTypeId> m_validUntilStateTypeIds;
QHash<ThingClassId, StateTypeId> m_averagePriceStateTypeIds;
QHash<ThingClassId, StateTypeId> m_lowestPriceStateTypeIds;
QHash<ThingClassId, StateTypeId> m_highestPriceStateTypeIds;
QHash<ThingClassId, StateTypeId> m_averageDeviationStateTypeIds;
};
#endif // INTEGRATIONPLUGINAWATTAR_H

View File

@ -20,8 +20,8 @@
"thingClasses": [
{
"id": "29cd8265-d8bb-4cf9-9080-bfc2cf9787bc",
"displayName": "aWATTar",
"name": "awattar",
"displayName": "aWATTar AT",
"name": "awattarAT",
"createMethods": ["user"],
"setupMethod": "displaypin",
"interfaces": ["connectable"],
@ -32,7 +32,8 @@
"displayName": "Online",
"displayNameEvent": "Online changed",
"type": "bool",
"defaultValue": false
"defaultValue": false,
"cached": false
},
{
"id": "eab37309-3dd8-46a0-94d4-bd05b5bb0430",
@ -89,6 +90,79 @@
"defaultValue": 0
}
]
},
{
"id": "61973ead-98a4-4064-8fc3-532b4ecb9f78",
"displayName": "aWATTar DE",
"name": "awattarDE",
"createMethods": ["user"],
"setupMethod": "justAdd",
"interfaces": ["connectable"],
"stateTypes": [
{
"id": "2646b541-1ce0-4656-b253-2f98608072b3",
"name": "connected",
"displayName": "Online",
"displayNameEvent": "Online changed",
"type": "bool",
"defaultValue": false,
"cached": false
},
{
"id": "048566fe-d49d-4cc7-b93b-520f727f600a",
"name": "currentMarketPrice",
"displayName": "current market price",
"displayNameEvent": "current market price changed",
"type": "double",
"unit": "EuroCentPerKiloWattHour",
"defaultValue": 0
},
{
"id": "f5ffd03d-e21f-4a27-bc69-f1aed426281c",
"name": "averageDeviation",
"displayName": "average deviation",
"displayNameEvent": "average deviation changed",
"type": "int",
"unit": "Percentage",
"defaultValue": 0
},
{
"id": "a1d9fb61-4907-4c2d-9bd8-b8cbcfe7f3e3",
"name": "validUntil",
"displayName": "valid until",
"displayNameEvent": "valid until changed",
"unit": "UnixTime",
"type": "int",
"defaultValue": 0
},
{
"id": "90571d1e-42c1-4a55-b70d-4781fab02313",
"name": "averagePrice",
"displayName": "average market price [+/- 12 h]",
"displayNameEvent": "average market price [+/- 12 h] changed",
"type": "double",
"unit": "EuroCentPerKiloWattHour",
"defaultValue": 0
},
{
"id": "9e4dd133-ecfc-4239-9536-b5ec502cb194",
"name": "lowestPrice",
"displayName": "lowest market price [+/- 12 h]",
"displayNameEvent": "lowest market price [+/- 12 h] changed",
"type": "double",
"unit": "EuroCentPerKiloWattHour",
"defaultValue": 0
},
{
"id": "c97662ed-0e61-4c0e-acca-6792a1c27213",
"name": "highestPrice",
"displayName": "highest market price [+/- 12 h]",
"displayNameEvent": "highest market price [+/- 12 h] changed",
"type": "double",
"unit": "EuroCentPerKiloWattHour",
"defaultValue": 0
}
]
}
]
}