Skip to content

Instantly share code, notes, and snippets.

@mamemomonga

mamemomonga/README.md

Last active Jul 27, 2020
Embed
What would you like to do?
IFTTTのWebHookをコマンドラインから実行する

IFTTT CLI

IFTTT Webhookを実行するperlスクリプトです。追加モジュールは必要ありませんが、curlが必要です。

WEBHOOK_KEY に自分のWebHook Keyを(Webhook KeyはWebHook画面の「Documentation」から確認できます)、 COMMANDS に サブコマンドとイベントを設定します。イベントは複数設定でき、連続して実行されます。

#!/usr/bin/perl
use strict;
use warnings;
use feature 'say';
# --------------------------
# WebHook Key
our $WEBHOOK_KEY='aaaaaaaaaaaaaaaaaaaaaa';
# Events
our @COMMANDS=(
{ cmd => 'acon', events => ['AC_ON']},
{ cmd => 'acoff', events => ['AC_OFF']},
{ cmd => 'lampon', events => ['LAMP1_ON']},
{ cmd => 'lampff', events => ['LAMP1_OFF']},
{ cmd => 'tvpwr', events => ['TV_PWR']},
{ cmd => 'plgon', events => ['PLUG1_ON']},
{ cmd => 'plgoff', events => ['PLUG1_OFF']},
{ cmd => 'on', events => ['AC_ON', 'LAMP1_ON', 'PLUG1_ON']},
{ cmd => 'off', events => ['AC_OFF','LAMP1_OFF', 'PLUG1_OFF']},
);
# curl
our $CURL_BIN='curl';
# --------------------------
sub usage {
say "[USAGE] $0 [cmd]";
say "[COMMAND] events";
foreach(@COMMANDS) {
printf(" %-10s %s\n",$_->{cmd},join(', ',@{$_->{events}}));
}
exit(1);
}
usage if($#ARGV == -1);
my $events=[];
foreach(@COMMANDS) {
$events=$_->{events} if ($_->{cmd} eq $ARGV[0]);
}
usage if($#{$events} == -1);
foreach(@{$events}) {
my @cmd=(
$CURL_BIN,
'-X',
'POST',
'https://maker.ifttt.com/trigger/'.$_.'/with/key/'.$WEBHOOK_KEY,
);
# say join(' ',@cmd);
system(@cmd) == 0 or die "Execute failed: $!";
say "";
sleep(1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment