im Thread viewtopic.php?f=21&t=254 hat bezibaerchen den robonect in OpenHab eingebunden. Ich habe die Lösung versucht möglicht 1:1 in Openhab 2 zu übernehmen und dabei die Shellscripte loszuwerden .
In meinem Beispiel habe ich die IP von mir drin, die müsste überall angepasst werden.
In Services/http.cfg brauchen wir 2 neue Einträge:
Code: Alles auswählen
automowerCache.url=http://192.168.178.60/json?cmd=status
automowerCache.updateInterval=60000
automower.items:
Code: Alles auswählen
String AutoMowerStatus "Status [MAP(automowerinfo_status.map):%s]" <grass> {http="<[automowerCache:30000:JSONPATH($.status.status)]"}
String AutoMowerBattery "Batteriestatus (%)[%s]" <battery> {http="<[automowerCache:30000:JSONPATH($.status.battery)]"}
String AutoMowerMode "Modus [MAP(automowerinfo_mode.map):%s]" <movecontrol> {http="<[automowerCache:30000:JSONPATH($.status.mode)]"}
String AutoMowerHours "Betriebsstunden [%s]" <pressure> {http="<[automowerCache:30000:JSONPATH($.status.hours)]"}
String AutoMowerWifi "WiFi Signal (db) [%s]" <signal> {http="<[automowerCache:30000:JSONPATH($.wlan.signal)]"}
String AutoMowerNextRunD "Nächster Mähzeitpunkt [%s]" <calendar> {http="<[automowerCache:30000:JSONPATH($.timer.next.date)]"}
String AutoMowerNextRunT "Nächster Mähzeitpunkt [%s]" <clock> {http="<[automowerCache:30000:JSONPATH($.timer.next.time)]"}
String AutoMowerDuration "Dauer [%s]" <clock-on> {http="<[automowerCache:30000:JS(automower_duration.js)]"}
String AutoMowerModeHomeAutoEOD "Modus" <movecontrol> {http=">[*:GET:http://192.168.178.60/json?cmd=mode&mode=%2$s]"}
String AutoMowerJob "Mähen" <grass>
Die Logik zum Jobstart ist in rules gewandert:
automower.rules:
Code: Alles auswählen
import org.joda.time.*
rule "AutomowerStartJob"
when
Item AutoMowerJob received command
then
logDebug("automower", "AutomowerStartJob: Entering Rule with {}",receivedCommand.toString)
// only work for active commands
if( receivedCommand.toString == "1" ||
receivedCommand.toString == "2" ||
receivedCommand.toString == "3" ||
receivedCommand.toString == "4" ){
logDebug("automower", "AutomowerStartJob: Starting Job")
var Number runtime = Integer::parseInt(receivedCommand.toString)
var hour = now.getHourOfDay
var minute = now.getMinuteOfHour
var commandstring = "http://192.168.178.60/json?cmd=mode&mode=job&begin=" + hour + ":" + minute + "&end=" + (hour + runtime) + ":" + minute ;
logDebug("automower", "AutomowerStartJob: Sending: {}", commandstring )
var String result = sendHttpGetRequest(commandstring)
logDebug("automower", "AutomowerStartJob: Automower returned: {}", result)
// reset the button
AutoMowerJob.sendCommand("")
}
end
rule "AutoMowerModeHomeAutoEOD"
when
Item AutoMowerModeHomeAutoEOD received command
then
logDebug("automower", "AutoMowerModeHomeAutoEOD: Entering Rule with {}",receivedCommand.toString)
if( receivedCommand.toString == "auto" ||
receivedCommand.toString == "home" ||
receivedCommand.toString == "eod" ||
receivedCommand.toString == "man" ){
/*
* 0: Auto
* 1: Manuell
* 2: Home
* 3: Demo
*/
switch receivedCommand.toString {
case receivedCommand.toString == "auto": AutoMowerMode.sendCommand("0")
case receivedCommand.toString == "home": AutoMowerMode.sendCommand("2")
case receivedCommand.toString == "eod": AutoMowerMode.sendCommand("0")
case receivedCommand.toString == "man": AutoMowerMode.sendCommand("1")
}
// reset the button
AutoMowerModeHomeAutoEOD.sendCommand("")
}
end
eine JS transformation zur hübschen Aufbereitung der Sekunden der Duration
automower_duration.js
Code: Alles auswählen
(function(i) {
var ret = "";
var seconds = JSON.parse(input).status.duration;
var days = Math.floor(seconds/(24*60*60));
var restwodays = seconds % (24*60*60);
var hours = Math.floor(restwodays/(60*60));
var restwohours = restwodays % (60*60);
var minutes = Math.floor(restwohours/ 60);
var seconds = restwohours % 60;
var minutess = "" + minutes;
if(minutes<=9) minutess = "0"+minutes;
var secondss = "" + seconds;
if(seconds<=9) secondss = "0"+seconds;
if ( days > 0 ) ret = "" + days + "T ";
if ( hours > 0 ) ret = ret + hours + ":";
if ( minutes > 0 ) ret = ret + minutess + ":";
ret = ret + secondss + "";
return ret;
})(input)
automowerinfo_mode.map
Code: Alles auswählen
0=AUTO
1=Manuell
2=HOME
3=Demo
automowerinfo_status.map
Code: Alles auswählen
0=Schläft
1=Geparkt
2=Mäht
3=Sucht die Ladestation
4=Lädt
5=Sucht
7=Fehlerstatus
8=Schleifsignal verloren
16=Automower abgeschaltet
17=Automower schläft
Michael