# $Id$ #################################################################################################### # # 55_weco.pm # # Copyright: betateilchen ® # e-mail: fhem.development@betateilchen.de # # Based on an idea from Frank S. in fhem forum. # # 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; use Time::HiRes qw(gettimeofday); use HttpUtils; #################################################################################################### # # Main routines # #################################################################################################### sub weco_Initialize($) { my ($hash) = @_; $hash->{DefFn} = "weco_Define"; $hash->{UndefFn} = "weco_Undef"; $hash->{AttrList} = "disable:1,0 ". "wecoInterval:600,1800,3600 wecotest:true,false ". "wecohu wecote wecodp wecopr wecopcv wecopcf wecowd wecows wecowsbft wecowg wecopa ". "wecopai wecopaest wecouv wecosd wecosc wecovi wecoch wecocm wecocl wecodc wecoww ". $readingFnAttributes; } sub weco_Define($$$) { my ($hash, $def) = @_; my @a = split("[ \t][ \t]*", $def); return "syntax: define weco " if(int(@a) != 4 ); my $name = $hash->{NAME}; $hash->{helper}{stationid} = $a[2]; $hash->{helper}{password} = $a[3]; $hash->{helper}{softwareid} = 'fhem'; $hash->{helper}{url} = "http://interface.wetterarchiv.de/weather/"; Log3($name, 4, "weco $name: created"); readingsSingleUpdate($hash, "state", "defined",1); weco_send($hash); return undef; } sub weco_Undef($$) { my ($hash, $arg) = @_; RemoveInternalTimer($hash); return undef; } sub weco_send($) { my ($hash, $local) = @_; my $name = $hash->{NAME}; return if IsDisabled($name); $local = 0 unless(defined($local)); my $url = $hash->{helper}{url}; $url .= "?id=". $hash->{helper}{stationid}; $url .= "&pwd=". $hash->{helper}{password}; $url .= "&sid=". $hash->{helper}{softwareid}; $url .= "&dtutc=".strftime "%Y%m%d%H%M", gmtime; $url .= "&dt=". strftime "%Y%m%d%H%M", localtime; $attr{$name}{wecoInterval} = 600 if(AttrVal($name,"wecoInterval",0) < 600); RemoveInternalTimer($hash); my ($data, $d, $r, $o); my $a = $attr{$name}; while ( my ($key, $value) = each(%{$a}) ) { next if substr($key,0,4) ne 'weco'; next if substr($key,4,1) ~~ ["I"]; $key = substr($key,4,length($key)-4); ($d, $r, $o) = split(":", $value); if(defined($r)) { $o = (defined($o)) ? $o : 0; $value = ReadingsVal($d, $r, 0) + $o; } $data .= "&$key=$value"; } readingsBeginUpdate($hash); if(defined($data)) { readingsBulkUpdate($hash, "data", $data); Log3 ($name, 4, "weco $name data sent: $data"); $url .= $data; my $response = GetFileFromURL($url); readingsBulkUpdate($hash, "response", $response); Log3 ($name, 4, "weco $name server response: $response"); readingsBulkUpdate($hash, "state", "active"); } else { CommandDeleteReading(undef, "$name data"); CommandDeleteReading(undef, "$name response"); Log3 ($name, 4, "weco $name no data"); readingsBulkUpdate($hash, "state", "defined"); $attr{$name}{wecoInterval} = 60; } readingsEndUpdate($hash, 1); InternalTimer(gettimeofday()+$attr{$name}{wecoInterval}, "weco_send", $hash, 0) unless($local == 1); return; } 1; #################################################################################################### # # Documentation # #################################################################################################### # # Changelog: # # 2014-04-12 initial release # #################################################################################################### =pod =item helper =begin html

weco

    Define

      define <name> weco <stationId> <password>

      This module provides connection to www.wetter.com
      to send data from your own weather station.


    Set-Commands

      - not implemented -


    Get-Commands

      - not implemented -


    Attributes

    • readingFnAttributes

    • wecoInterval - Interval (seconds) to send data to www.wetter.com Will be adjusted to 600 if set to a value lower than 600.
    • wecotest - If set to "true" data will not be stored on server. Used for development and testing.
    • weco.... - Attribute name corresponding to parameter name from api. Each of this attributes contains information about weather data to be sent in format sensorName:readingName[:offset]
      Example: attr weco wecote outside:temperature will define the attribut wecote and
      reading "temperature" from device "outside" will be sent to network as paramater "te" (which indicates current temperature)
      Optional Parameter "offset" will be added to the read value (e.g. sometimes necessary to send dewpoint - use offset 273.15 if needed in Kelvin)


    Generated Readings/Events:

    • data - data string transmitted to www.wetter.com
    • response - response string received from server


    Author's notes

    • Find complete api description here
    • Have fun!

=end html =begin html_DE

weco

    Sorry, keine deutsche Dokumentation vorhanden.

    Die englische Doku gibt es hier: weco
=end html_DE =cut