############################################## # $Id: 20_pilight_temp.pm 0.11 2015-03-29 Risiko $ # # Usage # # define pilight_temp # # Changelog # # V 0.10 2015-03-29 - initial beta version # V 0.11 2015-03-29 - FIX: $readingFnAttributes ############################################## package main; use strict; use warnings; use Time::HiRes qw(gettimeofday); use JSON; sub pilight_temp_Parse($$); sub pilight_temp_Define($$); sub pilight_temp_Fingerprint($$); sub pilight_temp_Initialize($) { my ($hash) = @_; $hash->{DefFn} = "pilight_temp_Define"; $hash->{Match} = "^PITEMP"; $hash->{ParseFn} = "pilight_temp_Parse"; $hash->{AttrList} = $readingFnAttributes; } ##################################### sub pilight_temp_Define($$) { my ($hash, $def) = @_; my @a = split("[ \t][ \t]*", $def); if(@a < 4) { my $msg = "wrong syntax: define pilight_temp "; Log3 undef, 2, $msg; return $msg; } my $me = $a[0]; my $protocol = $a[2]; my $id = $a[3]; $hash->{STATE} = "defined"; $hash->{PROTOCOL} = lc($protocol); $hash->{ID} = $id; #$attr{$me}{verbose} = 5; $modules{pilight_temp}{defptr}{lc($protocol)}{$me} = $hash; AssignIoPort($hash); return undef; } ########################################### sub pilight_temp_Parse($$) { my ($mhash, $rmsg, $rawdata) = @_; my $backend = $mhash->{NAME}; Log3 $backend, 4, "pilight_temp_Parse: RCV -> $rmsg"; my ($dev,$protocol,$id,$temp,$humidity,@args) = split(",",$rmsg); return () if($dev ne "PITEMP"); my $chash; foreach my $n (keys %{ $modules{pilight_temp}{defptr}{lc($protocol)} }) { my $lh = $modules{pilight_temp}{defptr}{$protocol}{$n}; next if ( !defined($lh->{ID}) ); if ($lh->{ID} eq $id) { $chash = $lh; last; } } return () if (!defined($chash->{NAME})); readingsBeginUpdate($chash); readingsBulkUpdate($chash,"state",$temp); readingsBulkUpdate($chash,"temperature",$temp); readingsBulkUpdate($chash,"humidity",$humidity) if (defined($humidity) && $humidity ne ""); readingsEndUpdate($chash, 1); return $chash->{NAME}; } 1; =pod =begin html

pilight_temp

    pilight_temp represents a temperature and humidity sensor receiving dat from pilight
    You have to define the base device pilight_ctrl first.
    Further information to pilight: http://www.pilight.org/
    Supported Sensors: http://wiki.pilight.org/doku.php/protocols#weather_stations

    Define
      define <name> pilight_temp protocol id

      Example:
        define myctrl pilight_temp alecto_wsd17 100

    Readings

    • state
      present the current temperature
    • temperature
      present the current temperature
    • humidity
      present the current humidity (if sensor support it)

=end html =cut