Skip to content
This repository has been archived by the owner on Dec 19, 2021. It is now read-only.

Easier integration with Home Assistant and somme error fixing #61

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions HOME_ASSISTANT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
The mower can be incorporated into Home Assistant as a Vacuum, here is the example configuration:


# Home Assistant config:
```
...
vacuum:
- platform: mqtt
name: "My Landroid"
command_topic: "mylandroid/set/mow"
payload_turn_on: "start"
payload_turn_off: "stop"
battery_level_topic: "mylandroid/status/batteryLevel"
battery_level_template: "{{ value }}"
charging_topic: "mylandroid/status/batteryCharging"
charging_template: "{{ value }}"
docked_topic: "mylandroid/status/statusDescription"
docked_template: "{{ true if value == 'Home' else false }}"
error_topic: "mylandroid/status/statusDescription"
error_template: "{{ value }}"
json_attributes_topic: "mylandroid/status/jsonData"
...
```

# Corresponding landroid-bridge config:
```
...
"mqtt": {
"enable": true,
"url": "mqtt://<yourbroker>",
"topic": "mylandroid"
},
...
```
36 changes: 28 additions & 8 deletions src/LandroidDataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export class LandroidDataset {
statusCode: number;
statusDescription: string;
schedule: TimePeriod[];
jsonData: object;

constructor(readings: any) {
if (readings) {
Expand Down Expand Up @@ -59,7 +60,8 @@ export class LandroidDataset {
errorDescription: this.errorDescription,
statusCode: this.statusCode,
statusDescription: this.statusDescription,
schedule: this.schedule.map(timePeriod => timePeriod.serialize())
schedule: this.schedule.map(timePeriod => timePeriod.serialize()),
jsonData: JSON.stringify(this.jsonData)
};
}

Expand Down Expand Up @@ -88,29 +90,47 @@ export class LandroidDataset {
}
}
if (readings["dat"]) {
this.macAddress = readings["dat"]["mac"];
this.firmware = readings["dat"]["fw"];
this.wifiQuality = Number(readings["dat"]["rsi"]).valueOf();
this.statusCode = Number(readings["dat"]["ls"]).valueOf();
this.statusDescription = LandroidDataset.STATUS_CODES[this.statusCode];
this.errorCode = Number(readings["dat"]["le"]).valueOf();
this.errorDescription = LandroidDataset.ERROR_CODES[this.errorCode];
this.jsonData = {
wifiQuality: this.wifiQuality,
statusCode: this.statusCode,
statusDescription: this.statusDescription,
errorCode: this.errorCode,
errorDescription: this.errorDescription
};
if (readings["dat"]["st"]) {
this.totalTime = Number(readings["dat"]["st"]["wt"]).valueOf();
this.totalDistance = Number(readings["dat"]["st"]["d"]).valueOf();
this.totalBladeTime = Number(readings["dat"]["st"]["b"]).valueOf();
this.jsonData["totalTime"] = this.totalTime;
this.jsonData["totalDistance"] = this.totalDistance;
this.jsonData["totalBladeTime"] = this.totalBladeTime;
}
if (readings["dat"]["bt"]) {
this.batteryChargeCycle = Number(readings["dat"]["bt"]["nr"]).valueOf();
this.batteryCharging = (readings["dat"]["bt"]["c"] ? true : false);
this.batteryVoltage = Number(readings["dat"]["bt"]["v"]).valueOf();
this.batteryTemperature = Number(readings["dat"]["bt"]["t"]).valueOf();
this.batteryLevel = Number(readings["dat"]["bt"]["p"]).valueOf();
this.jsonData["batteryChargeCycle"] = this.batteryChargeCycle;
this.jsonData["batteryCharging"] = this.batteryCharging;
this.jsonData["batteryVoltage"] = this.batteryVoltage;
this.jsonData["batteryTemperature"] = this.batteryTemperature;
this.jsonData["batteryLevel"] = this.batteryLevel;
}
this.macAddress = readings["dat"]["mac"];
this.firmware = readings["dat"]["fw"];
this.wifiQuality = Number(readings["dat"]["rsi"]).valueOf();
this.statusCode = Number(readings["dat"]["ls"]).valueOf();
this.statusDescription = LandroidDataset.STATUS_CODES[this.statusCode];
this.errorCode = Number(readings["dat"]["le"]).valueOf();
this.errorDescription = LandroidDataset.ERROR_CODES[this.errorCode];
if (readings["dat"]["dmp"]) {
this.pitch = Number(readings["dat"]["dmp"][0]).valueOf();
this.roll = Number(readings["dat"]["dmp"][1]).valueOf();
this.yaw = Number(readings["dat"]["dmp"][2]).valueOf();
this.jsonData["pitch"] = this.pitch;
this.jsonData["roll"] = this.roll;
this.jsonData["yaw"] = this.yaw;
}
}
}
Expand Down
9 changes: 6 additions & 3 deletions src/LandroidS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ export class LandroidS {

private onMqttMessage(topic: string, payload: any): void {
try {
if(typeof payload !== "string") {
payload = payload.toString();
}
if (topic === "set/start") {
this.startMower();
} else if (topic === "set/stop") {
Expand All @@ -177,20 +180,20 @@ export class LandroidS {
} else if (payload === "stop") {
this.stopMower();
} else {
this.log.error("Invalid MQTT payload for topic %s", topic);
this.log.error("Invalid MQTT payload %s for topic %s", payload, topic);
}
} else if (topic === "set/rainDelay") {
this.setRainDelay(payload);
} else if (topic === "set/timeExtension") {
this.setTimeExtension(payload);
} else if (topic.startsWith("set/schedule/")) {
let weekday = parseInt(topic.substr("set/schedule/".length), 10);
this.setSchedule(weekday, String(payload));
this.setSchedule(weekday, payload);
} else {
this.log.error("Unknown MQTT topic: %s", topic);
}
} catch (e) {
this.log.error("Invalid MQTT payload for topic %s: %s", topic, e);
this.log.error("Invalid MQTT payload %s for topic %s", e, topic);
}
}

Expand Down