# $Id$ ############################################################################## # # 84_IOhomecontrolDevice.pm # Copyright by Dr. Boris Neubert # e-mail: omega at online dot de # # This file is part of fhem. # # Fhem 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. # # Fhem 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. # # You should have received a copy of the GNU General Public License # along with fhem. If not, see . # ############################################################################## package main; use strict; use warnings; sub IOhomecontrolDevice_Initialize($) { my ($hash) = @_; $hash->{DefFn} = "IOhomecontrolDevice_Define"; $hash->{SetFn} = "IOhomecontrolDevice_Set"; $hash->{parseParams} = 1; $hash->{AttrList} = "setCmds " . $readingFnAttributes; } sub IOhomecontrolDevice_Define($$) { # define IOhomecontrolDevice my ( $hash, $argref, undef ) = @_; my @def = @{$argref}; if ( $#def != 2 ) { my $msg = "wrong syntax: define IOhomecontrolDevice "; Log 2, $msg; return $msg; } my $name = $def[0]; my $master = $def[2]; my $interface = $defs{$master}; $hash->{"INTERFACE"} = $interface; if ( !defined($interface) || $interface->{TYPE} ne "IOhomecontrol" ) { return "No such IOhomecontrol interface: $master"; } else { return; } } sub IOhomecontrolDevice_getSetCmds($) { my $hash = shift; my $name = $hash->{NAME}; my $attr = AttrVal( $name, "setCmds", "" ); my ( undef, $setCmds ) = parseParams( $attr, "," ); return $setCmds; } sub IOhomecontrolDevice_runSceneByIdCallback($$$$) { my ( $hash, $httpParams, $err, $result ) = @_; my $name = $hash->{NAME}; my $interface = $hash->{INTERFACE}; my $id = $httpParams->{params}{id}; my $sn = $interface->{fhem}{".scenes"}->{$id}; if ( defined($err) ) { Log3 $hash, 2, "IOhomecontrolDevice $name: running scene id $id, name $sn, failed ($err)"; } else { Log3 $hash, 5, "IOhomecontrolDevice $name: running scene id $id, name $sn, completed"; readingsSingleUpdate( $hash, "state", $sn, 1 ); } } sub IOhomecontrolDevice_Set($$$) { my ( $hash, $argsref, undef ) = @_; my @a = @{$argsref}; return "set needs at least one parameter" if ( @a < 2 ); my $name = shift @a; my $cmd = shift @a; my $setCmds = IOhomecontrolDevice_getSetCmds($hash); my $usage = "Unknown argument $cmd, choose one of scene" . join( " ", ( keys %{$setCmds} ) ); if ( exists( $setCmds->{$cmd} ) ) { readingsSingleUpdate( $hash, "state", $cmd, 1 ); my $subst = $setCmds->{$cmd}; Log3 $hash, 5, "IOhomecontrolDevice $name: substitute set command $cmd by $subst"; ( $argsref, undef ) = parseParams($subst); @a = @{$argsref}; $cmd = shift @a; } if ( $cmd eq "scene" ) { if ($#a) { return "Command scene needs exactly one argument."; } else { my $id = $a[0]; my $interface = $hash->{INTERFACE}; return IOhomecontrol_setScene( $interface, $id, \&IOhomecontrolDevice_runSceneByIdCallback ); } } else { return $usage; } return undef; } ##################################### 1; =pod =item device =item summary control IOhomecontrol devices via IOhomecontrol interface =item summary_DE IOhomecontrol-Geräte mittels IOhomecontrol-Interface steuern =begin html

IOhomecontrolDevice

    Define

      define <name> IOhomecontrolDevice <interface>

      Defines an IOhomecontrol device. <interface> is the name of the IOhomecontrol interface device (gateway) that is used to communicate with the IOhomecontrol devices.

      Example:
        define shutter1 IOhomecontrolDevice myKLF200


    Set

      set <name> scene <id>

      Runs the scene identified by <id> which can be either the numeric id of the scene or the scene's name.

      Examples:
        set shutter1 scene 1
        set shutter1 scene "3.dz.roll2 100%"

      Scene names with blanks must be enclosed in double quotes.

    Attributes

    • setCmds: a comma-separated list of set command definitions. Every definition is of the form <shorthand>=<command>. This defines a new single-word command <shorthand> as a substitute for <command>.
      Example: attr shutter1 setCmds up=scene "3.dz.roll2 100%",down=scene "3.dz.roll2 0%"
      Substituted commands (and only these) are shown in the state reading. This is useful in conjunction with the devStateIcon attribute, e.g. attr shutter1 devStateIcon down:shutter_closed up:shutter_open.

    • readingFnAttributes


    Full example
      define myKLF200 IOhomecontrol KLF200 velux.local /opt/fhem/etc/veluxpw.txt
      attr myKLF200 verbose 5
      attr myKLF200 logTraffic 1

      define shutter1 IOhomecontrolDevice myKLF200
      attr shutter1 setCmds up=scene "3.dz.roll2 0%",down=scene "3.dz.roll2 100%"
      attr shutter1 webCmd up:down
      attr shutter1 devStateIcon down:shutter_closed up:shutter_open


=end html =cut