Hallo,
ich habe mittlerweile etwas gebastelt:
98_wemo.pm
##############################################
package main;
BEGIN { push( @INC ); }
use strict;
use warnings;
use IO::Socket::INET;
use Switch;
use WebService::Belkin::WeMo::Device;
use WebService::Belkin::WeMo::Discover;
use Data::Dumper;
sub
wemo_Initialize($)
{
my ($hash) = @_;
$hash->{SetFn} = "wemo_Set";
$hash->{DefFn} = "wemo_Define";
$hash->{AttrList} = "remote_ip";
#print "##### Init #####\n";
#print Dumper $hash;
}
###################################
sub
wemo_Set($@)
{
my ($hash, @a) = @_;
my $rc = undef;
return "no set value specified" if(int(@a) < 2);
return "on off" if($a[1] eq "?");
shift @a;
my $command = shift @a;
Log 3, "wemo command: $command";
$rc = commitwemo($hash, $command);
if ($rc) {
$hash->{CHANGED}[0] = $command;
$hash->{STATE} = $command;
$hash->{READINGS}{state}{TIME} = TimeNow();
$hash->{READINGS}{state}{VAL} = $command;
};
return undef;
}
sub
wemo_Define($$)
{
my ($hash, $def) = @_;
my @a = split("[ \t][ \t]*", $def);
return undef;
}
sub commitwemo
{
my ($hash, $onoff) = @_;
my $name = $hash->{NAME};
#my $param = $onoff ? "on" : "off";
my $remote_ip = AttrVal($name, "remote_ip", '127.0.0.1');
my ($mywemo);
# flush after every write
$| = 1;
my $wemo = WebService::Belkin::WeMo::Device->new(ip => $remote_ip, db => '/etc/belkin.db');
if($onoff eq "on")
{
$wemo->on();
}
if($onoff eq "off")
{
$wemo->off();
}
#print "##### Set #####\n";
#print Dumper $hash;
return 1;
}
1;
Den Doku-Teil muss ich noch anpassen.
Voraussetzung: Die Perl-Belkin-WeMo-API-master installieren wie im vorherigen Posting verlinkt.
Syntax in der fhem.cfg:
define WemoTest wemo
attr WemoTest room z_frei
attr WemoTest remote_ip 192.168.3.141
attr WemoTest icon light_light_dim_100
Mein aktuelles Problem: Ich würde gerne beim FHEM-Start automatisch den aktuellen Status des WeMo-Switches auslesen - aber wie???
Viele Grüße
Peter