Seite 1 von 2

Notify on error via IFTTT

Verfasst: Sa 8. Apr 2017, 08:37
von larsan
Hi all!

I've made a small perl script which reads the Status field from robonect.
If it is 7 or 8 (error or lost loop signal) I send a request to IFTTT, which in turn sends a notification to my phone.

If anyone would like to use the script, tell me, and I'll make one with a small tutorial attached.

Re: Notify on error via IFTTT

Verfasst: Mo 10. Apr 2017, 09:18
von Gambit
Hello,

yes please provide some information :-)

Regards,
Gambit

Re: Notify on error via IFTTT

Verfasst: Mo 10. Apr 2017, 11:08
von larsan
The code is available here.

You'll also need an account at IFTTT.com, where you'll need to create a "maker" recipe.
If you need instructions on how, I'll try to take some screenshots. :)

Also, you need a computer/rasberry or similar which can schedule the script.
I'm using a Synology NAS for this, but a simple crontab on linux/mac should suffice.
On windows you'd probably use the task scheduler.

If anyone wants me to, I can try to extend the code further, allowing for the actual error message to be sent to the phone.

EDIT: The maker channel on IFTTT can notify via a vast number of services. Email, SMS, Slack-channel etc. Just pick the one you want. :)

Re: Notify on error via IFTTT

Verfasst: Mi 12. Apr 2017, 12:27
von larsan
Example notification via Slack:
fullsizeoutput_ba4.jpeg
fullsizeoutput_ba4.jpeg (35.74 KiB) 4484 mal betrachtet
In english: Shaun is charging. Battery level 44%.

Re: Notify on error via IFTTT

Verfasst: Do 13. Apr 2017, 15:02
von Gambit
Hello,

thanks for the input - I used it as a template sending now mover alert via PHP to Telegram :)

Regards,
Michael

Re: Notify on error via IFTTT

Verfasst: Do 13. Apr 2017, 15:07
von larsan
Cool

What's telegram?

Re: Notify on error via IFTTT

Verfasst: Sa 15. Apr 2017, 09:58
von pirni
Nice idea. I would like to have some more Information, on how you Do it, to send Status to telegram, if possible.
Do you created a bot or something?
@larsan it id the better WhatsApp for your Smartphone ;)

Re: Notify on error via IFTTT

Verfasst: Mi 19. Apr 2017, 14:13
von Gambit
Hello,

not really a bot - there is a telegram client for Linux available - so you can use your PI if available.
The code is more or less the same larsan provided. :-)
I scheduled it with cron every 4 minutes.

Code: Alles auswählen

#!/usr/bin/php
<?php

$status_code = array();

$status_code["0"]=" Status wird ermittelt";
$status_code["1"]=" parkt";
$status_code["2"]=" arbeitet";
$status_code["3"]=" sucht die Ladestation";
$status_code["4"]=" lädt";
$status_code["5"]=" sucht (wartet auf Umsetzen)";
$status_code["7"]=" braucht Hilfe - FEHLER!";
$status_code["8"]=" braucht Hilfe - Schleifensignal verloren!";
$status_code["16"]=" ist abgeschaltet";
$status_code["17"]=" schläft";

$url = "http://192.168.0.135/json?cmd=status";
$cURL = curl_init();
curl_setopt($cURL, CURLOPT_URL, $url);
curl_setopt($cURL, CURLOPT_HTTPGET, true);
curl_setopt($cURL, CURLOPT_RETURNTRANSFER, true);
curl_setopt($cURL, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    'Accept: application/json'
));

$result = curl_exec($cURL);
curl_close($cURL);

$back=json_decode($result,true);
$name = $back['name'];
$status = $back['status']['status'];
$all_back = $name.$status_code[$status];
$duration = $back['status']['duration']/60;
if ($duration<5 and $status==7) $ret=shell_exec("/home/pi/telegram_send_home.sh
'$all_back'");
?>
Cheers,
Gambit

Re: Notify on error via IFTTT

Verfasst: Do 20. Apr 2017, 08:46
von larsan
Nice. A real JSON-parser too. :)

Re: Notify on error via IFTTT

Verfasst: Fr 21. Apr 2017, 07:55
von pirni
Thanks a lot. Seems like i have to search for my old Rasp in the deeps of my cupboard, to reactivate it again :D