Rolladensteureung mit zwei on-off devices

Begonnen von MarkraM, 20 September 2014, 21:18:18

Vorheriges Thema - Nächstes Thema

MarkraM

Hallo,
(Entschuldigung für mein Deutsch, es hatte schon besser sein gekonnt.)
Ich benutze schon eine lange Weile FHEM auf dem Pi. Jetzt möchte auch die Rolladen steuern. Ich fand so nicht direkt einen weg um zwei On-Off aktoren zu kombinieren in ein "UpDown" Device. Also hab ich selber was gebastelt. Ich weiß aber nicht ob ich auf dem richtigen Pfad bin und möchte deshalb dieses Forum wie Review Forum benutzen.
Fragen:
- gibt es vielleicht eine möglichkeit "OutOfTheBox" um dies zu machen?
- wie kann ich events von den On-Off aktoren beobachten um den State zu aktualisieren?
- gibt es eine unterstützte Möglichkeit um mehrere "UpDown" Devices zu kombinieren in ein "UpDown" Gruppe Device?
Viele Grüße,
Mark

package main;

use strict;
use warnings;

our %modules;

sub UpDown_Define($$);
sub UpDown_Initialize($);
sub UpDown_Parse($$);
sub UpDown_Set($@);
sub UpDown_Get($@);

// Combine 2 on-off devices into one "UpDow" device.

sub UpDown_Initialize($) {
my ($hash) = @_;

$hash->{Match}    = "^UpDown:";
$hash->{DefFn}    = "UpDown_Define";
$hash->{SetFn}    = "UpDown_Set";
$hash->{AttrList} =
    "IODev do_not_notify:1,0 ignore:0,1 dummy:0,1 "
  . "showtime:1,0 loglevel:0,1,2,3,4,5,6 ";
$hash->{STATE} = "Initialized";
return undef;
}

#############################
sub UpDown_Define($$) {
my ( $hash, $def ) = @_;
my @a = split( "[ \t][ \t]*", $def );
my $name = $hash->{NAME};
return "wrong syntax: define <name> UpDown UpDevice DownDevice RunningTime"
  if ( int(@a) != 5 );
my $id = join( ":", "UpDown", $a[0] );

$modules{UpDown}{defptr}{$id} = $hash;
$hash->{STATE}   = "Defined";
$hash->{UPDEVICE}   = "$a[2]";
$hash->{DOWNDEVICE} = "$a[3]";
$hash->{RUNNINGTIME} = "$a[4]";
    $hash->{STATE} = "up";

    unless ( defined( AttrVal( $name, "webCmd", undef ) ) ) {
        $attr{$name}{webCmd} = 'toggle:up:down';
    }
    unless ( defined( AttrVal( $name, "devStateIcon", undef ) ) ) {
        $attr{$name}{devStateIcon} =  'up:closeG:down down:close:up';
    }
    unless ( defined( AttrVal( $name, "icon", undef ) ) ) {
        $attr{$name}{icon} = 'close';
    }

return undef;
}

################################
sub UpDown_Set($@) {
my ( $hash, @a ) = @_;
return "no set value specified" if ( @a < 2 );

my $name    = $hash->{NAME};
my $upDevice   = $hash->{UPDEVICE},;
my $downDevice = $hash->{DOWNDEVICE};
my $runningTime = $hash->{RUNNINGTIME};
my $state = $hash->{STATE};
    my $cmd  = lc $a[1];

if ($cmd eq "up" || ($cmd eq "toggle" && $state eq "down")){
  fhem("set $downDevice off");
  fhem("set $upDevice on-for-timer $runningTime");
  $hash->{STATE} = "up";
} elsif ($cmd eq "down" || ($cmd eq "toggle" && $state eq "up")) {
  fhem("set $upDevice off");
  fhem("set $downDevice on-for-timer $runningTime");
  $hash->{STATE} = "down";
} else {
  return "Unknown argument $a[0], choose one of: "
  . join( " ", "toggle", "up", "down" );
}
}

1;