Last active
August 8, 2017 08:06
-
-
Save dinmammas/bb3594f3e9d42525a5a12538395bf479 to your computer and use it in GitHub Desktop.
Query Robonect-card for status/notify via IFTTT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# Above path to perl may need to be changed, depending on your env. Type "which perl" in a terminal to find out. | |
# Original script by Thomas Johansson | |
use strict; | |
use warnings; | |
my $statusnum = ""; | |
my $battery = "0"; | |
my $response = "YOUR_MOWER_NAME_HERE "; | |
my $errmsg = ""; | |
# I'm assuming that you've setup your robonect with a user and a pass. If not, do so. | |
my $getstring = "http://USER:PASS\@ADDRESS_TO_YOUR_SERVER/json?cmd=status"; | |
my $curl = `which curl`; | |
chomp($curl); | |
my $jsonstuff = `$curl -s $getstring`; | |
chomp($jsonstuff); | |
# Get status number | |
if ($jsonstuff =~ /.*status": \{"status": (\d{1,2}).*/) { | |
$statusnum = $1; | |
}; | |
# Get battery percentage | |
if ($jsonstuff =~ /."battery": (\d{1,3}).*/) { | |
$battery = $1; | |
}; | |
# Set response according to status number. | |
if ($statusnum eq "0") { | |
$response .= "har okänd status!"; | |
} elsif ($statusnum eq "1") { | |
$response .= "har parkerat!"; | |
} elsif ($statusnum eq "2") { | |
$response .= "klipper gräs!"; | |
} elsif ($statusnum eq "3") { | |
$response .= "söker efter laddstationen!"; | |
} elsif ($statusnum eq "4") { | |
$response .= "laddar batterierna!"; | |
} elsif ($statusnum eq "5") { | |
$response .= "söker efter grönbete!"; | |
} elsif ($statusnum eq "7") { | |
# Get error message | |
if ($jsonstuff =~ /."error_message": "(.+?)".*/) { | |
$errmsg = "Felmeddelande: " . $1; | |
}; | |
$response .= "har råkat ut för ett fel!"; | |
} elsif ($statusnum eq "8") { | |
$response .= "har tappat slingsignalen!"; | |
} elsif ($statusnum eq "16") { | |
$response .= "är avstängd!"; | |
} elsif ($statusnum eq "17") { | |
$response .= "sover gott!" | |
}; | |
# Send request to IFTTT on all statuses. If you want to send alerts for errors only, replace line 61 with this: if ($statusnum eq "7" || $statusnum eq "8") { | |
if ($statusnum ne "") { | |
my $cstatus = system("$curl -s -o /dev/null -X POST -H \"Content-Type: application/json\" -d '{\"value1\":\"$response\",\"value2\":\"$battery\",\"value3\":\"$errmsg\"}' https://maker.ifttt.com/trigger/NAME_OF_YOUR_EVENT_IN_MAKER_CHANNEK/with/key/YOUR_KEY_HERE"); | |
if ($cstatus ne "0") { | |
die("Could not post\n"); | |
} else { | |
exit(0); | |
}; | |
}; | |
# Statusnumbers: 0 = unknown status, 1 = parked, 2 = mowing, 3 = on it's way home, 4 = charging, 5 = on it's way out, 7 = error, 8 = loop signal lost, 16 = off, 17 = sleeping |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment