From 59376b3abf7738f62062fcb0890c17c13a316c7e Mon Sep 17 00:00:00 2001 From: Beta-User <> Date: Tue, 2 May 2023 16:53:59 +0000 Subject: [PATCH] mqtt2.template: changes to Hoymiles inverter git-svn-id: https://svn.fhem.de/fhem/trunk@27513 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/lib/AttrTemplate/mqtt2.template | 9 +- .../AttrTemplate/99_attrT_Ahoy_Utils.pm | 85 +++++++++++++++++++ 2 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 fhem/contrib/AttrTemplate/99_attrT_Ahoy_Utils.pm diff --git a/fhem/FHEM/lib/AttrTemplate/mqtt2.template b/fhem/FHEM/lib/AttrTemplate/mqtt2.template index 2b98e0d40..c20437d1d 100644 --- a/fhem/FHEM/lib/AttrTemplate/mqtt2.template +++ b/fhem/FHEM/lib/AttrTemplate/mqtt2.template @@ -5572,10 +5572,13 @@ par:INVERTER_NR;INVERTER_NR - order nr. in your setup. Note: numbering starts wi par:RADIO_SINGLE;inverter has just one channel;{ undef } par:RADIO_DOUBLE;inverter has two channels;{ undef } par:RADIO_QUATTRO;inverter has four channels;{ undef } -par:ICON;ICON as set, defaults to solar;{ AttrVal('DEVICE','icon','solar') } +par:ICON;ICON as set, defaults to measure_photovoltaic_inst;{ AttrVal('DEVICE','icon','measure_photovoltaic_inst') } attr DEVICE icon ICON +{ Svn_GetFile('contrib/AttrTemplate/99_attrT_Ahoy_Utils.pm', 'FHEM/99_attrT_Ahoy_Utils.pm', sub(){ CommandReload(undef, '99_attrT_Ahoy_Utils') }) } deletereading -q DEVICE .*_.* +attr DEVICE webCmd : option:{ RADIO_SINGLE } +attr DEVICE devStateIcon {FHEM::attrT_Ahoy_Utils::devStateIcon($name,1)} attr DEVICE readingList INVERTERLONG_ID/available:.* available\ INVERTERLONG_ID/last_success:.* last_success\ INVERTERLONG_ID/ch0/U_AC:.* U_AC\ @@ -5603,6 +5606,7 @@ attr DEVICE readingList INVERTERLONG_ID/available:.* available\ INVERTERLONG_ID/ch1/YieldDay:.* YieldDay1\ INVERTERLONG_ID/ch1/YieldTotal:.* YieldTotal option:{ RADIO_DOUBLE } +attr DEVICE devStateIcon {FHEM::attrT_Ahoy_Utils::devStateIcon($name,2)} attr DEVICE readingList \ INVERTERLONG_ID/available:.* available\ INVERTERLONG_ID/last_success:.* last_success\ @@ -5637,6 +5641,7 @@ attr DEVICE readingList \ INVERTERLONG_ID/ch2/YieldDay:.* YieldDay2\ INVERTERLONG_ID/ch2/YieldTotal:.* YieldTotal2 option:{ RADIO_QUATTRO } +attr DEVICE devStateIcon {FHEM::attrT_Ahoy_Utils::devStateIcon($name)} attr DEVICE readingList \ INVERTERLONG_ID/available:.* available\ INVERTERLONG_ID/last_success:.* last_success\ @@ -5693,7 +5698,7 @@ attr DEVICE setList \ limit_pct:slider,2,1,100 BASE_ID/ctrl/limit/INVERTER_NR $EVTPART1 attr DEVICE setStateList on off attr DEVICE model hoymiles_microinverter_inverter -setreading DEVICE attrTemplateVersion 20230313 +setreading DEVICE attrTemplateVersion 20230502 # contributed by tpm88, https://forum.fhem.de/index.php/topic,94495.msg1251265.html#msg1251265 name:hoymiles_opendtu_hub_bridge diff --git a/fhem/contrib/AttrTemplate/99_attrT_Ahoy_Utils.pm b/fhem/contrib/AttrTemplate/99_attrT_Ahoy_Utils.pm new file mode 100644 index 000000000..9018db60c --- /dev/null +++ b/fhem/contrib/AttrTemplate/99_attrT_Ahoy_Utils.pm @@ -0,0 +1,85 @@ +############################################## +# $Id$ +# + +package FHEM::attrT_Ahoy_Utils; ## no critic 'Package declaration' + +use strict; +use warnings; + +use Color; +use GPUtils qw(GP_Import); + +## Import der FHEM Funktionen +#-- Run before package compilation +BEGIN { + + # Import from main context + GP_Import( + qw( + FW_makeImage + AttrVal + InternalVal + ReadingsVal + ReadingsNum + ReadingsAge + defs + ) + ); +} + +sub main::attrT_Ahoy_Utils_Initialize { goto &Initialize } + +# initialize ################################################################## +sub Initialize { + my $hash = shift; + return; +} + +# Enter you functions below _this_ line. + +sub devStateIcon { + my $devname = shift // return; + my $panels = shift // 4; + my $colors = shift // 0; + + return if !defined $defs{$devname}; + + my $ret = ReadingsNum($devname,'available',0); + $ret = $ret > 1 ? '10px-kreis-gruen' : isday() ? '10px-kreis-rot' :'10px-kreis-gelb'; + $ret = FW_makeImage($ret, 'edit_settings'); + my $col = substr(Color::pahColor(-10,50,70,ReadingsNum($devname,'temperature',0),$colors),0,6); + $ret .= FW_makeImage("sani_solar_temp\@$col",'file_unknown@grey'); + $ret .= ' '; + $ret .= ReadingsNum($devname,'temperature',0,1); + $ret .= ' °C
'; + $ret .= ReadingsNum($devname,'P_AC',0); + $ret .= ' W / '; + $ret .= ReadingsNum($devname,'YieldDay',0); + $ret .= ' Wh'; + + my $total = ReadingsNum($devname,'YieldTotal',0,1); + if ( $total > 0 ) { + $ret .= ' / '; + $ret .= $total; + $ret .= ' kWh'; + } + + for (1..$panels) { + $ret .= '
'; + $col = substr(Color::pahColor(0,50,100,ReadingsNum($devname,"Irradiation$_",0),$colors),0,6); + $ret .= FW_makeImage("solar\@$col",'file_unknown@grey'); + $ret .= ' '; + $ret .= ReadingsNum($devname,"P_DC$_",0); + $ret .= ' W / '; + $ret .= ReadingsNum($devname,"YieldDay$_",0); + $ret .= ' Wh'; + $total = ReadingsNum($devname,"YieldTotal$_",0,1); + if ( $total > 0 ) { + $ret .= ' / '; + $ret .= $total; + $ret .= ' kWh'; + } + } + return qq(

$ret

); +}