Calling a HTTP url from FHEM to trigger action

I need to call HTTP urls from FHEM for several things, like firing IR signals to my TV (see my post: https://kaistech.wordpress.com/2016/10/09/wifi-infrared-ir-remote-extension-using-esp8266/ ).
As far as I know, FHEM currently does not have a way to do this easily (HTTPMOD seems to be a bit too complicated for that).

My solution is based on a simple PERL script which is called directly from FHEM:

Script /home/pi/irhttp.pl:

#!/usr/bin/perl -w

use warnings;
use strict;
use Time::HiRes qw/time usleep/;
use Socket qw(:all);
use POSIX ":sys_wait_h";

use LWP::Simple;

#print $ARGV[0];
#print "\n";

my $url = 'http://192.168.2.114/ir?code=';
$url .= $ARGV[0];

my $content = get($url);
die "Can't GET $url" if (! defined $content);

Then make it executable: sudo chmod +x /home/pi/irhttp.pl

Now you can call it from FHEM e.g. from a DOIF like this:

define DOIF_Dummy_WohnzimmerTVMode DOIF ([Dummy_WohnzimmerTVMode]) ({system ("/home/pi/irhttp.pl 50153655 &")})

Note: Here I pass the a argument to the Perl script which is attached to the URL.

Advertisements

One thought on “Calling a HTTP url from FHEM to trigger action

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s