From 3c3e7e4a4fe0e621c88f7eeeb6ef0a0f22e870a8 Mon Sep 17 00:00:00 2001
From: Beta-User <>
Date: Mon, 28 Feb 2022 19:08:25 +0000
Subject: [PATCH] mqtt2.template: (and other) changes to jsonMap in tasmota
lights
git-svn-id: https://svn.fhem.de/fhem/trunk@25757 2b470e98-0d58-463d-a4d8-8e2adae1ed80
---
fhem/FHEM/lib/AttrTemplate/mqtt2.template | 125 ++++++++++----------
fhem/MAINTAINER.txt | 2 +-
fhem/contrib/RHASSPY/10_RHASSPY.pm | 137 +++++++---------------
3 files changed, 105 insertions(+), 159 deletions(-)
diff --git a/fhem/FHEM/lib/AttrTemplate/mqtt2.template b/fhem/FHEM/lib/AttrTemplate/mqtt2.template
index 1d86af18b..20048d483 100644
--- a/fhem/FHEM/lib/AttrTemplate/mqtt2.template
+++ b/fhem/FHEM/lib/AttrTemplate/mqtt2.template
@@ -1029,13 +1029,22 @@ name:tasmota_basic_state_power1
filter:TYPE=MQTT2_DEVICE
desc:Applies to Sonoff Basic, S20 using POWER1-topic for relay state
NOTE: The format the device is sending data will also be changed to lowercase!
NOTE: This template is intended to configure also channel one of multi-channel tasmota devices
order:A_01a
-par:CMNDTOPIC;Command topic prefix, without trailing /;{ AttrVal("DEVICE","readingList","") =~ m,([^:]*)\b(tele|cmnd|stat)(/.*)?/LWT:, ? "${1}cmnd$3" : undef }
-par:TELETOPIC;info topic prefix, without trailing /;{ AttrVal("DEVICE","readingList","") =~ m,([^:]*)\b(tele|cmnd|stat)(/.*)?/LWT:, ? "${1}tele$3" : undef }
-par:STATTOPIC;ack topic prefix, without trailing /;{ AttrVal("DEVICE","readingList","") =~ m,([^:]*)\b(tele|cmnd|stat)(/.*)?/LWT:, ? "${1}stat$3" : undef }
-par:CALLSPEECHRECOGN;Set this to 0 to not set any speech recogn. related attributes;{ 1 }
-par:ICON;ICON as set, defaults to hue_filled_outlet;{ AttrVal("DEVICE","icon","hue_filled_outlet") }
+par:CMNDTOPIC;Command topic prefix, without trailing /;{ AttrVal('DEVICE','readingList','') =~ m,([^:]*)\b(tele|cmnd|stat)(/.*)?/LWT:, ? "${1}cmnd$3" : undef }
+par:TELETOPIC;info topic prefix, without trailing /;{ AttrVal('DEVICE','readingList','') =~ m,([^:]*)\b(tele|cmnd|stat)(/.*)?/LWT:, ? "${1}tele$3" : undef }
+par:STATTOPIC;ack topic prefix, without trailing /;{ AttrVal('DEVICE','readingList','') =~ m,([^:]*)\b(tele|cmnd|stat)(/.*)?/LWT:, ? "${1}stat$3" : undef }
+par:CALLSPEECHRECOGN;Set this to 0 to not set any speech recogn. related attributes;{ 1 }
+par:JSONMAPTYPE;Set this to suitable type, one of 1 (default), 2 (rgbw), 3 (rgbcct), 4 (pure dimmer);{ 1 }
+par:ICON;ICON as set, defaults to hue_filled_outlet;{ AttrVal('DEVICE','icon','hue_filled_outlet') }
attr DEVICE icon ICON
-attr DEVICE jsonMap POWER1:0 POWER2:0 POWER3:0 POWER4:0 Dimmer:0 Channel_0:0 Channel_1:0 Channel_2:0 Channel_3:0 Channel_4:0 HSBColor:0 Color:0
+option:{ JSONMAPTYPE == 1 }
+attr DEVICE jsonMap POWER1:0 POWER2:0 POWER3:0 POWER4:0 Dimmer:0 Channel_0:0 Channel_1:0 Channel_2:0 Channel_3:0 Channel_4:0 Channel_5:0 HSBColor:0 Color:0
+option:{ JSONMAPTYPE == 2 }
+attr DEVICE jsonMap POWER1:0 POWER2:0 POWER3:0 POWER4:0 Dimmer:pct Channel_0:0 Channel_1:0 Channel_2:0 Channel_3:0 Channel_4:0 Channel_5:0 HSBColor:0 Color:rgb
+option:{ JSONMAPTYPE == 3 }
+attr DEVICE jsonMap POWER1:0 POWER2:0 POWER3:0 POWER4:0 Dimmer:pct Channel_0:0 Channel_1:0 Channel_2:0 Channel_3:0 HSBColor:0 Channel_5:0 Color:rgb Channel_4:white
+option:{ JSONMAPTYPE == 4 }
+attr DEVICE jsonMap POWER1:0 POWER2:0 POWER3:0 POWER4:0 Dimmer:pct Channel_0:0 Channel_1:0 Channel_2:0 Channel_3:0 Channel_4:0 Channel_5:0 HSBColor:0 Color:0
+option:global
set DEVICE attrTemplate tasmota_set_lowercase_texts_and_state1
attr DEVICE setList \
off:noArg CMNDTOPIC/POWER1 0\
@@ -1171,15 +1180,13 @@ name:tasmota_plug_with_rgbw_split
filter:TYPE=MQTT2_DEVICE:FILTER=readingList=.*(tele|cmnd|stat).*
desc:plug with seperate RGBW LED flashed with Tasmota.
NOTE: a second device will be created for the rgb device.
Tested with Tasmota V. 7.1.2 and Maxcio YX-DE02 Plug using template: {"NAME":"Maxcio YX-DE04","GPIO":[255,17,255,21,56,40,0,0,37,38,39,255,255],"FLAG":1,"BASE":18}
order:A_01c1a
-set DEVICE attrTemplate tasmota_basic_state_power1 CALLSPEECHRECOGN=0
-par:CMNDTOPIC;Command topic prefix, without trailing /;{ AttrVal("DEVICE","readingList","") =~ m,([^:]*)\b(tele|cmnd|stat)(/.*)?/LWT:, ? "${1}cmnd$3" : undef }
-par:TELETOPIC;info topic prefix, without trailing /;{ AttrVal("DEVICE","readingList","") =~ m,([^:]*)\b(tele|cmnd|stat)(/.*)?/LWT:, ? "${1}tele$3" : undef }
-par:STATTOPIC;ack topic prefix, without trailing /;{ AttrVal("DEVICE","readingList","") =~ m,([^:]*)\b(tele|cmnd|stat)(/.*)?/LWT:, ? "${1}stat$3" : undef }
+set DEVICE attrTemplate tasmota_basic_state_power1 CALLSPEECHRECOGN=0 JSONMAPTYPE=2
+par:CMNDTOPIC;Command topic prefix, without trailing /;{ AttrVal('DEVICE','readingList','') =~ m,([^:]*)\b(tele|cmnd|stat)(/.*)?/LWT:, ? "${1}cmnd$3" : undef }
+par:TELETOPIC;info topic prefix, without trailing /;{ AttrVal('DEVICE','readingList','') =~ m,([^:]*)\b(tele|cmnd|stat)(/.*)?/LWT:, ? "${1}tele$3" : undef }
+par:STATTOPIC;ack topic prefix, without trailing /;{ AttrVal('DEVICE','readingList','') =~ m,([^:]*)\b(tele|cmnd|stat)(/.*)?/LWT:, ? "${1}stat$3" : undef }
attr DEVICE comment Mains channel for DEVICE, see also DEVICE_CH2 for rgb LED
attr DEVICE devStateIcon {my $onl = ReadingsVal($name,"LWT","false") eq "Online"?"10px-kreis-gruen":"10px-kreis-rot"; my $light = ReadingsVal($name,"state","off");"".FW_makeImage($onl)." ".FW_makeImage($light)." uptime: ".ReadingsVal($name,"Uptime",undef)}
-attr DEVICE jsonMap POWER1:0 Dimmer:0 Channel_1:0 Channel_2:0 Channel_3:0 HSBColor:0 POWER2:0
setreading DEVICE associatedWith DEVICE_CH2
-deletereading -q DEVICE (?!associatedWith|IODev).*
copy DEVICE DEVICE_CH2
deleteattr DEVICE_CH2 stateFormat
attr DEVICE_CH2 comment RGBW channel for DEVICE
@@ -1188,7 +1195,7 @@ attr DEVICE_CH2 setList \
off:noArg CMNDTOPIC/POWER2 0\
on:noArg CMNDTOPIC/POWER2 1\
toggle:noArg CMNDTOPIC/POWER2 2\
- Color:colorpicker,RGB CMNDTOPIC/COLOR\
+ rgb:colorpicker,RGB CMNDTOPIC/COLOR\
pct:colorpicker,BRI,0,5,100 CMNDTOPIC/DIMMER\
white:colorpicker,BRI,0,5,100 { "CMNDTOPIC/COLOR ". sprintf("000000%02X",$EVTPART1*2.55) }\
dimup:noArg { my $num=int((ReadingsNum($NAME,'pct',0)+4)/10)*10+10; return qq {CMNDTOPIC/Dimmer $num}; }\
@@ -1197,16 +1204,16 @@ attr DEVICE_CH2 readingList \
STATTOPIC/RESULT:.* { json2nameValue($EVENT,'',$JSONMAP) }\
STATTOPIC/POWER2:.* state
attr DEVICE_CH2 jsonMap POWER2:0 Dimmer:pct Channel_4:white Channel_1:0 Channel_2:0 Channel_3:0 HSBColor:0 POWER1:0 Heap:0 LedTable:0 LoadAvg:0 MqttCount:0 SaveData:0 Scheme:0 SetOption26:0 Sleep:0 SleepMode:0 Speed:0 StateText1:0 StateText2:0 StateText3:0 StateText4:0 Time:0 Uptime:0 UptimeSec:0 Wifi_SSId:0 Wifi_RSSI:0 Wifi_LinkCount:0 Wifi_Downtime:0 Wifi_Channel:0 Wifi_BSSId:0 Wifi_AP:0 ANALOG_A0:0 SetOption26:0 Sleep:0 SleepMode:0 Speed:0 StateText1:0 StateText2:0 StateText3:0 StateText4:0 Time:0 Uptime:0 UptimeSec:0 Wifi_SSId:0 Wifi_RSSI:0 Wifi_LinkCount:0 Wifi_Downtime:0 Wifi_Channel:0 Wifi_BSSId:0 Wifi_AP:0 ANALOG_A0:0
-attr DEVICE_CH2 webCmd pct:white:Color
+attr DEVICE_CH2 webCmd pct:white:rgb
attr DEVICE_CH2 webCmdLabel Helligkeit\
:Weiss\
:Farbe:
-attr DEVICE_CH2 devStateIcon {Color::devStateIcon($name,"rgb","Color","pct","state")}
+attr DEVICE_CH2 devStateIcon {Color::devStateIcon($name,'rgb','rgb','pct','state')}
attr DEVICE_CH2 setStateList on off toggle
deletereading -q DEVICE_CH2 (?!associatedWith|IODev).*
set DEVICE,DEVICE_CH2 attrTemplate speechcontrol_type_switch
attr DEVICE,DEVICE_CH2 model tasmota_plug_with_rgbw_split
-setreading DEVICE,DEVICE_CH2 attrTemplateVersion 20210903
+setreading DEVICE,DEVICE_CH2 attrTemplateVersion 20220228
#tasmota device with Infrared-circuit
name:tasmota_ir
@@ -1991,38 +1998,34 @@ name:tasmota_rgb_led_controller
filter:TYPE=MQTT2_DEVICE:FILTER=readingList=.*(tele|cmnd|stat).*
desc:Tasmota RGB controller tested with RGB variant of Magichome, arilux LC-01 ,etc... -> https://github.com/arendst/Sonoff-Tasmota/wiki/MagicHome-LED-strip-controller
order:A_05a
-set DEVICE attrTemplate tasmota_basic_state_power1
-par:CMNDTOPIC;Command topic prefix, without trailing /;{ AttrVal("DEVICE","readingList","") =~ m,([^:]*)\b(tele|cmnd|stat)(/.*)?/LWT:, ? "${1}cmnd$3" : undef }
-par:TELETOPIC;info topic prefix, without trailing /;{ AttrVal("DEVICE","readingList","") =~ m,([^:]*)\b(tele|cmnd|stat)(/.*)?/LWT:, ? "${1}tele$3" : undef }
-par:STATTOPIC;ack topic prefix, without trailing /;{ AttrVal("DEVICE","readingList","") =~ m,([^:]*)\b(tele|cmnd|stat)(/.*)?/LWT:, ? "${1}stat$3" : undef }
-par:ICON;ICON as set, defaults to light_control;{ AttrVal("DEVICE","icon","light_control") }
-attr DEVICE icon ICON
+set DEVICE attrTemplate tasmota_basic_state_power1 CALLSPEECHRECOGN=0 JSONMAPTYPE=2 \ICON=ICON
+par:CMNDTOPIC;Command topic prefix, without trailing /;{ AttrVal('DEVICE','readingList','') =~ m,([^:]*)\b(tele|cmnd|stat)(/.*)?/LWT:, ? "${1}cmnd$3" : undef }
+par:TELETOPIC;info topic prefix, without trailing /;{ AttrVal('DEVICE','readingList','') =~ m,([^:]*)\b(tele|cmnd|stat)(/.*)?/LWT:, ? "${1}tele$3" : undef }
+par:STATTOPIC;ack topic prefix, without trailing /;{ AttrVal('DEVICE','readingList','') =~ m,([^:]*)\b(tele|cmnd|stat)(/.*)?/LWT:, ? "${1}stat$3" : undef }
+par:ICON;ICON as set, defaults to light_control;{ AttrVal('DEVICE','icon','light_control') }
attr DEVICE setList\
off:noArg CMNDTOPIC/POWER1 0\
on:noArg CMNDTOPIC/POWER1 1\
toggle:noArg CMNDTOPIC/POWER1 2\
rgb:colorpicker,RGB CMNDTOPIC/COLOR\
pct:colorpicker,BRI,0,5,100 CMNDTOPIC/DIMMER
-deletereading -q DEVICE (?!associatedWith|IODev).*
attr DEVICE autocreate 0
-attr DEVICE devStateIcon {Color::devStateIcon($name,"rgb","rgb","pct","state")}
+attr DEVICE devStateIcon {Color::devStateIcon($name,'rgb','rgb','pct','state')}
attr DEVICE webCmd rgb:rgb ff0000:rgb 00ff00:rgb 0000ff:toggle:on:off
-attr DEVICE jsonMap POWER1:0 POWER2:0 POWER3:0 POWER4:0 Dimmer:pct Channel_0:0 Channel_1:0 Channel_2:0 Channel_3:0 Channel_4:0 HSBColor:0 Color:rgb
set DEVICE attrTemplate speechcontrol_type_light
attr DEVICE model tasmota_rgb_led_controller
-setreading DEVICE attrTemplateVersion 20220225
+setreading DEVICE attrTemplateVersion 20220228
name:tasmota_rgbw_led
filter:TYPE=MQTT2_DEVICE:FILTER=readingList=.*(tele|cmnd|stat).*
desc:Tasmota RGBW bulb or RGBW LED controller
order:A_05a1
-set DEVICE attrTemplate tasmota_basic_state_power1
-par:CMNDTOPIC;Command topic prefix, without trailing /;{ AttrVal("DEVICE","readingList","") =~ m,([^:]*)\b(tele|cmnd|stat)(/.*)?/LWT:, ? "${1}cmnd$3" : undef }
-par:TELETOPIC;info topic prefix, without trailing /;{ AttrVal("DEVICE","readingList","") =~ m,([^:]*)\b(tele|cmnd|stat)(/.*)?/LWT:, ? "${1}tele$3" : undef }
-par:STATTOPIC;ack topic prefix, without trailing /;{ AttrVal("DEVICE","readingList","") =~ m,([^:]*)\b(tele|cmnd|stat)(/.*)?/LWT:, ? "${1}stat$3" : undef }
-par:ICON;ICON as set, defaults to light_control;{ AttrVal("DEVICE","icon","light_control") }
-attr DEVICE icon ICON
-deletereading -q DEVICE (?!associatedWith|IODev).*
+set DEVICE attrTemplate tasmota_basic_state_power1 CALLSPEECHRECOGN=0 \JSONMAPTYPE=JSONMAPTYPE \ICON=ICON
+par:CMNDTOPIC;Command topic prefix, without trailing /;{ AttrVal('DEVICE','readingList','') =~ m,([^:]*)\b(tele|cmnd|stat)(/.*)?/LWT:, ? "${1}cmnd$3" : undef }
+par:TELETOPIC;info topic prefix, without trailing /;{ AttrVal('DEVICE','readingList','') =~ m,([^:]*)\b(tele|cmnd|stat)(/.*)?/LWT:, ? "${1}tele$3" : undef }
+par:STATTOPIC;ack topic prefix, without trailing /;{ AttrVal('DEVICE','readingList','') =~ m,([^:]*)\b(tele|cmnd|stat)(/.*)?/LWT:, ? "${1}stat$3" : undef }
+par:JSONMAPTYPE;Set to suitable type, 2 (rgbw);{ 2 }
+par:ICON;ICON as set, defaults to light_control;{ AttrVal('DEVICE','icon','light_control') }
attr DEVICE setList\
off:noArg CMNDTOPIC/POWER1 0\
on:noArg CMNDTOPIC/POWER1 1\
@@ -2031,7 +2034,7 @@ attr DEVICE setList\
pct:colorpicker,BRI,0,5,100 CMNDTOPIC/DIMMER\
dimup:noArg { my $num=int((ReadingsNum($NAME,'pct',0)+4)/10)*10+10; return qq {CMNDTOPIC/Dimmer $num}; }\
dimdown:noArg { my $num=int((ReadingsNum($NAME,'pct',0)+7)/10)*10-10; return qq {CMNDTOPIC/Dimmer $num}; }\
- white:colorpicker,BRI,0,5,100 { "CMNDTOPIC/COLOR ". sprintf("000000%02X",$EVTPART1*2.55) }\
+ white:colorpicker,BRI,0,5,100 { 'CMNDTOPIC/COLOR '. sprintf("000000%02X",$EVTPART1*2.55) }\
saturation:colorpicker,BRI,0,1,100 CMNDTOPIC/HSBCOLOR2\
Speed:colorpicker,BRI,0,1,20 CMNDTOPIC/SPEED\
Fade:uzsuSelect,ON,OFF CMNDTOPIC/FADE $EVTPART1\
@@ -2043,59 +2046,54 @@ attr DEVICE readingList \
TELETOPIC/INFO.:.* { $EVENT =~ m,^..Info[1-3]..(.+).$, ? json2nameValue($1,'',$JSONMAP) : json2nameValue($EVENT,'',$JSONMAP) }\
TELETOPIC/UPTIME:.* { json2nameValue($EVENT,'',$JSONMAP) }\
STATTOPIC/RESULT:.* { json2nameValue($EVENT,'',$JSONMAP) }\
- STATTOPIC/RESULT:.* { $EVENT =~ m,HSBColor...(\d+)\,(\d+)\,(\d+), ? $2 eq ReadingsVal($NAME,"saturation","unknown") ? return : { "saturation"=>$2 } : return }\
+ STATTOPIC/RESULT:.* { $EVENT =~ m,HSBColor...(\d+)\,(\d+)\,(\d+), ? $2 eq ReadingsVal($NAME,'saturation','unknown') ? return : { saturation=>$2 } : return }\
STATTOPIC/POWER1:.* state
-attr DEVICE jsonMap POWER1:0 Dimmer:pct Channel_4:white Channel_1:0 Channel_2:0 Channel_3:0 HSBColor:0 Color:rgb
attr DEVICE webCmd pct:white:rgb
attr DEVICE webCmdLabel Helligkeit\
:Weiss\
:Farbe:
-attr DEVICE devStateIcon {Color::devStateIcon($name,"rgb","rgb","pct","state")}
+attr DEVICE devStateIcon {Color::devStateIcon($name,'rgb','rgb','pct','state')}
attr DEVICE setStateList on off toggle
set DEVICE attrTemplate speechcontrol_type_light
attr DEVICE model tasmota_rgbw_led
-setreading DEVICE attrTemplateVersion 20220225
+setreading DEVICE attrTemplateVersion 20220228
name:tasmota_rgbcct_light
filter:TYPE=MQTT2_DEVICE:FILTER=readingList=.*(tele|cmnd|stat).*
desc:Tasmota RGBW bulb with CT option like LSC Smart Connect Candle 400lm RGBW
order:A_05a2
-set DEVICE attrTemplate tasmota_basic_state_power1
-set DEVICE attrTemplate tasmota_rgbw_led
-par:CMNDTOPIC;Command topic prefix, without trailing /;{ AttrVal("DEVICE","readingList","") =~ m,([^:]*)\b(tele|cmnd|stat)(/.*)?/LWT:, ? "${1}cmnd$3" : undef }
-par:TELETOPIC;info topic prefix, without trailing /;{ AttrVal("DEVICE","readingList","") =~ m,([^:]*)\b(tele|cmnd|stat)(/.*)?/LWT:, ? "${1}tele$3" : undef }
-par:STATTOPIC;ack topic prefix, without trailing /;{ AttrVal("DEVICE","readingList","") =~ m,([^:]*)\b(tele|cmnd|stat)(/.*)?/LWT:, ? "${1}stat$3" : undef }
+par:CMNDTOPIC;Command topic prefix, without trailing /;{ AttrVal('DEVICE','readingList','') =~ m,([^:]*)\b(tele|cmnd|stat)(/.*)?/LWT:, ? "${1}cmnd$3" : undef }
+par:TELETOPIC;info topic prefix, without trailing /;{ AttrVal('DEVICE','readingList','') =~ m,([^:]*)\b(tele|cmnd|stat)(/.*)?/LWT:, ? "${1}tele$3" : undef }
+par:STATTOPIC;ack topic prefix, without trailing /;{ AttrVal('DEVICE','readingList','') =~ m,([^:]*)\b(tele|cmnd|stat)(/.*)?/LWT:, ? "${1}stat$3" : undef }
+set DEVICE attrTemplate tasmota_rgbw_led JSONMAPTYPE=3
attr DEVICE setList\
off:noArg CMNDTOPIC/POWER1 0\
on:noArg CMNDTOPIC/POWER1 1\
toggle:noArg CMNDTOPIC/POWER1 2\
- Color:colorpicker,RGB CMNDTOPIC/COLOR\
+ rgb:colorpicker,RGB CMNDTOPIC/COLOR\
pct:colorpicker,BRI,0,5,100 CMNDTOPIC/DIMMER\
dimup:noArg { my $num=int((ReadingsNum($NAME,'pct',0)+4)/10)*10+10; return qq {CMNDTOPIC/Dimmer $num}; }\
dimdown:noArg { my $num=int((ReadingsNum($NAME,'pct',0)+7)/10)*10-10; return qq {CMNDTOPIC/Dimmer $num}; }\
white:colorpicker,BRI,0,5,100 { "CMNDTOPIC/COLOR ". sprintf("000000%02X",$EVTPART1*2.55) }\
CT:colorpicker,CT,153,5,500 CMNDTOPIC/CT
-attr DEVICE jsonMap POWER1:0 Dimmer:pct Channel_4:white Channel_1:0 Channel_2:0 Channel_3:0 HSBColor:0 Channel_5:0
-attr DEVICE webCmd pct:white:Color:CT
+attr DEVICE webCmd pct:white:rgb:CT
attr DEVICE webCmdLabel Helligkeit\
:Weiss\
:Farbe\
:Temp
set DEVICE attrTemplate speechcontrol_type_light
attr DEVICE model tasmota_rgbcct_led
-setreading DEVICE attrTemplateVersion 20200522 or prior
+setreading DEVICE attrTemplateVersion 20220228
name:tasmota_cct_led
filter:TYPE=MQTT2_DEVICE:FILTER=readingList=.*(tele|cmnd|stat).*
desc:Tasmota CCT bulb or CCT LED controller
order:A_05a3
-set DEVICE attrTemplate tasmota_basic_state_power1
-par:CMNDTOPIC;Command topic prefix, without trailing /;{ AttrVal("DEVICE","readingList","") =~ m,([^:]*)\b(tele|cmnd|stat)(/.*)?/LWT:, ? "${1}cmnd$3" : undef }
-par:TELETOPIC;info topic prefix, without trailing /;{ AttrVal("DEVICE","readingList","") =~ m,([^:]*)\b(tele|cmnd|stat)(/.*)?/LWT:, ? "${1}tele$3" : undef }
-par:STATTOPIC;ack topic prefix, without trailing /;{ AttrVal("DEVICE","readingList","") =~ m,([^:]*)\b(tele|cmnd|stat)(/.*)?/LWT:, ? "${1}stat$3" : undef }
-par:ICON;ICON as set, defaults to light_control;{ AttrVal("DEVICE","icon","light_control") }
-attr DEVICE icon ICON
-deletereading -q DEVICE (?!associatedWith|IODev).*
+set DEVICE attrTemplate tasmota_basic_state_power1 JSONMAPTYPE=4 \ICON=ICON
+par:CMNDTOPIC;Command topic prefix, without trailing /;{ AttrVal('DEVICE','readingList','') =~ m,([^:]*)\b(tele|cmnd|stat)(/.*)?/LWT:, ? "${1}cmnd$3" : undef }
+par:TELETOPIC;info topic prefix, without trailing /;{ AttrVal('DEVICE','readingList','') =~ m,([^:]*)\b(tele|cmnd|stat)(/.*)?/LWT:, ? "${1}tele$3" : undef }
+par:STATTOPIC;ack topic prefix, without trailing /;{ AttrVal('DEVICE','readingList','') =~ m,([^:]*)\b(tele|cmnd|stat)(/.*)?/LWT:, ? "${1}stat$3" : undef }
+par:ICON;ICON as set, defaults to light_control;{ AttrVal('DEVICE','icon','light_control') }
attr DEVICE setList\
off:noArg CMNDTOPIC/POWER1 0\
on:noArg CMNDTOPIC/POWER1 1\
@@ -2112,25 +2110,23 @@ attr DEVICE readingList \
TELETOPIC/UPTIME:.* { json2nameValue($EVENT,'',$JSONMAP) }\
STATTOPIC/RESULT:.* { json2nameValue($EVENT,'',$JSONMAP) }\
STATTOPIC/POWER1:.* state
-attr DEVICE jsonMap POWER1:0 Dimmer:pct Channel_4:0 Channel_1:0 Channel_2:0 Channel_3:0 HSBColor:0
attr DEVICE webCmd pct:CT
-attr DEVICE devStateIcon {Color::devStateIcon($name,"dimmer",'',"pct","state")}
+attr DEVICE devStateIcon {Color::devStateIcon($name,'dimmer','','pct','state')}
attr DEVICE setStateList on off toggle
set DEVICE attrTemplate speechcontrol_type_light
attr DEVICE model tasmota_cct_led
-setreading DEVICE attrTemplateVersion 20210515
+setreading DEVICE attrTemplateVersion 20220228
#source post: https://forum.fhem.de/index.php/topic,105364.0.html
name:tasmota_TuyaMCU_dimmer
filter:TYPE=MQTT2_DEVICE:FILTER=readingList=.*(tele|cmnd|stat).*
desc:Tasmota controller, suitable for devices using the "Tuya MCU Module" to control a dimmer.
See instructions in https://github.com/arendst/Tasmota/wiki/TuyaMCU-Configurations#dimmer and Forum Thread
order:A_05b
-set DEVICE attrTemplate tasmota_basic_state_power1
-par:CMNDTOPIC;Command topic prefix, without trailing /;{ AttrVal("DEVICE","readingList","") =~ m,([^:]*)\b(tele|cmnd|stat)(/.*)?/LWT:, ? "${1}cmnd$3" : undef }
-par:TELETOPIC;info topic prefix, without trailing /;{ AttrVal("DEVICE","readingList","") =~ m,([^:]*)\b(tele|cmnd|stat)(/.*)?/LWT:, ? "${1}tele$3" : undef }
-par:STATTOPIC;ack topic prefix, without trailing /;{ AttrVal("DEVICE","readingList","") =~ m,([^:]*)\b(tele|cmnd|stat)(/.*)?/LWT:, ? "${1}stat$3" : undef }
-par:ICON;ICON as set, defaults to light_control;{ AttrVal("DEVICE","icon","light_control") }
-attr DEVICE icon ICON
+set DEVICE attrTemplate tasmota_basic_state_power1 JSONMAPTYPE=4 \ICON=ICON
+par:CMNDTOPIC;Command topic prefix, without trailing /;{ AttrVal('DEVICE','readingList','') =~ m,([^:]*)\b(tele|cmnd|stat)(/.*)?/LWT:, ? "${1}cmnd$3" : undef }
+par:TELETOPIC;info topic prefix, without trailing /;{ AttrVal('DEVICE','readingList','') =~ m,([^:]*)\b(tele|cmnd|stat)(/.*)?/LWT:, ? "${1}tele$3" : undef }
+par:STATTOPIC;ack topic prefix, without trailing /;{ AttrVal('DEVICE','readingList','') =~ m,([^:]*)\b(tele|cmnd|stat)(/.*)?/LWT:, ? "${1}stat$3" : undef }
+par:ICON;ICON as set, defaults to light_control;{ AttrVal('DEVICE','icon','light_control') }
attr DEVICE setList\
off:noArg CMNDTOPIC/POWER1 0\
on:noArg CMNDTOPIC/POWER1 1\
@@ -2140,12 +2136,11 @@ deletereading -q DEVICE (?!associatedWith|IODev).*
attr DEVICE autocreate 0
attr DEVICE devStateIcon off:light_light_dim_00:on on:light_light_dim_90:off
attr DEVICE webCmd pct
-attr DEVICE jsonMap POWER1:0 Dimmer:pct Channel_4:white Channel_1:0 Channel_2:0 Channel_3:0 HSBColor:0 Color:rgb
attr DEVICE comment After applying the template, the device to be controlled needs further configuration. For the necessary steps see Tasmota wiki instructions.
farewell:template has been applied successfully. Now it's recommended to do some configruation, see Tasmota wiki instructions.
set DEVICE attrTemplate speechcontrol_type_light
attr DEVICE model tasmota_TuyaMCU_dimmer
-setreading DEVICE attrTemplateVersion 20220225
+setreading DEVICE attrTemplateVersion 20220228
# tasmota battery powered window sensor MC400A
# contributed by OppiM, source post https://forum.fhem.de/index.php/topic,94495.msg1084052.html#msg1084052
diff --git a/fhem/MAINTAINER.txt b/fhem/MAINTAINER.txt
index ffdbc64cf..02672486a 100644
--- a/fhem/MAINTAINER.txt
+++ b/fhem/MAINTAINER.txt
@@ -534,7 +534,7 @@ FHEM/98_ModbusAttr.pm StefanStrobel Sonstiges
FHEM/98_ModbusElsnerWS.pm klaus.schauer Sonstiges
FHEM/98_ModbusSET.pm StefanStrobel Sonstiges
FHEM/98_ModbusTrovis5576.pm Reinerlein Heizungssteuerung/Raumklima
-FHEM/98_monitoring.pm rudolfkoenig/orphan Automatisierung
+FHEM/98_monitoring.pm Beta-User Automatisierung
FHEM/98_notice.pm mfr69bs Sonstiges
FHEM/98_PHC.pm StefanStrobel Sonstiges
FHEM/98_PID20.pm John Automatisierung
diff --git a/fhem/contrib/RHASSPY/10_RHASSPY.pm b/fhem/contrib/RHASSPY/10_RHASSPY.pm
index df4009e12..95e4df262 100644
--- a/fhem/contrib/RHASSPY/10_RHASSPY.pm
+++ b/fhem/contrib/RHASSPY/10_RHASSPY.pm
@@ -320,7 +320,7 @@ sub Define {
$hash->{defaultRoom} = $defaultRoom;
my $language = $h->{language} // shift @{$anon} // lc AttrVal('global','language','en');
- $hash->{MODULE_VERSION} = '0.5.15';
+ $hash->{MODULE_VERSION} = '0.5.16';
$hash->{baseUrl} = $Rhasspy;
initialize_Language($hash, $language) if !defined $hash->{LANGUAGE} || $hash->{LANGUAGE} ne $language;
$hash->{LANGUAGE} = $language;
@@ -342,7 +342,6 @@ sub Define {
if ($hash->{useGenericAttrs}) {
addToAttrList(q{genericDeviceType});
- #addToAttrList(q{homebridgeMapping});
}
notifyRegexpChanged($hash,'',1);
@@ -1404,10 +1403,10 @@ sub initialize_TTS {
my($unnamedParams, $namedParams) = parseParams($values);
if ( InternalVal($keywd,'TYPE','unknown') eq 'AMADDevice' ) {
- $hash->{helper}->{TTS}->{config}->{$keywd}->{ttsCommand} //= q{set $DEVICE ttsMsg $message};
my $siteId = $namedParams->{siteId} // shift @{$unnamedParams }// $keywd;
$hash->{helper}->{TTS}->{$siteId} = $keywd;
$hash->{helper}->{TTS}->{config}->{$keywd} = $namedParams;
+ $hash->{helper}->{TTS}->{config}->{$keywd}->{ttsCommand} //= 'set $DEVICE ttsMsg $message';
}
}
if ( keys %{$hash->{helper}->{TTS}} ) {
@@ -1464,7 +1463,8 @@ sub initialize_STT {
if ( !defined $hash->{helper}->{STT}->{config}->{allowed} ) {
delete $hash->{helper}->{STT};
- return 'Setting the allowed key in rhasspySTT is mandatory!' ;
+ disable_msgDialog($hash, ReadingsVal($hash->{NAME}, 'enableMsgDialog', 1), 1 );
+ return 'Setting the allowed key in rhasspySTT is mandatory!' if $init_done;
}
return;
@@ -1512,7 +1512,7 @@ sub initialize_msgDialog {
$hash->{helper}->{msgDialog}->{config}->{msgCommand}
= AttrVal($msgConfig, "$hash->{prefix}MsgCommand", q{msg push \@$recipients $message});
}
- return disable_msgDialog($hash, 1, 1)
+ return disable_msgDialog($hash, 1, 1);
}
@@ -1527,19 +1527,18 @@ sub disable_msgDialog {
if ( defined $hash->{helper}->{STT}
&& defined $hash->{helper}->{STT}->{config}
&& defined $hash->{helper}->{STT}->{config}->{AMADCommBridge} ) {
- $devsp = qq($hash->{helper}->{STT}->{config}->{AMADCommBridge});
+ $devsp = 'TYPE=AMADCommBridge';
}
if ($enable) {
- $devsp .= $devsp ? ',TYPE=(ROOMMATE|GUEST)' : 'TYPE=(ROOMMATE|GUEST)';
+ $devsp = $devsp ? 'TYPE=(AMADCommBridge|ROOMMATE|GUEST)' : 'TYPE=(ROOMMATE|GUEST)';
}
if ($hash->{autoTraining}) {
$devsp .= $devsp ? ',global' : 'global';
}
- my @ntfdevs = devspec2array($devsp);
- if (@ntfdevs) {
- setNotifyDev($hash,$devsp);
+ if ( $devsp && devspec2array($devsp) ) {
delete $hash->{disableNotifyFn};
+ setNotifyDev($hash,$devsp);
} else {
notifyRegexpChanged($hash,'',1);
}
@@ -2228,7 +2227,7 @@ sub getMapping {
my $hash = shift // return;
my $device = shift // return;
my $intent = shift // return;
- my $type = shift // $intent; #Beta-User: seems first three parameters are obligatory...?
+ my $type = shift // $intent;
my $disableLog = shift // 0;
my $subType = $type;
@@ -2511,54 +2510,6 @@ sub Notify {
return;
}
-
-=pod
- if ($values[0] eq 'all') {
- initialize_Language($hash, $hash->{LANGUAGE});
- initialize_devicemap($hash);
- $hash->{'.needTraining'} = 1;
- updateSlots($hash);
- return fetchIntents($hash);
-
- if ( $attribute eq 'rhasspyShortcuts' ) {
- for ( keys %{ $hash->{helper}{shortcuts} } ) {
- delete $hash->{helper}{shortcuts}{$_};
- }
- if ($command eq 'set') {
- return init_shortcuts($hash, $value);
- }
- }
-
- if ( $attribute eq 'rhasspyIntents' ) {
- for ( keys %{ $hash->{helper}{custom} } ) {
- delete $hash->{helper}{custom}{$_};
- }
- if ($command eq 'set') {
- return init_custom_intents($hash, $value);
- }
- }
-
- if ( $attribute eq 'rhasspyTweaks' ) {
- for ( keys %{ $hash->{helper}{tweaks} } ) {
- delete $hash->{helper}{tweaks}{$_};
- }
- if ($command eq 'set') {
- return initialize_rhasspyTweaks($hash, $value) if $init_done;
- }
- }
-
-
- if ( $attribute eq 'languageFile' ) {
- if ($command ne 'set') {
- delete $hash->{CONFIGFILE};
- delete $attr{$name}{languageFile};
- delete $hash->{helper}{lng};
- $value = undef;
- }
- return initialize_Language($hash, $hash->{LANGUAGE}, $value);
- }
-=cut
-
return if !ReadingsVal($name,'enableMsgDialog',1) || !defined $hash->{helper}->{msgDialog};
my @events = @{deviceEvents($dev_hash, 1)};
@@ -2639,31 +2590,7 @@ sub activateVoiceInput {
return IOWrite($hash, 'publish', qq{hermes/hotword/$hotword/detected $json});
}
-=pod
- #source: https://rhasspy.readthedocs.io/en/latest/reference/#tts_say
- hermes/tts/say (JSON)
-
- Generate spoken audio for a sentence using the configured text to speech system
- Automatically sends playBytes
- playBytes.requestId = say.id
- text: string - sentence to speak (required)
- lang: string? = null - override language for TTS system
- id: string? = null - unique ID for request (copied to sayFinished)
- volume: float? = null - volume level to speak with (0 = off, 1 = full volume)
- siteId: string = "default" - Hermes site ID
- sessionId: string? = null - current session ID
- Response(s)
- hermes/tts/sayFinished (JSON)
-
- hermes/tts/sayFinished (JSON)
-
- Indicates that the text to speech system has finished speaking
- id: string? = null - unique ID for request (copied from say)
- siteId: string = "default" - Hermes site ID
- Response to hermes/tts/say
-
-
-=cut
+#source: https://rhasspy.readthedocs.io/en/latest/reference/#tts_say
sub sayFinished {
my $hash = shift // return;
my $data = shift // return;
@@ -2710,7 +2637,6 @@ sub msgDialog_close {
return if !defined $hash->{helper}{msgDialog}->{$device};;
msgDialog_respond( $hash, $device, $response, 0 );
- #delete $hash->{helper}{'.delayed'}->{$device};
delete $hash->{helper}{msgDialog}->{$device};
return;
}
@@ -2816,7 +2742,7 @@ sub handleTtsMsgDialog {
sayFinished($hash, $data->{id}, $hash->{siteId});
} elsif (defined $hash->{helper}->{STT}
&& defined $hash->{helper}->{STT}->{config}->{$recipient} ) {
- ttsDialog_respond($hash,$recipient,$message);
+ ttsDialog_respond($hash,$recipient,$message,0);
sayFinished($hash, $data->{id}, $hash->{siteId}); #Beta-User: may be moved to response logic later with timeout...?
}
@@ -3024,6 +2950,9 @@ sub analyzeMQTTmessage {
my $siteId = $data->{siteId} // return;
$active = $data->{reason} if $active && defined $data->{reason};
readingsSingleUpdate($hash, "hotwordAwaiting_" . makeReadingName($siteId), $active, 1);
+
+ my $ret = handleHotwordGlobal($hash, $active ? 'on' : 'off', $data, $active ? 'on' : 'off');
+ push @updatedList, $ret if $ret && $defs{$ret};
push @updatedList, $hash->{NAME};
return \@updatedList;
}
@@ -3042,7 +2971,7 @@ sub analyzeMQTTmessage {
if ( $topic =~ m{\Ahermes/hotword/([^/]+)/detected}x ) {
my $hotword = $1;
my $siteId = $data->{siteId};
- if ( $siteId ) {
+ if ( 0 && $siteId ) { #Beta-User: deactivated
my $device = ReadingsVal($hash->{NAME}, "siteId2ttsDevice_$siteId",undef);
$device //= $hash->{helper}->{TTS}->{$siteId} if defined $hash->{helper}->{TTS} && defined $hash->{helper}->{TTS}->{$siteId};
if ($device) {
@@ -3053,6 +2982,8 @@ sub analyzeMQTTmessage {
return \@updatedList if !$hash->{handleHotword} && !defined $hash->{helper}{hotwords};
my $ret = handleHotwordDetection($hash, $hotword, $data);
push @updatedList, $ret if $ret && $defs{$ret};
+ $ret = handleHotwordGlobal($hash, $hotword, $data, 'detected');
+ push @updatedList, $ret if $ret && $defs{$ret};
push @updatedList, $hash->{NAME};
return \@updatedList;
}
@@ -3225,7 +3156,7 @@ sub sendSpeakCommand {
return 'speak with explicite params needs siteId and text as arguments!' if !defined $cmd->{siteId} || !defined $cmd->{text};
$sendData->{siteId} = $cmd->{siteId};
$sendData->{init}->{text} = $cmd->{text};
- } else { #Beta-User: might need review, as parseParams is used by default...!
+ } else {
my($unnamedParams, $namedParams) = parseParams($cmd);
if (defined $namedParams->{siteId} && defined $namedParams->{text}) {
@@ -3572,6 +3503,25 @@ sub handleHotwordDetection {
return analyzeAndRunCmd($hash, $hash->{NAME}, $command, $hotword, $siteId);
}
+sub handleHotwordGlobal {
+ my $hash = shift // return;
+ my $hotword = shift // return;
+ my $data = shift;
+ my $mode = shift;
+
+ return if !defined $hash->{helper}{hotwords} || !defined $hash->{helper}{hotwords}->{global};
+ my $cmd = $hash->{helper}{hotwords}->{global}->{$mode} // $hash->{helper}{hotwords}->{global}->{default} // return;
+ my %specials = (
+ '$VALUE' => $hotword,
+ '$MODE' => $mode,
+ '$DEVICE' => $hash->{NAME},
+ '$ROOM' => $data->{siteId},
+ '$DATA' => toJSON($data)
+ );
+ $cmd = EvalSpecials($cmd, %specials);
+ return AnalyzeCommandChain($hash, $cmd);
+}
+
# Eingehender Custom-Intent
sub handleCustomIntent {
my $hash = shift // return;
@@ -5663,14 +5613,15 @@ i="i am hungry" f="set Stove on" d="Stove" c="would you like roast pork"<
Define custom reactions as soon as a specific hotword is detected. This does not require any specific configuration on any other FHEM device.
- One hotword per line, syntax is either a simple and an extended version.
Define custom reactions as soon as a specific hotword is detected (or with "global": a toggle command is detected). This does not require any specific configuration on any other FHEM device.
+ One hotword per line, syntax is either a simple and an extended version. The "hotword" global will be treated specially and can be used to also execute custom commands when a
bumblebee_linux = set amplifier2 mute on
- porcupine_linux = livingroom="set amplifier mute on" default={Log3($DEVICE,3,"device $DEVICE - room $ROOM - value $VALUE")}
First example will execute the command for all incoming messages for the respective hotword, second will decide based on the given siteId keyword; $DEVICE is evaluated to RHASSPY name, $ROOM to siteId and $VALUE to the hotword.
+ porcupine_linux = livingroom="set amplifier mute on" default={Log3($DEVICE,3,"device $DEVICE - room $ROOM - value $VALUE")}
+ global = { rhasspyHotword($DEVICE,$VALUE,$DATA,$MODE) }
First example will execute the command for all incoming messages for the respective hotword, second will decide based on the given siteId keyword; $DEVICE is evaluated to RHASSPY name, $ROOM to siteId and $VALUE to the hotword. Additionally, in "global key", $DATA will contain entire JSON-$data (as parsed internally, encoded in JSON) and $MODE will be one of on, off or detected
. You may assign different commands to on, off and detected.
default is optional. If set, this action will be executed for all siteIds without match to other keywords.
- Additionally, if either rhasspyHotwords ia set or key handleHotword in DEF is activated, the reading hotword will be filled with hotword plus siteId to also allow arbitrary event handling.
NOTE: As all hotword messages are sent to a common topic structure, you may need additional measures to distinguish between several RHASSPY instances, e.g. by restricting subscriptions and/or using different entries in this attribute.