From 7c910412180a6ead882bc9c0abc8d72b60bd68fc Mon Sep 17 00:00:00 2001 From: sachag <> Date: Fri, 16 Jul 2010 13:50:34 +0000 Subject: [PATCH] Added support for Allnet 3076 ethernet attached dimmers. git-svn-id: https://svn.fhem.de/fhem/trunk@653 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/22_ALL3076.pm | 159 ++++++++++++++++++++++++++++++++++++++ fhem/docs/commandref.html | 45 +++++++++++ 2 files changed, 204 insertions(+) create mode 100644 fhem/FHEM/22_ALL3076.pm diff --git a/fhem/FHEM/22_ALL3076.pm b/fhem/FHEM/22_ALL3076.pm new file mode 100644 index 000000000..e6ac53bf5 --- /dev/null +++ b/fhem/FHEM/22_ALL3076.pm @@ -0,0 +1,159 @@ +################################################################ +# +# Copyright notice +# +# (c) 2010 Sacha Gloor (sacha@imp.ch) +# +# This script is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# The GNU General Public License can be found at +# http://www.gnu.org/copyleft/gpl.html. +# A copy is found in the textfile GPL.txt and important notices to the license +# from the author is found in LICENSE.txt distributed with these scripts. +# +# This script is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# This copyright notice MUST APPEAR in all copies of the script! +# +################################################################ + +############################################## +package main; + +use strict; +use warnings; +use Data::Dumper; +use LWP::UserAgent; +use HTTP::Request; + +sub +ALL3076_Initialize($) +{ + my ($hash) = @_; + + $hash->{SetFn} = "ALL3076_Set"; + $hash->{DefFn} = "ALL3076_Define"; + $hash->{AttrList} = "loglevel:0,1,2,3,4,5,6"; +} + +################################### +sub +ALL3076_Set($@) +{ + my ($hash, @a) = @_; + + return "no set value specified" if(int(@a) != 2); + return "Unknown argument $a[1], choose one of dim[1-100]% dimdown dimup on off toggle" if($a[1] eq "?"); + + my $v = $a[1]; + my $v2 = ""; + my $err_log=""; + + if(defined $a[2]) { $v2=$a[2]; } + + if($v eq "toggle") + { + if(defined $hash->{READINGS}{state}{VAL}) + { + if($hash->{READINGS}{state}{VAL} eq "off") + { + $v="on"; + } + else + { + $v="off"; + } + } + else + { + $v="off"; + } + } + Log GetLogLevel($a[0],2), "ALL3076 set @a"; + $err_log=ALL3076_execute($hash->{DEF},$v,$v2); + if($err_log ne "") + { + Log GetLogLevel($a[0],2), "ALL3076 ".$err_log; + } + + $hash->{CHANGED}[0] = $v.$v2; + $hash->{STATE} = $v.$v2; + $hash->{READINGS}{state}{TIME} = TimeNow(); + $hash->{READINGS}{state}{VAL} = $v.$v2; + return undef; +} +################################### +sub +ALL3076_execute($@) +{ + my ($target,$cmd,$cmd2) = @_; + my $URL=''; + my $log=''; + + if($cmd eq "on") + { + $URL="http://".$target."/r?r=0&s=1"; + } + elsif($cmd eq "off") + { + $URL="http://".$target."/r?r=0&s=0"; + } + elsif($cmd eq "dimdown") + { + # We switch it on first + $log.=ALL3076_execute($target,"on"); + $URL="http://".$target."/r?d=0"; + } + elsif($cmd eq "dimup") + { + # We switch it on first + $log.=ALL3076_execute($target,"on"); + $URL="http://".$target."/r?d=1"; + } + elsif(substr($cmd,0,3) eq "dim") + { + # We switch it on first + $log.=ALL3076_execute($target,"on"); + + my $proz=substr($cmd,3,length($cmd)-4); + my $proz_v=sprintf("%d",$proz*255/100); + + $URL="http://".$target."/r?d=".$proz_v; + } + elsif($cmd eq "on-old-for-timer") + { + sleep(1); # Todo + } + else + { + return($log); + } +# print "URL: $URL\n"; + my $agent = LWP::UserAgent->new(env_proxy => 1,keep_alive => 1, timeout => 30); + my $header = HTTP::Request->new(GET => $URL); + my $request = HTTP::Request->new('GET', $URL, $header); + my $response = $agent->request($request); + + $log.= "Can't get $URL -- ".$response->status_line + unless $response->is_success; + + return($log); +} + +sub +ALL3076_Define($$) +{ + my ($hash, $def) = @_; + my @a = split("[ \t][ \t]*", $def); + + return "Wrong syntax: use define ALL3076 " if(int(@a) != 3); + return undef; +} + +1; diff --git a/fhem/docs/commandref.html b/fhem/docs/commandref.html index a45b1c2d0..8dca62129 100644 --- a/fhem/docs/commandref.html +++ b/fhem/docs/commandref.html @@ -68,6 +68,7 @@ + +

ALL3076

+