Shelly: Add support for the PlusSmoke

master
Michael Zanetti 2023-12-06 20:43:51 +01:00
parent 74bda79d10
commit c887a3c540
3 changed files with 132 additions and 3 deletions

View File

@ -23,6 +23,8 @@ The currently supported devices are:
* Shelly Motion
* Shelly Vintage
* Shelly TRV
* Shelly Smoke
* Shelly Plus Smoke
## Requirements
The Shelly device needs to be connected to the same WiFi as nymea is in. New Shelly devices will open a WiFi named with

View File

@ -123,8 +123,10 @@ void IntegrationPluginShelly::discoverThings(ThingDiscoveryInfo *info)
namePattern = QRegExp("shellytrv-[0-9A-Z]+$");
} else if (info->thingClassId() == shellyFloodThingClassId) {
namePattern = QRegExp("^shellyflood-[0-9A-Z]+$");
} else if (info->thingClassId() == shellyFloodThingClassId) {
} else if (info->thingClassId() == shellySmokeThingClassId) {
namePattern = QRegExp("^shellysmoke-[0-9A-Z]+$");
} else if (info->thingClassId() == shellyPlusSmokeThingClassId) {
namePattern = QRegExp("^shellyplussmoke-[0-9A-Z]+$", Qt::CaseInsensitive);
} else if (info->thingClassId() == shellyGasThingClassId) {
namePattern = QRegExp("^shellygas-[0-9A-Z]+$");
}
@ -711,6 +713,14 @@ void IntegrationPluginShelly::executeAction(ThingActionInfo *info)
return;
}
if (action.actionTypeId() == shellyPlusSmokeMuteActionTypeId) {
ShellyRpcReply *reply = m_rpcClients.value(thing)->sendRequest("Smoke.Mute");
connect(reply, &ShellyRpcReply::finished, info, [info](ShellyRpcReply::Status status, const QVariantMap &/*response*/){
info->finish(status == ShellyRpcReply::StatusSuccess ? Thing::ThingErrorNoError : Thing::ThingErrorHardwareFailure);
});
return;
}
if (actionType.name() == "power") {
int relay = 1;
QHash<ActionTypeId, int> actionChannelMap = {
@ -1309,6 +1319,14 @@ void IntegrationPluginShelly::fetchStatusGen2(Thing *thing)
child->setStateValue("connected", true);
child->setStateValue("signalStrength", signalStrength);
}
// The Shelly Plus Smoke doesn't seem to send notifications, need to fill in data from polling
if (thing->thingClassId() == shellyPlusSmokeThingClassId) {
thing->setStateValue(shellyPlusSmokeBatteryLevelStateTypeId, response.value("devicepower:0").toMap().value("battery").toMap().value("percent").toInt());
thing->setStateValue(shellyPlusSmokeBatteryCriticalStateTypeId, thing->stateValue(shellyPlusSmokeBatteryLevelStateTypeId).toInt() < 10);
thing->setStateValue(shellyPlusSmokeFireDetectedStateTypeId, response.value("smoke:0").toMap().value("alarm").toBool());
thing->setStateValue(shellyPlusSmokeMuteStateTypeId, response.value("smoke:0").toMap().value("mute").toBool());
}
});
ShellyRpcReply *infoReply = client->sendRequest("Shelly.GetDeviceInfo");
@ -1742,6 +1760,11 @@ void IntegrationPluginShelly::setupGen2(ThingSetupInfo *info)
info->finish(Thing::ThingErrorNoError);
return;
}
if (info->thing()->thingClassId() == shellyPlusSmokeThingClassId) {
info->finish(Thing::ThingErrorNoError);
return;
}
});
});
@ -1872,12 +1895,17 @@ void IntegrationPluginShelly::setupGen2(ThingSetupInfo *info)
if (id.startsWith("temperature")) {
Thing *addonTempSensor = myThings().filterByParentId(thing->id()).findByParams({{shellyAddonTempSensorThingAddonIdParamTypeId, id}});
QVariantMap temperatureMap = notification.value(id).toMap();
if (addonTempSensor) {
QVariantMap temperatureMap = notification.value(id).toMap();
addonTempSensor->setStateValue(shellyAddonTempSensorTemperatureStateTypeId, temperatureMap.value("tC").toDouble());
}
}
if (id.startsWith("smoke:0")) {
QVariantMap map = notification.value("smoke:0").toMap();
thing->setStateValue(shellyPlusSmokeFireDetectedStateTypeId, map.value("alarm").toBool());
}
}
});

View File

@ -2456,6 +2456,105 @@
}
]
},
{
"id": "8013cb36-2375-4d52-b042-4b61a290be3b",
"name": "shellyPlusSmoke",
"displayName": "Shelly Plus Smoke",
"createMethods": ["discovery"],
"setupMethod": "enterpin",
"interfaces": ["firesensor", "wirelessconnectable", "battery", "update"],
"paramTypes": [
{
"id": "f06b28da-821f-4d6f-a9a4-16c0faa0e745",
"name":"id",
"displayName": "Shelly ID",
"type": "QString",
"readOnly": true
}
],
"stateTypes": [
{
"id": "12cf10d4-c74f-49e3-ac5a-3647ffb0cc64",
"name": "fireDetected",
"displayName": "Fire detected",
"type": "bool",
"defaultValue": false
},
{
"id": "724cd341-95b3-4bc6-b9c9-d8e85c0f8b7a",
"name": "mute",
"displayName": "Muted",
"displayNameAction": "Set mute",
"type": "bool",
"defaultValue": false,
"writable": true
},
{
"id": "8e5095d7-ab1c-42ba-934d-8e6c290f6b49",
"name": "connected",
"displayName": "Connected",
"type": "bool",
"defaultValue": false,
"cached": false
},
{
"id": "bc08e45b-8976-45da-9f26-80a0cdf92a3d",
"name": "signalStrength",
"displayName": "Signal strength",
"type": "uint",
"unit": "Percentage",
"minValue": 0,
"maxValue": 100,
"defaultValue": 0,
"cached": false
},
{
"id": "201dc87b-7fd3-4252-9bc8-e3cc3ac88f77",
"name": "batteryLevel",
"displayName": "Battery level",
"type": "int",
"minValue": 0,
"maxValue": 100,
"unit": "Percentage",
"defaultValue": 0
},
{
"id": "735eca96-b388-49f5-8e38-41361a4b85ad",
"name": "batteryCritical",
"displayName": "Battery level critical",
"type": "bool",
"defaultValue": false
},
{
"id": "7626bcf4-5a16-400a-bc00-6deb64b699c1",
"name": "updateStatus",
"displayName": "Update status",
"type": "QString",
"possibleValues": ["idle", "available", "updating"],
"defaultValue": "idle"
},
{
"id": "ce6114c9-d422-4e32-bfc3-4f3435915da5",
"name": "currentVersion",
"displayName": "Current firmware version",
"type": "QString",
"defaultValue": ""
},
{
"id": "39a37cb7-9485-4895-842f-348770c9cdc3",
"name": "availableVersion",
"displayName": "Available firmware version",
"type": "QString",
"defaultValue": ""
}
], "actionTypes": [
{
"id": "ac36efdb-1929-4e13-befd-b981439eaeab",
"name": "performUpdate",
"displayName": "Start firmware update"
}
]
},
{
"id": "f032e312-0911-450e-9456-67c27f31bebd",
"name": "shellyGas",