[Beta] Waschmaschinenstatus

Begonnen von traxanos, 27 Juli 2015, 23:50:40

Vorheriges Thema - Nächstes Thema

ReneH87

Hier mal mein Ansatz als eigenes Modul, mit nachfolgendem Notify als Trigger. Die Variablen "espInterval" (= Interval in welchem Daten von der Steckdose abgefragt werden), "configPowerOff" (=Leistung, wenn WaMa aus), "configPowerDone" (=Leistung, wenn WaMa fertig), "configWaitDone" (=Wartezeit, wenn Wert unter "configPowerDone" fällt. Danach wird nochmal geprüft, ob WaMa weiterhin unter diesem Schwellwert ist. Erst danach wird der Waschgang als fertig gemeldet.) sind im Device der Steckdose zu definieren.


Keller.Waschmaschine:P.* {
Waschmaschine_onNotify($NAME);
}



##############################################
# $Id: myUtilsTemplate.pm 7570 2015-01-14 18:31:44Z rudolfkoenig $
#
# Save this file as 99_myUtils.pm, and create your own functions in the new
# file. They are then available in every Perl expression.

package main;

use strict;
use warnings;
use POSIX;

sub
Waschmaschine_Utils_Initialize($$)
{
  my ($hash) = @_;
}

sub Waschmaschine_onNotify($) {
my ($Device) = @_;

my $espInterval = AttrVal($Device, "espInterval", "60");
my $configPowerOff = AttrVal($Device, "configPowerOff", "1");
my $configPowerDone = AttrVal($Device, "configPowerDone", "10");
my $configWaitDone = AttrVal($Device, "configWaitDone", "60");

my $maschineStatus = ReadingsVal($Device,"maschineStatus","off");
my $power = ReadingsVal($Device,"P",0);
my $consumption = ReadingsVal($Device,"consumption",0);
my $difTimeLastUpdate = time() - time_str2num(ReadingsTimestamp($Device, "consumption","2000-01-01 00:00:00"));

my $consumptionNew = sprintf("%.3f", $consumption) + sprintf("%.3f", $power * ($espInterval/3600));
if($difTimeLastUpdate > 1){
fhem('setreading '.$Device.' consumption '.$consumptionNew.';');

if($power < $configPowerOff && $maschineStatus ne "off") {
fhem('setreading '.$Device.' maschineStatus off;');
fhem('setreading '.$Device.' consumptionOnStart 0;');
} elsif($power >= $configPowerOff && $maschineStatus eq "off") {
fhem('setreading '.$Device.' maschineStatus on;');
fhem('setreading '.$Device.' consumptionOnStart '.$consumption.';');
} elsif ($power >= $configPowerDone && $maschineStatus ne "running") {
fhem('setreading '.$Device.' maschineStatus running;');
fhem("set chatBot _msg Die Waschmaschine wurde gestartet.");
} elsif ($power < $configPowerDone && $maschineStatus eq "running" && !functionExist("Waschmaschine_checkIfDone")) {
InternalTimer(gettimeofday() + $configWaitDone, "Waschmaschine_checkIfDone", $Device);
}
}
}

sub Waschmaschine_checkIfDone($) {
my ($Device) = @_;

my $power = ReadingsVal($Device,"P",0);
my $configPowerDone = AttrVal($Device, "configPowerDone", "10");
my $maschineStatus = ReadingsVal($Device,"maschineStatus","off");
my $consumptionOnStart = ReadingsVal($Device,"consumptionOnStart",0);
my $consumption = ReadingsVal($Device,"consumption",0);
my $lastPowerConsumption = $consumption - $consumptionOnStart;
my $duration = ReadingsVal($Device,"elapsedTime","0:00h");

my $currentHour = POSIX::strftime("%H",localtime(time));

if ($power < $configPowerDone && $maschineStatus eq "running") {
fhem('setreading '.$Device.' maschineStatus done;');
fhem("set chatBot _msg Die Waschmaschine ist nach ".$duration."h fertig. Es wurden ".sprintf("%.2f", $lastPowerConsumption/1000)."kWh verbraucht.");
if($currentHour > 8 && $currentHour < 23) {
googleBroadcast("Die Waschmaschine ist fertig.");
}
}
}


1;