publish lock action command result via mqtt
This commit is contained in:
@@ -8,11 +8,12 @@
|
|||||||
#define mqtt_topic_battery_max_turn_current "/battery/maxTurnCurrent"
|
#define mqtt_topic_battery_max_turn_current "/battery/maxTurnCurrent"
|
||||||
#define mqtt_topic_battery_lock_distance "/battery/lockDistance"
|
#define mqtt_topic_battery_lock_distance "/battery/lockDistance"
|
||||||
|
|
||||||
#define mqtt_topic_lockstate_state "/lock/state"
|
#define mqtt_topic_lock_state "/lock/state"
|
||||||
#define mqtt_topic_lockstate_trigger "/lock/trigger"
|
#define mqtt_topic_lock_trigger "/lock/trigger"
|
||||||
#define mqtt_topic_lockstate_completionStatus "/lock/completionStatus"
|
#define mqtt_topic_lock_completionStatus "/lock/completionStatus"
|
||||||
|
#define mqtt_topic_lock_action_command_result "/lock/commandResult"
|
||||||
#define mqtt_topic_door_sensor_state "/lock/doorSensorState"
|
#define mqtt_topic_door_sensor_state "/lock/doorSensorState"
|
||||||
#define mqtt_topic_lockstate_action "/lock/action"
|
#define mqtt_topic_lock_action "/lock/action"
|
||||||
|
|
||||||
#define mqtt_topic_config_button_enabled "/configuration/buttonEnabled"
|
#define mqtt_topic_config_button_enabled "/configuration/buttonEnabled"
|
||||||
#define mqtt_topic_config_led_enabled "/configuration/ledEnabled"
|
#define mqtt_topic_config_led_enabled "/configuration/ledEnabled"
|
||||||
|
|||||||
17
Network.cpp
17
Network.cpp
@@ -147,7 +147,7 @@ bool Network::reconnect()
|
|||||||
Serial.println(F("MQTT connected"));
|
Serial.println(F("MQTT connected"));
|
||||||
_mqttConnected = true;
|
_mqttConnected = true;
|
||||||
delay(200);
|
delay(200);
|
||||||
subscribe(mqtt_topic_lockstate_action);
|
subscribe(mqtt_topic_lock_action);
|
||||||
|
|
||||||
for(auto topic : _configTopics)
|
for(auto topic : _configTopics)
|
||||||
{
|
{
|
||||||
@@ -206,7 +206,7 @@ void Network::onMqttDataReceived(char *&topic, byte *&payload, unsigned int &len
|
|||||||
value[i] = payload[i];
|
value[i] = payload[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
if(comparePrefixedPath(topic, mqtt_topic_lockstate_action))
|
if(comparePrefixedPath(topic, mqtt_topic_lock_action))
|
||||||
{
|
{
|
||||||
if(strcmp(value, "") == 0) return;
|
if(strcmp(value, "") == 0) return;
|
||||||
|
|
||||||
@@ -216,7 +216,7 @@ void Network::onMqttDataReceived(char *&topic, byte *&payload, unsigned int &len
|
|||||||
{
|
{
|
||||||
_lockActionReceivedCallback(value);
|
_lockActionReceivedCallback(value);
|
||||||
}
|
}
|
||||||
publishString(mqtt_topic_lockstate_action, "");
|
publishString(mqtt_topic_lock_action, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
for(auto configTopic : _configTopics)
|
for(auto configTopic : _configTopics)
|
||||||
@@ -239,21 +239,21 @@ void Network::publishKeyTurnerState(const Nuki::KeyTurnerState& keyTurnerState,
|
|||||||
{
|
{
|
||||||
memset(&str, 0, sizeof(str));
|
memset(&str, 0, sizeof(str));
|
||||||
lockstateToString(keyTurnerState.lockState, str);
|
lockstateToString(keyTurnerState.lockState, str);
|
||||||
publishString(mqtt_topic_lockstate_state, str);
|
publishString(mqtt_topic_lock_state, str);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(_firstTunerStatePublish || keyTurnerState.trigger != lastKeyTurnerState.trigger)
|
if(_firstTunerStatePublish || keyTurnerState.trigger != lastKeyTurnerState.trigger)
|
||||||
{
|
{
|
||||||
memset(&str, 0, sizeof(str));
|
memset(&str, 0, sizeof(str));
|
||||||
triggerToString(keyTurnerState.trigger, str);
|
triggerToString(keyTurnerState.trigger, str);
|
||||||
publishString(mqtt_topic_lockstate_trigger, str);
|
publishString(mqtt_topic_lock_trigger, str);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(_firstTunerStatePublish || keyTurnerState.lastLockActionCompletionStatus != lastKeyTurnerState.lastLockActionCompletionStatus)
|
if(_firstTunerStatePublish || keyTurnerState.lastLockActionCompletionStatus != lastKeyTurnerState.lastLockActionCompletionStatus)
|
||||||
{
|
{
|
||||||
memset(&str, 0, sizeof(str));
|
memset(&str, 0, sizeof(str));
|
||||||
completionStatusToString(keyTurnerState.lastLockActionCompletionStatus, str);
|
completionStatusToString(keyTurnerState.lastLockActionCompletionStatus, str);
|
||||||
publishString(mqtt_topic_lockstate_completionStatus, str);
|
publishString(mqtt_topic_lock_completionStatus, str);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(_firstTunerStatePublish || keyTurnerState.doorSensorState != lastKeyTurnerState.doorSensorState)
|
if(_firstTunerStatePublish || keyTurnerState.doorSensorState != lastKeyTurnerState.doorSensorState)
|
||||||
@@ -276,6 +276,11 @@ void Network::publishKeyTurnerState(const Nuki::KeyTurnerState& keyTurnerState,
|
|||||||
_firstTunerStatePublish = false;
|
_firstTunerStatePublish = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Network::publishCommandResult(const char *resultStr)
|
||||||
|
{
|
||||||
|
publishString(mqtt_topic_lock_action_command_result, resultStr);
|
||||||
|
}
|
||||||
|
|
||||||
void Network::publishBatteryReport(const Nuki::BatteryReport& batteryReport)
|
void Network::publishBatteryReport(const Nuki::BatteryReport& batteryReport)
|
||||||
{
|
{
|
||||||
publishFloat(mqtt_topic_battery_voltage, (float)batteryReport.batteryVoltage / 1000.0);
|
publishFloat(mqtt_topic_battery_voltage, (float)batteryReport.batteryVoltage / 1000.0);
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ public:
|
|||||||
bool isMqttConnected();
|
bool isMqttConnected();
|
||||||
|
|
||||||
void publishKeyTurnerState(const Nuki::KeyTurnerState& keyTurnerState, const Nuki::KeyTurnerState& lastKeyTurnerState);
|
void publishKeyTurnerState(const Nuki::KeyTurnerState& keyTurnerState, const Nuki::KeyTurnerState& lastKeyTurnerState);
|
||||||
|
void publishCommandResult(const char* resultStr);
|
||||||
void publishBatteryReport(const Nuki::BatteryReport& batteryReport);
|
void publishBatteryReport(const Nuki::BatteryReport& batteryReport);
|
||||||
void publishConfig(const Nuki::Config& config);
|
void publishConfig(const Nuki::Config& config);
|
||||||
void publishAdvancedConfig(const Nuki::AdvancedConfig& config);
|
void publishAdvancedConfig(const Nuki::AdvancedConfig& config);
|
||||||
|
|||||||
@@ -108,6 +108,8 @@ void NukiWrapper::update()
|
|||||||
char resultStr[15] = {0};
|
char resultStr[15] = {0};
|
||||||
Nuki::cmdResultToString(cmdResult, resultStr);
|
Nuki::cmdResultToString(cmdResult, resultStr);
|
||||||
|
|
||||||
|
_network->publishCommandResult(resultStr);
|
||||||
|
|
||||||
Serial.print(F("Lock action result: "));
|
Serial.print(F("Lock action result: "));
|
||||||
Serial.println(resultStr);
|
Serial.println(resultStr);
|
||||||
|
|
||||||
|
|||||||
@@ -14,11 +14,12 @@ Just enable pairing mode on the NUKI lock and power on the ESP32. Pairing should
|
|||||||
|
|
||||||
## MQTT Interface
|
## MQTT Interface
|
||||||
|
|
||||||
|
- lock/action: Allows to execute lock actions. After executing the action, the value is reset to an empty string. Possible actions: unlock, lock, unlatch, lockNgo, lockNgoUnlatch, fullLock, fobAction1, fobAction2, fobAction3
|
||||||
- lock/state: Reports the current lock state as a string. Possible values are: uncalibrated, locked, unlocked, unlatched, unlockedLnga, unlatching, bootRun, motorBlocked
|
- lock/state: Reports the current lock state as a string. Possible values are: uncalibrated, locked, unlocked, unlatched, unlockedLnga, unlatching, bootRun, motorBlocked
|
||||||
- lock/trigger: The trigger of the last action: autoLock, automatic, button, manual, system
|
- lock/trigger: The trigger of the last action: autoLock, automatic, button, manual, system
|
||||||
- lock/completionStatus: Status of the last action: success, motorBlocked, canceled, tooRecent, busy, lowMotorVoltage, clutchFailure, motorPowerFailure, incompleteFailure, invalidCode, otherError, unknown
|
- lock/completionStatus: Status of the last action as reported by NUKI lock (needs bluetooth connection): success, motorBlocked, canceled, tooRecent, busy, lowMotorVoltage, clutchFailure, motorPowerFailure, incompleteFailure, invalidCode, otherError, unknown
|
||||||
|
- lock/commandResult: Result of the last action as reported by NUKI library: success, failed, timeOut, working, notPaired, error, undefined
|
||||||
- lock/doorSensorState: State of the door sensor: unavailable, deactivated, doorClosed, doorOpened, doorStateUnknown, calibrating
|
- lock/doorSensorState: State of the door sensor: unavailable, deactivated, doorClosed, doorOpened, doorStateUnknown, calibrating
|
||||||
- lock/action: Allows to execute lock actions. After executing the action, the value is reset to an empty string. Possible actions: unlock, lock, unlatch, lockNgo, lockNgoUnlatch, fullLock, fobAction1, fobAction2, fobAction3
|
|
||||||
|
|
||||||
- battery/voltage: Reports the current battery voltage in Volts.
|
- battery/voltage: Reports the current battery voltage in Volts.
|
||||||
- battery/level: Battery level in percent
|
- battery/level: Battery level in percent
|
||||||
|
|||||||
Reference in New Issue
Block a user