2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-07 12:58:13 +00:00

mqtt2.template +ebus: changes to ebus, #122048

git-svn-id: https://svn.fhem.de/fhem/trunk@24753 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
Beta-User 2021-07-15 16:18:11 +00:00
parent 7d31ade2f6
commit d31a235139
3 changed files with 148 additions and 19 deletions

View File

@ -3389,24 +3389,25 @@ name:eBus_daemon_splitter
filter:TYPE=MQTT2_DEVICE
desc:Device containing all status messages from the ebus daemon itself<br>NOTE: acts also as a bridge device to split up the hardware on the bus into different mqtt2_devices<br>NOTE:<br>- for use with MQTT2_CLIENT use a copy of the Device with the same clientId than the IO, delete original's readingList after applying the template!<br>- this might change the devices CID
order:E_01a
par:DEVTYPE;Internal TYPE of the device; { InternalVal("DEVICE","TYPE",undef)}
par:DEV_ID;base topic set ebus;{ AttrVal("DEVICE","readingList","") =~ m,[^:]+:?(ebus[a-zA-Z][^/]*)[/].*:, ? $1 : "ebusd" }
par:DEVTYPE;Internal TYPE of the device; { InternalVal("DEVICE",'TYPE',undef)}
par:DEV_ID;base topic set ebus;{ AttrVal("DEVICE",'readingList','') =~ m,[^:]+:?(ebus[a-zA-Z][^/]*)[/].*:, ? $1 : 'ebusd' }
par:ICON;ICON as set, defaults to sani_boiler_temp;{ AttrVal("DEVICE","icon","sani_boiler_temp") }
{ Svn_GetFile("contrib/AttrTemplate/99_attrTmqtt2_ebus_Utils.pm", "FHEM/99_attrTmqtt2_ebus_Utils.pm", sub(){ CommandReload(undef, "99_attrTmqtt2_ebus_Utils") }) }
{ Svn_GetFile('contrib/AttrTemplate/99_attrTmqtt2_ebus_Utils.pm', 'FHEM/99_attrTmqtt2_ebus_Utils.pm', sub(){ CommandReload(undef, '99_attrTmqtt2_ebus_Utils') }) }
{ Svn_GetFile("contrib/AttrTemplate/mqtt2.ebus.template", "FHEM/lib/AttrTemplate/mqtt2.ebus.template", sub(){ AttrTemplate_Initialize() }) }
attr DEVICE icon ICON
modify DEVICE DEV_ID
attr DEVICE autocreate 1
attr DEVICE bridgeRegexp (ebus\S[^/]*?)/(bai|\d+|cc|e7f|ehp|f\d\d|hc|hc\d+|he.|hmu|hwc|mc|mc.\d|omu|omu.\d|pms|rcc|rcc.\d|sc|sdr_p|solar|ui|uih|v\d\d|v81.\d|vd\d|vl\d|vr_\d\d|zeo)/.*:.* "$1_$2"\
(ebus\S[^/]*?)/(global|broadcast|general|scan[^/]+)/.*:.* "$1"
attr DEVICE readingList DEV_ID/scan.\d+/.*:.* { $TOPIC =~ m,scan.(\d+)/,; json2nameValue($EVENT,"scan_${1}_") }\
attr DEVICE readingList DEV_ID/scan[^/]+/.*:.* { $TOPIC =~ m,scan.([^/]+)/,; FHEM::aTm2u_ebus::j2nv($EVENT,"scan_${1}_") }\
DEV_ID/global/uptime:.* uptime\
DEV_ID/global/running:.* running\
DEV_ID/global/version:.* version\
DEV_ID/global/signal:.* signal\
DEV_ID/global/updatecheck:.* updatecheck\
DEV_ID/global/scan:.* scan
attr DEVICE userReadings formatedUptime:uptime.* {my $m = ReadingsVal($name,"uptime",0)/60;; return sprintf "0 000 00:%02d", $m if $m < 60;; my $h = $m / 60;; $m %= 60;; return sprintf "0 000 %02d:%02d", $h, $m if $h < 24;; my $d = $h / 24;; $h %= 24;; return sprintf "0 %03d %02d:%02d", $d, $h, $m if $d <365;; my $y = $d / 365;; $d %= 365;; return sprintf "%d %03d %02d:%02d", $y, $d, $h, $m}
DEV_ID/global/scan:.* scan\
DEV_ID/broadcast/datetime:.* { FHEM::aTm2u_ebus::j2nv($EVENT) }
attr DEVICE userReadings formatedUptime:uptime.* {my $m = ReadingsVal($name,'uptime',0)/60; return sprintf '0 000 00:%02d', $m if $m < 60; my $h = $m / 60; $m %= 60; return sprintf '0 000 %02d:%02d', $h, $m if $h < 24; my $d = $h / 24; $h %= 24;; return sprintf '0 %03d %02d:%02d', $d, $h, $m if $d <365; my $y = $d / 365; $d %= 365; return sprintf '%d %03d %02d:%02d', $y, $d, $h, $m}
attr DEVICE stateFormat Status: \
1:running\
Signal: \
@ -3419,7 +3420,7 @@ set DEVICE getKnown
attr DEVICE comment NOTE: additional templates and code have been downloaded from svn (contrib).<br>Pls. inform the maintainer, if the bridgeRegexp doesn't fit to all of your devices connected to the bus.
farewell:template has been applied successfully. <br>NOTE: additional templates and code have been downloaded from svn (contrib). <br>To configure further parts of your ebus ecosystem, have a look at these templates and the <a href=https://wiki.fhem.de/wiki/EBUS-MQTT2">Wiki</a>.
attr DEVICE model eBus_daemon_splitter
setreading DEVICE attrTemplateVersion 20200824
setreading DEVICE attrTemplateVersion 20210715
###########################################

View File

@ -6,6 +6,7 @@ package FHEM::attrT_z2m_thermostat_Utils; ## no critic 'Package declaration'
use strict;
use warnings;
use JSON qw(decode_json);
#use Time::HiRes qw( gettimeofday );
#use List::Util qw( min max );
@ -29,9 +30,9 @@ BEGIN {
ReadingsVal
ReadingsNum
ReadingsAge
decode_json
json2nameValue
defs
Log3
)
);
}

View File

@ -1,23 +1,143 @@
##############################################
# $Id: attrTmqtt2_ebus_Utils.pm 2020-01-18 Beta-User $
# $Id: attrTmqtt2_ebus_Utils.pm 2021-07-15 Beta-User $
#
package main;
package FHEM::aTm2u_ebus; ## no critic 'Package declaration'
use strict;
use warnings;
sub
attrTmqtt2_ebus_Utils_Initialize
{
my $hash = shift;
return;
use JSON qw(decode_json);
use Scalar::Util qw(looks_like_number);
use GPUtils qw(GP_Import);
#-- Run before package compilation
BEGIN {
# Import from main context
GP_Import(
qw(
json2nameValue
AttrVal
InternalVal
CommandGet
CommandSet
readingsSingleUpdate
readingsBulkUpdate
readingsBeginUpdate
readingsEndUpdate
ReadingsVal
ReadingsNum
ReadingsAge
json2nameValue
defs
Log3
)
);
}
sub ::attrTmqtt2_ebus_Utils_Initialize { goto &Initialize }
sub ::attrTmqtt2_ebus_createBarView { goto &createBarView }
# initialize ##################################################################
sub Initialize {
my $hash = shift;
return;
}
# Enter you functions below _this_ line.
sub
attrTmqtt2_ebus_createBarView {
sub j2nv {
my $EVENT = shift // return;
my $pre = shift;
my $filt = shift;
my $not = shift;
$EVENT=~ s{[{]"value":\s("[^"]+")[}]}{$1}g;
return json2nameValue($EVENT, $pre, $filt, $not);
}
sub send_weekprofile {
my $name = shift;
my $wp_name = shift;
my $wp_profile = shift // return;
my $model = shift // ReadingsVal($name,'week','selected'); #selected,Mo-Fr,Mo-So,Sa-So? holiday to set actual $wday to sunday program?
my $topic = shift // AttrVal($name,'devicetopic','') . '/hcTimer.$wkdy/set ';
my $onLimit = shift // '20';
my $hash = $defs{$name};
my $wp_profile_data = CommandGet(undef,"$wp_name profile_data $wp_profile 0");
if ($wp_profile_data =~ m{(profile.*not.found|usage..profile_data..name)}xms ) {
Log3( $hash, 3, "[$name] weekprofile $wp_name: no profile named \"$wp_profile\" available" );
return;
}
my @Dl = ("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
my @D = ("Sun","Mon","Tue","Wed","Thu","Fri","Sat");
my $payload;
my @days = (0..6);
my $text = decode_json($wp_profile_data);
( $model, @days ) = split m{:}xms, $model;
(my $sec,my $min,my $hour,my $mday,my $mon,my $year,my $wday,my $yday,my $isdst) = localtime;
@days = ( $model eq 'Mo-Fr' || $model eq 'Mo-So' ) ? (1) : ($model eq 'Sa-So' || $model eq 'holiday' ) ? (0) : (0..6) if !@days;
for my $i (@days) {
$payload = q{};
my $pairs = 0;
my $onOff = 'off';
for my $j (0..20) {
my $time = '00:00';
if (defined $text->{$D[$i]}{time}[$j]) {
$time = $text->{$D[$i]}{time}[$j-1] // '00:00';
my $val = $text->{$D[$i]}{temp}[$j];
if ( $val eq $onOff || (looks_like_number($val) && _compareOnOff( $val, $onOff, $onLimit ) ) ) {
$time = '00:00' if !$j;
$payload .= qq{$time;;$text->{$D[$i]}{time}[$j];;};
$pairs++;
$val = $val eq 'on' ? 'off' : 'on';
}
}
while ( $pairs < 3 && !defined $text->{$D[$i]}{time}[$j] ) {
#fill up the three pairs with last time
$time = $text->{$D[$i]}{time}[$j-1];
$pairs++;
$payload .= qq{-:-;;-:-;;};
}
last if $pairs == 3;
}
if ( $model eq 'holiday' ) {
$payload .= 'selected';
CommandSet($defs{$name},"$name $Dl[$wday] $payload")
} else {
$payload .= $model;
CommandSet($defs{$name},"$name $Dl[$i] $payload");
}
}
readingsSingleUpdate( $defs{$name}, 'weekprofile', "$wp_name $wp_profile",1);
return;
}
sub _compareOnOff {
my $val = shift // return;
my $onOff = shift // return;
my $lim = shift;
if ( $onOff eq 'on' ) {
return $val < $lim;
} else {
return $val >= $lim;
}
return;
}
sub createBarView {
my ($val,$maxValue,$color) = @_;
$maxValue = $maxValue//100;
$color = $color//"red";
@ -38,6 +158,7 @@ attrTmqtt2_ebus_createBarView {
1;
__END__
=pod
=begin html
@ -47,14 +168,20 @@ attrTmqtt2_ebus_createBarView {
<b>Functions to support attrTemplates for ebusd</b><br>
</ul>
<ul>
<b>attrTmqtt2_ebus_createBarView</b><br>
<code>attrTmqtt2_ebus_createBarView($,$$)</code><br>
<li><b>aTm2u_ebus::j2nv</b><br>
<code>aTm2u_ebus::j2nv($,$$$)</code><br>
This ist just a wrapper to fhem.pl json2nameValue() to prevent the "_value" postfix. It will first clean the first argument by applying <code>$EVENT=~ s{[{]"value":\s("[^"]+")[}]}{$1}g;</code>.
</li>
<li><b>aTm2u_ebus::createBarView</b><br>
<code>aTm2u_ebus::createBarView($,$$)</code><br>
Parameters are
<ul>
<li>$value (required)</li>
<li>$maxvalue (optional), defaults to 100</li>
<li>$color, (optional), defaults to red</li>
</ul>
For compability reasons, function will also be exported as attrTmqtt2_ebus_createBarView(). Better use package version to call it...
</li>
</ul><br>
=end html
=cut