diff --git a/debian/control b/debian/control index 715f98ee6..a83af2d5f 100644 --- a/debian/control +++ b/debian/control @@ -992,6 +992,22 @@ Description: nymea.io plugin for simulated devices This package will install the nymea.io plugin for simulated devices +Package: nymea-plugin-simpleheatpump +Architecture: any +Depends: ${shlibs:Depends}, + ${misc:Depends}, + libnymea-gpio, + nymea-plugins-translations, +Description: nymea.io plugin for simple heat pumps + The nymea daemon is a plugin based IoT (Internet of Things) server. The + server works like a translator for devices, things and services and + allows them to interact. + With the powerful rule engine you are able to connect any device available + in the system and create individual scenes and behaviors for your environment. + . + This package will install the nymea.io plugin for simple heat pumps + + Package: nymea-plugin-somfytahoma Architecture: any Depends: ${shlibs:Depends}, @@ -1372,6 +1388,7 @@ Depends: nymea-plugin-boblight, nymea-plugin-remotessh, nymea-plugin-serialportcommander, nymea-plugin-systemmonitor, + nymea-plugin-simpleheatpump, nymea-plugin-onewire, nymea-plugin-dynatrace, Description: Meta package for nymea makers, tinkerers and hackers plugins. diff --git a/debian/nymea-plugin-simpleheatpump.install.in b/debian/nymea-plugin-simpleheatpump.install.in new file mode 100644 index 000000000..8d1184b55 --- /dev/null +++ b/debian/nymea-plugin-simpleheatpump.install.in @@ -0,0 +1 @@ +usr/lib/@DEB_HOST_MULTIARCH@/nymea/plugins/libnymea_integrationpluginsimpleheatpump.so diff --git a/nymea-plugins.pro b/nymea-plugins.pro index 044bb5278..1118b516f 100644 --- a/nymea-plugins.pro +++ b/nymea-plugins.pro @@ -56,6 +56,7 @@ PLUGIN_DIRS = \ serialportcommander \ sgready \ simulation \ + simpleheatpump \ sma \ somfytahoma \ sonos \ diff --git a/simpleheatpump/README.md b/simpleheatpump/README.md new file mode 100644 index 000000000..e2ad4ee90 --- /dev/null +++ b/simpleheatpump/README.md @@ -0,0 +1,4 @@ +# Simple heat pump + +Control heat pumps offering a simple relay interface for boosting the energy consumption when cheap or self produced energy is available. + diff --git a/simpleheatpump/integrationpluginsimpleheatpump.cpp b/simpleheatpump/integrationpluginsimpleheatpump.cpp new file mode 100644 index 000000000..048e18815 --- /dev/null +++ b/simpleheatpump/integrationpluginsimpleheatpump.cpp @@ -0,0 +1,141 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +* +* Copyright 2013 - 2021, nymea GmbH +* Contact: contact@nymea.io +* +* This file is part of nymea. +* This project including source code and documentation is protected by +* copyright law, and remains the property of nymea GmbH. All rights, including +* reproduction, publication, editing and translation, are reserved. The use of +* this project is subject to the terms of a license agreement to be concluded +* with nymea GmbH in accordance with the terms of use of nymea GmbH, available +* under https://nymea.io/license +* +* GNU Lesser General Public License Usage +* Alternatively, this project may be redistributed and/or modified under the +* terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; version 3. This project is distributed in the hope that +* it will be useful, but WITHOUT ANY WARRANTY; without even the implied +* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this project. If not, see . +* +* For any further details and any questions please contact us under +* contact@nymea.io or see our FAQ/Licensing Information on +* https://nymea.io/license/faq +* +* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#include "integrationpluginsimpleheatpump.h" +#include "plugininfo.h" + +IntegrationPluginSimpleHeatpump::IntegrationPluginSimpleHeatpump() +{ + +} + +void IntegrationPluginSimpleHeatpump::init() +{ + +} + +void IntegrationPluginSimpleHeatpump::discoverThings(ThingDiscoveryInfo *info) +{ + // Check if GPIOs are available on this platform + if (!Gpio::isAvailable()) { + qCWarning(dcSimpleHeatPump()) << "There are no GPIOs available on this plattform"; + //: Error discovering GPIOs + return info->finish(Thing::ThingErrorHardwareNotAvailable, QT_TR_NOOP("No GPIOs available on this system.")); + } + + // FIXME: provide once system configurations are loaded + + info->finish(Thing::ThingErrorNoError); +} + +void IntegrationPluginSimpleHeatpump::setupThing(ThingSetupInfo *info) +{ + Thing *thing = info->thing(); + qCDebug(dcSimpleHeatPump()) << "Setup" << thing->name() << thing->params(); + + if (thing->thingClassId() == simpleHeatPumpInterfaceThingClassId) { + // Check if GPIOs are available on this platform + if (!Gpio::isAvailable()) { + qCWarning(dcSimpleHeatPump()) << "There are no GPIOs available on this plattform"; + //: Error set up GPIOs + return info->finish(Thing::ThingErrorHardwareNotAvailable, QT_TR_NOOP("No GPIOs found on this system.")); + } + + int gpioNumber = thing->paramValue(simpleHeatPumpInterfaceThingGpioNumberParamTypeId).toInt(); + bool initialValue = thing->stateValue(simpleHeatPumpInterfaceBoostStateTypeId).toBool(); + + if (gpioNumber < 0) { + qCWarning(dcSimpleHeatPump()) << "Invalid GPIO number" << gpioNumber; + info->finish(Thing::ThingErrorInvalidParameter); + return; + } + + Gpio *gpio = new Gpio(gpioNumber, this); + if (!gpio->exportGpio()) { + qCWarning(dcSimpleHeatPump()) << "Could not export gpio" << gpioNumber; + gpio->deleteLater(); + return info->finish(Thing::ThingErrorHardwareFailure, QT_TR_NOOP("Failed to set up the GPIO interface.")); + } + + if (!gpio->setDirection(Gpio::DirectionOutput)) { + qCWarning(dcSimpleHeatPump()) << "Failed to configure gpio" << gpioNumber << "as output"; + gpio->deleteLater(); + return info->finish(Thing::ThingErrorHardwareFailure, QT_TR_NOOP("Failed to set up the GPIO interface.")); + } + + // Set the pin to the initial value + if (!gpio->setValue(initialValue ? Gpio::ValueHigh : Gpio::ValueLow)) { + qCWarning(dcSimpleHeatPump()) << "Failed to set initially value" << initialValue << "for gpio" << gpioNumber; + gpio->deleteLater(); + return info->finish(Thing::ThingErrorHardwareFailure, QT_TR_NOOP("Failed to set up the GPIO interface.")); + } + + m_gpios.insert(thing, gpio); + info->finish(Thing::ThingErrorNoError); + } +} + +void IntegrationPluginSimpleHeatpump::postSetupThing(Thing *thing) +{ + Q_UNUSED(thing) +} + +void IntegrationPluginSimpleHeatpump::thingRemoved(Thing *thing) +{ + if (m_gpios.contains(thing)) { + delete m_gpios.take(thing); + } +} + +void IntegrationPluginSimpleHeatpump::executeAction(ThingActionInfo *info) +{ + Thing *thing = info->thing(); + + if (thing->thingClassId() == simpleHeatPumpInterfaceThingClassId) { + Gpio *gpio = m_gpios.value(info->thing()); + if (!gpio) { + qCWarning(dcSimpleHeatPump()) << "Failed to execute action. There is no GPIO available for" << thing; + info->finish(Thing::ThingErrorHardwareNotAvailable); + return; + } + + if (info->action().actionTypeId() == simpleHeatPumpInterfaceBoostActionTypeId) { + bool boostEnabled = info->action().paramValue(simpleHeatPumpInterfaceBoostActionBoostParamTypeId).toBool(); + if (!gpio->setValue(boostEnabled ? Gpio::ValueHigh : Gpio::ValueLow)) { + qCWarning(dcSimpleHeatPump()) << "Failed to set the boost mode for" << thing << "to" << boostEnabled; + info->finish(Thing::ThingErrorHardwareFailure); + return; + } + + thing->setStateValue(simpleHeatPumpInterfaceBoostStateTypeId, boostEnabled); + info->finish(Thing::ThingErrorNoError); + } + } +} diff --git a/simpleheatpump/integrationpluginsimpleheatpump.h b/simpleheatpump/integrationpluginsimpleheatpump.h new file mode 100644 index 000000000..cc06e34d9 --- /dev/null +++ b/simpleheatpump/integrationpluginsimpleheatpump.h @@ -0,0 +1,60 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +* +* Copyright 2013 - 2021, nymea GmbH +* Contact: contact@nymea.io +* +* This file is part of nymea. +* This project including source code and documentation is protected by +* copyright law, and remains the property of nymea GmbH. All rights, including +* reproduction, publication, editing and translation, are reserved. The use of +* this project is subject to the terms of a license agreement to be concluded +* with nymea GmbH in accordance with the terms of use of nymea GmbH, available +* under https://nymea.io/license +* +* GNU Lesser General Public License Usage +* Alternatively, this project may be redistributed and/or modified under the +* terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; version 3. This project is distributed in the hope that +* it will be useful, but WITHOUT ANY WARRANTY; without even the implied +* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this project. If not, see . +* +* For any further details and any questions please contact us under +* contact@nymea.io or see our FAQ/Licensing Information on +* https://nymea.io/license/faq +* +* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef INTEGRATIONPLUGINSIMPLEHEATPUMP_H +#define INTEGRATIONPLUGINSIMPLEHEATPUMP_H + +#include "integrations/integrationplugin.h" + +#include + +class IntegrationPluginSimpleHeatpump : public IntegrationPlugin +{ + Q_OBJECT + + Q_PLUGIN_METADATA(IID "io.nymea.IntegrationPlugin" FILE "integrationpluginsimpleheatpump.json") + Q_INTERFACES(IntegrationPlugin) + +public: + explicit IntegrationPluginSimpleHeatpump(); + + void init() override; + void discoverThings(ThingDiscoveryInfo *info) override; + void setupThing(ThingSetupInfo *info) override; + void postSetupThing(Thing *thing) override; + void thingRemoved(Thing *thing) override; + void executeAction(ThingActionInfo *info) override; + +private: + QHash m_gpios; + +}; + +#endif // INTEGRATIONPLUGINSIMPLEHEATPUMP_H diff --git a/simpleheatpump/integrationpluginsimpleheatpump.json b/simpleheatpump/integrationpluginsimpleheatpump.json new file mode 100644 index 000000000..ebcccf6fc --- /dev/null +++ b/simpleheatpump/integrationpluginsimpleheatpump.json @@ -0,0 +1,47 @@ +{ + "name": "SimpleHeatPump", + "displayName": "Simple heat pump", + "id": "6e99e657-7fd6-4c5f-b321-62656c00e1d6", + "vendors": [ + { + "name": "nymea", + "displayName": "nymea", + "id": "2062d64d-3232-433c-88bc-0d33c0ba2ba6", + "thingClasses": [ + { + "id": "bc553762-c842-422e-888f-6824aad099fb", + "name": "simpleHeatPumpInterface", + "displayName": "Simple heat pump interface", + "createMethods": ["user"], + "interfaces": [ "simpleheatpump" ], + "settingsTypes": [ + ], + "paramTypes": [ + { + "id": "b97d03d9-35ce-445d-903e-b1e3857006ce", + "name": "gpioNumber", + "displayName": "GPIO number", + "type": "int", + "defaultValue": -1 + } + ], + "stateTypes": [ + { + "id": "f8bccedf-5eb2-49a0-b892-c398dbd6a18d", + "name": "boost", + "displayName": "Boost production enabled", + "displayNameEvent": "Boost production changed", + "displayNameAction": "Boost production", + "type": "bool", + "writable": true, + "defaultValue": false, + "cached": true, + "ioType": "digitalOutput", + "suggestLogging": true + } + ] + } + ] + } + ] +} diff --git a/simpleheatpump/meta.json b/simpleheatpump/meta.json new file mode 100644 index 000000000..ef17c8602 --- /dev/null +++ b/simpleheatpump/meta.json @@ -0,0 +1,12 @@ +{ + "title": "Simple heat pump", + "tagline": "Control heat pumps offering a simple relay interface for boosting the energy consumption when cheap or self produced energy is available.", + "icon": "", + "stability": "community", + "offline": true, + "technologies": [ + ], + "categories": [ + "heating" + ] +} diff --git a/simpleheatpump/simpleheatpump.pro b/simpleheatpump/simpleheatpump.pro new file mode 100644 index 000000000..b41c9f22e --- /dev/null +++ b/simpleheatpump/simpleheatpump.pro @@ -0,0 +1,9 @@ +include(../plugins.pri) + +PKGCONFIG += nymea-gpio + +SOURCES += \ + integrationpluginsimpleheatpump.cpp + +HEADERS += \ + integrationpluginsimpleheatpump.h diff --git a/simpleheatpump/translations/6e99e657-7fd6-4c5f-b321-62656c00e1d6-en_US.ts b/simpleheatpump/translations/6e99e657-7fd6-4c5f-b321-62656c00e1d6-en_US.ts new file mode 100644 index 000000000..465e9e4e3 --- /dev/null +++ b/simpleheatpump/translations/6e99e657-7fd6-4c5f-b321-62656c00e1d6-en_US.ts @@ -0,0 +1,77 @@ + + + + + IntegrationPluginSimpleHeatpump + + + No GPIOs available on this system. + Error discovering GPIOs + + + + + No GPIOs found on this system. + Error set up GPIOs + + + + + + + Failed to set up the GPIO interface. + + + + + SimpleHeatPump + + + Boost production + The name of the ActionType ({f8bccedf-5eb2-49a0-b892-c398dbd6a18d}) of ThingClass simpleHeatPumpInterface + + + + + Boost production changed + The name of the EventType ({f8bccedf-5eb2-49a0-b892-c398dbd6a18d}) of ThingClass simpleHeatPumpInterface + + + + + + + Boost production enabled + The name of the ParamType (ThingClass: simpleHeatPumpInterface, ActionType: boost, ID: {f8bccedf-5eb2-49a0-b892-c398dbd6a18d}) +---------- +The name of the ParamType (ThingClass: simpleHeatPumpInterface, EventType: boost, ID: {f8bccedf-5eb2-49a0-b892-c398dbd6a18d}) +---------- +The name of the StateType ({f8bccedf-5eb2-49a0-b892-c398dbd6a18d}) of ThingClass simpleHeatPumpInterface + + + + + GPIO number + The name of the ParamType (ThingClass: simpleHeatPumpInterface, Type: thing, ID: {b97d03d9-35ce-445d-903e-b1e3857006ce}) + + + + + Simple heat pump + The name of the plugin SimpleHeatPump ({6e99e657-7fd6-4c5f-b321-62656c00e1d6}) + + + + + Simple heat pump interface + The name of the ThingClass ({bc553762-c842-422e-888f-6824aad099fb}) + + + + + nymea + The name of the vendor ({2062d64d-3232-433c-88bc-0d33c0ba2ba6}) + + + +