2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-10 09:16:53 +00:00

mqtt2.template: changes to z2m thermostat + myUtils

git-svn-id: https://svn.fhem.de/fhem/trunk@23376 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
Beta-User 2020-12-18 11:00:47 +00:00
parent 57c2b34697
commit 8ef0280be2
2 changed files with 51 additions and 19 deletions

View File

@ -789,7 +789,7 @@ filter:TYPE=MQTT2_DEVICE:FILTER=CID~zigbee.*
order:L_17 order:L_17
par:BASE_TOPIC;base topic set in configuration.yaml of the zigbee2mqtt bridge;{ AttrVal("DEVICE","devicetopic",AttrVal("DEVICE","readingList","")) =~ m,[\b]?([^/:]+)[/].+, ? $1 : undef } par:BASE_TOPIC;base topic set in configuration.yaml of the zigbee2mqtt bridge;{ AttrVal("DEVICE","devicetopic",AttrVal("DEVICE","readingList","")) =~ m,[\b]?([^/:]+)[/].+, ? $1 : undef }
par:DEV_ID;name of the device in the zigbee2mqtt bridge;{ AttrVal("DEVICE","devicetopic",AttrVal("DEVICE","readingList","")) =~ m,[^/]+[/]([^/:]+).*, ? $1 : undef } par:DEV_ID;name of the device in the zigbee2mqtt bridge;{ AttrVal("DEVICE","devicetopic",AttrVal("DEVICE","readingList","")) =~ m,[^/]+[/]([^/:]+).*, ? $1 : undef }
par:ICON;ICON as set, defaults to hm-cc-rt-dn;{ AttrVal("DEVICE","icon","hm-cc-rt-dn") } par:ICON;ICON as set, defaults to temp_control;{ AttrVal("DEVICE","icon","temp_control") }
attr DEVICE icon ICON attr DEVICE icon ICON
attr DEVICE devicetopic BASE_TOPIC/DEV_ID attr DEVICE devicetopic BASE_TOPIC/DEV_ID
attr DEVICE readingList $\DEVICETOPIC:.* { json2nameValue($EVENT,'',$JSONMAP) } attr DEVICE readingList $\DEVICETOPIC:.* { json2nameValue($EVENT,'',$JSONMAP) }
@ -810,7 +810,7 @@ attr DEVICE setStateList on off
attr DEVICE model zigbee2mqtt_eurotronic_spirit attr DEVICE model zigbee2mqtt_eurotronic_spirit
set DEVICE attrTemplate speechcontrol_type_thermostat set DEVICE attrTemplate speechcontrol_type_thermostat
deletereading -q DEVICE (?!associatedWith).* deletereading -q DEVICE (?!associatedWith).*
setreading DEVICE attrTemplateVersion 20201209 setreading DEVICE attrTemplateVersion 20201218
name:zigbee2mqtt_thermostat_with_weekrofile name:zigbee2mqtt_thermostat_with_weekrofile
desc: stub of a version for <a href="https://zigbee.blakadder.com/Moes_HY368-ZB.html">Model HY368-ZB manufactured by Moes</a> via zigbee2mqtt <br>Not yet tested... <br>To contribute, participate in <a href="https://forum.fhem.de/index.php/topic,116535.0.html">Forum Thread</a> desc: stub of a version for <a href="https://zigbee.blakadder.com/Moes_HY368-ZB.html">Model HY368-ZB manufactured by Moes</a> via zigbee2mqtt <br>Not yet tested... <br>To contribute, participate in <a href="https://forum.fhem.de/index.php/topic,116535.0.html">Forum Thread</a>
@ -818,7 +818,7 @@ filter:TYPE=MQTT2_DEVICE:FILTER=CID~zigbee.*
order:L_17a order:L_17a
par:BASE_TOPIC;base topic set in configuration.yaml of the zigbee2mqtt bridge;{ AttrVal("DEVICE","devicetopic",AttrVal("DEVICE","readingList","")) =~ m,[\b]?([^/:]+)[/].+, ? $1 : undef } par:BASE_TOPIC;base topic set in configuration.yaml of the zigbee2mqtt bridge;{ AttrVal("DEVICE","devicetopic",AttrVal("DEVICE","readingList","")) =~ m,[\b]?([^/:]+)[/].+, ? $1 : undef }
par:DEV_ID;name of the device in the zigbee2mqtt bridge;{ AttrVal("DEVICE","devicetopic",AttrVal("DEVICE","readingList","")) =~ m,[^/]+[/]([^/:]+).*, ? $1 : undef } par:DEV_ID;name of the device in the zigbee2mqtt bridge;{ AttrVal("DEVICE","devicetopic",AttrVal("DEVICE","readingList","")) =~ m,[^/]+[/]([^/:]+).*, ? $1 : undef }
par:ICON;ICON as set, defaults to hm-cc-rt-dn;{ AttrVal("DEVICE","icon","hm-cc-rt-dn") } par:ICON;ICON as set, defaults to temp_control;{ AttrVal("DEVICE","icon","temp_control") }
par:WPNAME;weekprofile attr value, defaults to device name;{ AttrVal("DEVICE","weekprofile","DEVICE") } par:WPNAME;weekprofile attr value, defaults to device name;{ AttrVal("DEVICE","weekprofile","DEVICE") }
farewell:template has been applied successfully. <br>NOTE: code has been downloaded from svn (contrib). <br>For use with weekprofile, additional configuration is needed! farewell:template has been applied successfully. <br>NOTE: code has been downloaded from svn (contrib). <br>For use with weekprofile, additional configuration is needed!
{ Svn_GetFile("contrib/AttrTemplate/99_attrT_z2m_thermostat_Utils.pm", "FHEM/99_attrT_z2m_thermostat_Utils.pm", sub(){ CommandReload(undef, "99_attrT_z2m_thermostat_Utils.pm") }) } { Svn_GetFile("contrib/AttrTemplate/99_attrT_z2m_thermostat_Utils.pm", "FHEM/99_attrT_z2m_thermostat_Utils.pm", sub(){ CommandReload(undef, "99_attrT_z2m_thermostat_Utils.pm") }) }
@ -833,6 +833,9 @@ attr DEVICE setList \
btnLock:LOCK,UNLOCK $\DEVICETOPIC/set {"child_lock": "$EVTPART1"}\ btnLock:LOCK,UNLOCK $\DEVICETOPIC/set {"child_lock": "$EVTPART1"}\
boost:noArg $\DEVICETOPIC/set {"preset": "boost"}\ boost:noArg $\DEVICETOPIC/set {"preset": "boost"}\
mode:schedule,manual,boost,complex,comfort,eco $\DEVICETOPIC/set {"preset": "$EVTPART1"}\ mode:schedule,manual,boost,complex,comfort,eco $\DEVICETOPIC/set {"preset": "$EVTPART1"}\
holidays $\DEVICETOPIC/set/schedule { "holidays":[$EVTPART1] }\
workdays $\DEVICETOPIC/set/schedule { "workdays":[$EVTPART1] }\
week:5+2,6+1,7 $\DEVICETOPIC/set $EVTPART1\
weekprofile { FHEM::attrT_z2m_thermostat_Utils::z2t_send_weekprofile($NAME, $EVTPART1, $EVTPART2) }\ weekprofile { FHEM::attrT_z2m_thermostat_Utils::z2t_send_weekprofile($NAME, $EVTPART1, $EVTPART2) }\
x_send_set_payload:textField { my $payload = $EVENT;$payload =~ s/$EVTPART0 //; qq($\DEVICETOPIC/set $payload)} x_send_set_payload:textField { my $payload = $EVENT;$payload =~ s/$EVTPART0 //; qq($\DEVICETOPIC/set $payload)}
attr DEVICE getList desired-temp:noArg desired-temp $\DEVICETOPIC/get {"current_heating_setpoint": ""}\ attr DEVICE getList desired-temp:noArg desired-temp $\DEVICETOPIC/get {"current_heating_setpoint": ""}\
@ -849,7 +852,7 @@ attr DEVICE setStateList on off
attr DEVICE model zigbee2mqtt_thermostat_with_weekrofile attr DEVICE model zigbee2mqtt_thermostat_with_weekrofile
set DEVICE attrTemplate speechcontrol_type_thermostat set DEVICE attrTemplate speechcontrol_type_thermostat
deletereading -q DEVICE (?!associatedWith).* deletereading -q DEVICE (?!associatedWith).*
setreading DEVICE attrTemplateVersion 20201215 setreading DEVICE attrTemplateVersion 20201218
########################################### ###########################################

View File

@ -1,5 +1,5 @@
############################################## ##############################################
# $Id: attrT_z2m_thermostat_Utils.pm 2020-12-10 Beta-User $ # $Id$
# #
package FHEM::attrT_z2m_thermostat_Utils; ## no critic 'Package declaration' package FHEM::attrT_z2m_thermostat_Utils; ## no critic 'Package declaration'
@ -21,6 +21,7 @@ BEGIN {
AttrVal AttrVal
InternalVal InternalVal
CommandGet CommandGet
CommandSet
readingsSingleUpdate readingsSingleUpdate
readingsBulkUpdate readingsBulkUpdate
readingsBeginUpdate readingsBeginUpdate
@ -58,8 +59,8 @@ sub z2t_send_weekprofile {
my $name = shift; my $name = shift;
my $wp_name = shift; my $wp_name = shift;
my $wp_profile = shift // return; my $wp_profile = shift // return;
my $topic = shift // AttrVal($name,'devicetopic','') . '/set';
my $model = shift // ReadingsVal($name,'week','5+2'); my $model = shift // ReadingsVal($name,'week','5+2');
my $topic = shift // AttrVal($name,'devicetopic','') . '/set';
my $hash = $defs{$name}; my $hash = $defs{$name};
$topic .= ' '; $topic .= ' ';
@ -70,21 +71,21 @@ sub z2t_send_weekprofile {
return; return;
} }
my @D = ("Sat","Sun","Mon","Tue","Wed","Thu","Fri"); my @D = ("Sun","Mon","Tue","Wed","Thu","Fri","Sat");
my $payload; my $payload;
my @days = (0..6); my @days = (0..6);
my $text = decode_json($wp_profile_data); my $text = decode_json($wp_profile_data);
if ( $model eq '5+2' || $model eq '6+1') { if ( $model eq '5+2' || $model eq '6+1') {
@days = (1,2); @days = (0,1);
$payload = '{"holidays":['; #$payload = '{"holidays":[';
} elsif ($model eq '7') { } elsif ($model eq '7') {
@days = (2); @days = (1);
$payload = '{"workdays":['; #$payload = '{"workdays":[';
} }
for my $i (@days) { for my $i (@days) {
$payload.='{'; $payload = '{';
for my $j (0..7) { for my $j (0..7) {
if (defined $text->{$D[$i]}{'time'}[$j]) { if (defined $text->{$D[$i]}{'time'}[$j]) {
@ -96,14 +97,17 @@ sub z2t_send_weekprofile {
} }
} }
$payload .='}'; $payload .='}';
if ($model eq '5+2' || $model eq '6+1') { if ( $i == 0 && ( $model eq '5+2' || $model eq '6+1') ) {
$payload .='},'if $i == 0 || $i > 1 && $i != $days[-1]; #$payload .='},'if $i == 0 || $i > 1 && $i != $days[-1];
$payload .='],"workdays":[' if $i == 1; #$payload .='],"workdays":[' if $i == 1;
CommandSet($defs{$name},"$name holidays $payload");
$payload = '{';
} }
CommandSet($defs{$name},"$name workdays $payload") if $model eq '5+2' || $model eq '6+1' || $model eq '7';
} }
$payload .=']}'; #$payload .=']}';
readingsSingleUpdate( $defs{$name}, 'weekprofile', "$wp_name $wp_profile",1); readingsSingleUpdate( $defs{$name}, 'weekprofile', "$wp_name $wp_profile",1);
return "$topic $payload"; return;
} }
@ -116,6 +120,31 @@ __END__
<a name="attrT_z2m_thermostat_Utils"></a> <a name="attrT_z2m_thermostat_Utils"></a>
<h3>attrT_z2m_thermostat_Utils</h3> <h3>attrT_z2m_thermostat_Utils</h3>
<ul>
<b>z2t_send_weekprofile</b>
<br>
This is a special function to request temperature list data from <i>weekprofile</i> and convert and send it out via MQTT<br>
<br>
General requirements and prerequisites:<br>
<ul>
<li>existing <i>weekprofile</i> device with activated <i>useTopic</i> feature</li>
<li>weekprofile attribute set at calling MQTT2_DEVICE</li>
</ul>
<br>
Special remarks for usage with attrTemplate <i>zigbee2mqtt_thermostat_with_weekrofile</i>:<br>
<ul>
<li>existing <i>setList</i> entries required (<i>workdays</i> and <i>holidays</i>)</li>
<li>for conversion from <i>weekprofile</i> data to entries <i>workdays</i> and <i>holidays</i> only monday and sunday data will be used, other days will be ignored</li>
<li>as parameters, <i>$name</i> (name of the calling MQTT2_DEVICE), <i>$wp_name</i> (name of the weekprofile device) and $wp_profile (in "topic:entity" format) have to be used, when topic changes are done via weekprofile, the relevent data will be sent to the MQTT2_DEVICE instances with suitable <i>weekprofile</i> attribute automatically.<br>
Additionally you may force sending holiday data by adding a forth parameter ($model) and set that to '5+2'.<br>
So entire Perl command for <i>zigbee2mqtt_thermostat_with_weekrofile</i> should look like:
<ul>
<code>FHEM::attrT_z2m_thermostat_Utils::z2t_send_weekprofile($NAME, $EVTPART1, $EVTPART2)</code><br>
</ul><br>or
<ul>
<code>FHEM::attrT_z2m_thermostat_Utils::z2t_send_weekprofile($NAME, $EVTPART1, $EVTPART2, '5+2')</code><br>
</ul>
</ul>
</ul>
=end html =end html
=cut =cut