if ( defined $data->{Colortemp} && defined $mapping->{rgb} && looks_like_number($data->{Colortemp}) ) {
Gibt auch Lampen, die können nur ct
# Custom Intents
- Bei Verwendung des Dialouges wenn man keine Antwort spricht, bricht Rhasspy ab. Die voice response "Tut mir leid, da hat etwas zu lange gedauert" wird
also gar nicht ausgegeben und:
PERL WARNING: Use of uninitialized value $cmd in pattern match (m//) at fhem.pl line 5868.
# "rhasspySpecials" bzw. rhasspyTweaks als weitere Attribute
Denkbare Verwendung:
- siteId2room für mobile Geräte (Denkbare Anwendungsfälle: Auswertung BT-RSSI per Perl, aktives Setzen über ein Reading? Oder einen intent? (tweak)
- Bestätigungs-Mapping (special) (ist noch offen)
# Sonstiges, siehe insbes. https://forum.fhem.de/index.php/topic,119447.msg1148832.html#msg1148832
- kein "match in room" bei GetNumeric
- "kind" und wie man es füllen könnte (mehr Dialoge)
- Bestätigungsdialoge - weitere Anwendungsfelder
- gDT: mehr und bessere mappings?
- Farbe und Farbtemperatur (fast fertig?)
- Hat man in einem Raum einen Satelliten aber kein Device mit der siteId/Raum, kann man den Satelliten bei z.B. dem Timer nicht ansprechen, weil der Raum nicht in den Slots ist.
Irgendwie müssen wir die neue siteId in den Slot Rooms bringen
# Parameter-Check für define? Anregung DrBasch aus https://forum.fhem.de/index.php/topic,119447.msg1157700.html#msg1157700
# Keine shortcuts-Intents, wenn Attribut nicht gesetzt: Anregung DrBasch aus https://forum.fhem.de/index.php/topic,119447.msg1157700.html#msg1157700 (erl.)
# Doku zu den "üblichen Formaten" (z.B. JSON-Keywords beginnen mit Großbuchstaben)?
=end ToDo
=begin ToClarify
#defaultRoom (JensS):
- überhaupt erforderlich?
- Schreibweise: RHASSPY ist raus, Rhasspy scheint der überkommene Raumname für die devspec zu sein => ist erst mal weiter beides drin
# GetTimer implementieren?
https://forum.fhem.de/index.php/topic,113180.msg1130139.html#msg1130139
# Wetterdurchsage
Ist möglich. Dazu hatte ich einen rudimentären Intent in diesem Thread erstellt. Müsste halt nur erweitert werden.
https://forum.fhem.de/index.php/topic,113180.msg1130754.html#msg1130754
=end ToClarify
=encoding utf8
=item device
=item summary Control FHEM with Rhasspy voice assistant
=item summary_DE Steuerung von FHEM mittels Rhasspy Sprach-Assistent
=begin html
This module receives, processes and executes voice commands coming from Rhasspy voice assistent.
define <name> RHASSPY <baseUrl> <devspec> <defaultRoom> <language> <fhemId> <prefix> <useGenericAttrs> <encoding>
All parameters in define are optional, but changing them later might lead to confusing results!
General Remark: RHASSPY uses parseParams at quite a lot places, not only in define, but also to parse attribute values.
So all parameters in define should be provided in the key=value form. In other places you may have to start e.g. a single line in an attribute with option:key="value xy shall be z"
or identifier:yourCode={fhem("set device off")} anotherOption=blabla
form.
baseUrl=http://127.0.0.1:12101
.devspec=room=Rhasspy
, see as a reference, how to e.g. use a comma-separated list of devices or combinations like devspec=room=livingroom,room=bathroom,bedroomlamp
.defaultRoom=default
.language=en
encoding=cp-1252
useGenericAttrs=1
adds genericDeviceType
to the global attribute list and activates RHASSPY's feature to estimate appropriate settings - similar to rhasspyMapping. In later versions homebridgeMapping
may also be on the list.RHASSPY needs a MQTT2_CLIENT device connected to the same MQTT-Server as the voice assistant (Rhasspy) service.
Example for defining an MQTT2_CLIENT device and the Rhasspy device in FHEM:
defmod rhasspyMQTT2 MQTT2_CLIENT 192.168.1.122:12183
attr rhasspyMQTT2 clientOrder RHASSPY MQTT_GENERIC_BRIDGE MQTT2_DEVICE
attr rhasspyMQTT2 subscriptions hermes/intent/+ hermes/dialogueManager/sessionStarted hermes/dialogueManager/sessionEnded
define Rhasspy RHASSPY devspec=room=Rhasspy defaultRoom=Livingroom language=en
Additionals remarks on MQTT2-IOs:
Using a separate MQTT server (and not the internal MQTT2_SERVER) is highly recommended, as the Rhasspy scripts also use the MQTT protocol for internal (sound!) data transfers. Best way is to either use MQTT2_CLIENT (see above) or bridge only the relevant topics from mosquitto to MQTT2_SERVER (see e.g. http://www.steves-internet-guide.com/mosquitto-bridge-configuration for the principles). When using MQTT2_CLIENT, it's necessary to set clientOrder
to include RHASSPY (as most likely it's the only module listening to the CLIENT it could be just set to attr <m2client> clientOrder RHASSPY
)
Furthermore, you are highly encouraged to restrict subscriptions only to the relevant topics:
attr <m2client> subscriptions setByTheProgram
In case you are using the MQTT server also for other purposes than Rhasspy, you have to set subscriptions
manually to at least include the following topics additionally to the other subscriptions desired for other purposes.
hermes/intent/+
hermes/dialogueManager/sessionStarted
hermes/dialogueManager/sessionEnded
Important: After defining the RHASSPY module, you are supposed to manually set the attribute IODev to force a non-dynamic IO assignement. Use e.g. attr <deviceName> IODev <m2client>
.
Note: RHASSPY consolidates a lot of data from different sources. The final data structure RHASSPY uses at runtime can be viewed using the list command. It's highly recommended to have a close look at this data structure, especially when starting with RHASSPY or in case something doesn't work as expected!
When changing something relevant within FHEM for either the data structure in
these changes must be get to known to RHASSPY and (often, but not allways) to Rhasspy. See the different versions provided by the update command.
Choose between one of the following:
Example: set <rhasspyDevice> update language
Send WAV file to Rhasspy.
siteId and path are required!
You may optionally add a number of repeats and a wait time in seconds between repeats. wait defaults to 15, if only repeats is given.
Examples:
set <rhasspyDevice> play siteId="default" path="/opt/fhem/test.wav"
set <rhasspyDevice> play siteId="default" path="./test.wav" repeats=3 wait=20
Voice output over TTS.
Both arguments (siteId and text) are required!
Example:
set <rhasspyDevice> speak siteId="default" text="This is a test"
Send a text command to Rhasspy.
Example:
set <rhasspyDevice> textCommand turn the light on
Send a request to Rhasspy to send all siteId's. This by default is done once, so in case you add more satellites to your system, this may help to get RHASSPY updated.
Example:
set <rhasspyDevice> fetchSiteIds
Sends a train-command to the HTTP-API of the Rhasspy master
Might be removed in the future versions in favor of the update features
Example:
set <rhasspyDevice> trainRhasspy
Sets volume of given siteId between 0 and 1 (float)
Both arguments (siteId and volume) are required!
Example:
set <rhasspyDevice> siteId="default" volume="0.5"
Creates a new - or overwrites an existing slot - in Rhasspy
Provide slotname, slotdata and (optional) info, if existing data shall be overwritten and training shall be initialized immediately afterwards.
First two arguments are required, third and fourth are optional.
overwrite defaults to true, setting any other value than true will keep existing Rhasspy slot data.
Examples:
set <rhasspyDevice> customSlot mySlot a,b,c overwrite training
set <rhasspyDevice> customSlot slotname=mySlot slotdata=a,b,c overwrite=false
Note: To get RHASSPY working properly, you have to configure attributes at RHASSPY itself and the subordinated devices as well.
RHASSPY itself supports the following attributes:
Path to the language-config file. If this attribute isn't set, a default set of english responses is used for voice responses.
The file itself must contain a JSON-encoded keyword-value structure (partly with sub-structures) following the given structure for the mentioned english defaults. As a reference, there's one available in german, or just make a dump of the English structure with e.g. (replace RHASSPY by your device's name): {toJSON($defs{RHASSPY}->{helper}{lng})}
, edit the result e.g. using https://jsoneditoronline.org and place this in your own languageFile version. There might be some variables to be used - these should also work in your sentences.
languageFile also allows combining e.g. a default set of german sentences with some few own modifications by using "defaults" subtree for the defaults and "user" subtree for your modified versions. This feature might be helpful in case the base language structure has to be changed in the future.
Example (placed in the same dir fhem.pl is located):
attr <rhasspyDevice> languageFile ./rhasspy-de.cfg
Not recommended. Use the language-file instead.
Optionally define alternative default answers. Available keywords are DefaultError
, NoActiveMediaDevice
and DefaultConfirmation
.
Example:
DefaultError=
DefaultConfirmation=Klaro, mach ich
Defines custom intents. See Custom Intent erstellen.
One intent per line.
Example:
attr <rhasspyDevice> rhasspyIntents SetCustomIntentsTest=SetCustomIntentsTest(siteId,Type)
together with the following myUtils-Code should get a short impression of the possibilities:
sub SetCustomIntentsTest {
my $room = shift;
my $type = shift;
Log3('rhasspy',3 , "RHASSPY: Room $room, Type $type");
return "RHASSPY: Room $room, Type $type";
}
The following arguments can be handed over:
If a simple text is returned, this will be considered as response.
For more advanced use of this feature, you may return an array. First element of the array will be interpreted as comma-separated list of devices that may have been modified (otherwise, these devices will not cast any events! See also the "d" parameter in rhasspyShortcuts). The second element is interpreted as response and may either be simple text or HASH-type data. This will keep the dialogue-session open to allow interactive data exchange with Rhasspy. An open dialogue will be closed after some time, default is 20 seconds, you may alternatively hand over other numeric values as third element of the array.
Define custom sentences without editing Rhasspys sentences.ini
The shortcuts are uploaded to Rhasspy when using the updateSlots set-command.
One shortcut per line, syntax is either a simple and an extended version.
Examples:
mute on=set amplifier2 mute on
lamp off={fhem("set lampe1 off")}
i="you are so exciting" f="set $NAME speak siteId='livingroom' text='Thanks a lot, you are even more exciting!'"
i="mute off" p={fhem ("set $NAME mute off")} n=amplifier2 c="Please confirm!"
i="i am hungry" f="set Stove on" d="Stove" c="would you like roast pork"
Abbreviations explanation:
i="what's the time for sunrise" r="at [Astro:SunRise] o'clock"
is valid.Currently sets additional settings for timers and slot-updates to Rhasspy. May contain further custom settings in future versions like siteId2room info or code links, allowed commands, confirmation requests etc.
Used to determine when the timer should response with e.g. "set to 30 minutes" or with "set to 10:30"
timerLimits=90,300,3000,2*HOURSECONDS,50
Five values have to be set, corresponding with the limits to timerSet responses. so above example will lead to seconds response for less then 90 seconds, minute+seconds response for less than 300 seconds etc.. Last value is the limit in seconds, if timer is set in time of day format.
Per default the timer responds with a voice command if it has elapsed. If you want to use a wav-file instead, you can set this here.
timerSounds= default=./yourfile1.wav eggs=3:20:./yourfile2.wav potatoes=5:./yourfile3.wav
Above keys are some examples and need to match the "Label"-tags for the timer provided by the Rhasspy-sentences.
default is optional. If set, this file will be used for all labeled timer without match to other keywords.
The two numbers are optional. The first one sets the number of repeats, the second is the waiting time between the repeats.
repeats defaults to 5, wait to 15
If only one number is set, this will be taken as repeats.
Changes aspects on slot generation and updates.
noEmptySlots=1
By default, RHASSPY will generate an additional slot for each of the genericDeviceType it recognizes, regardless, if there's any devices marked to belong to this type. If set to 1, no empty slots will be generated.
overwrite_all=false
By default, RHASSPY will overwrite all generated slots. Setting this to false will change this.
Atm. keywords confirm and/or default can be used to change the corresponding defaults (15 seconds / 20 seconds) used for dialogue timeouts.
Example:
timeouts: confirm=25 default=30
If set to 1, RHASSPY will forward incoming messages also to further MQTT2-IO-client modules like MQTT2_DEVICE, even if the topic matches to one of it's own subscriptions. By default, these messages will not be forwarded for better compability with autocreate feature on MQTT2_DEVICE. See also clientOrder attribute in MQTT2 IO-type commandrefs; setting this in one instance of RHASSPY might affect others, too.
For the subordinated devices, a list of the possible attributes is automatically extended by several further entries
The names of these attributes all start with the prefix previously defined in RHASSPY - except for genericDeviceType (gDT).
These attributes are used to configure the actual mapping to the intents and the content sent by Rhasspy.
Note: As the analyses of the gDT is intented to lead to fast configuration progress, it's highly recommended to use this as a starting point. All other RHASSPY-specific attributes will then be considered as a user command to overwrite the results provided by the automatics initiated by gDT usage.
By default, the following attribute names are used: rhasspyName, rhasspyRoom, rhasspyGroup, rhasspyChannels, rhasspyColors, rhasspySpecials.
Each of the keywords found in these attributes will be sent by update to Rhasspy to create the corresponding slot.
Comma-separated "labels" for the device as used when speaking a voice-command. They will be used as keywords by Rhasspy. May contain space or mutated vovels.
Example:
attr m2_wz_08_sw rhasspyName kitchen lamp,ceiling lamp,workspace,whatever
Comma-separated "labels" for the "rooms" the device is located in. Recommended to be unique.
Example:
attr m2_wz_08_sw rhasspyRoom living room
Comma-separated "labels" for the "groups" the device is in. Recommended to be unique.
Example:
attr m2_wz_08_sw rhasspyGroup lights
If automatic detection (gDT) does not work or is not desired, this is the place to tell RHASSPY how your device can be controlled.
Example:
attr lamp rhasspyMapping SetOnOff:cmdOn=on,cmdOff=off,response="All right"
GetOnOff:currentVal=state,valueOff=off
GetNumeric:currentVal=pct,type=brightness
SetNumeric:currentVal=brightness,cmd=brightness,minVal=0,maxVal=255,map=percent,step=1,type=brightness
GetState:response=The temperature in the kitchen is at [lamp:temperature] degrees
MediaControls:cmdPlay=play,cmdPause=pause,cmdStop=stop,cmdBack=previous,cmdFwd=next
Used to change the channels of a tv, set light-scenes, etc.
key=value line by line arguments mapping command strings to fhem- or Perl commands.
Example:
attr TV rhasspyChannels orf eins=channel 201
orf zwei=channel 202
orf drei=channel 203
Note: This attribute is not added to global attribute list by default. Add it using userattr or by editing the global userattr attribute.
Used to change to colors of a light
key=value line by line arguments mapping keys to setter strings on the same device.
Example:
attr lamp1 rhasspyColors red=rgb FF0000
green=rgb 008000
blue=rgb 0000FF
yellow=rgb FFFF00
Note: This attribute is not added to global attribute list by default. Add it using userattr or by editing the global userattr attribute. You may consider using rhasspySpecials (colorCommandMap and/or colorForceHue2rgb) instead.
Currently some colour light options besides group and venetian blind related stuff is implemented, this could be the place to hold additional options, e.g. for confirmation requests. You may use several of the following lines.
key:value line by line arguments similar to rhasspyTweaks.
If set, the device will not be directly addressed, but the mentioned group - typically a FHEM structure device or a HUEDevice-type group. This has the advantage of saving RF ressources and/or already implemented logics.
Note: all addressed devices will be switched, even if they are not member of the rhasspyGroup. Each group should only be addressed once, but it's recommended to put this info in all devices under RHASSPY control in the same external group logic.
All of the following options are optional.
Example:
attr lamp1 rhasspySpecials group:async_delay=100 prio=1 group=lights
attr blind1 rhasspySpecials venetianBlind:setter=dim device=blind1_slats
Explanation (one of the two arguments is mandatory):
If set, the slat target position will be set to the same level than the main device.
Allows mapping of values from the Color> key to individual commands.
Example:
attr lamp1 rhasspySpecials colorCommandMap:0='rgb FF0000' 120='rgb 00FF00' 240='rgb 0000FF'
Defaults to "0". If set, a rgb command will be issued, even if the device is capable to handle hue commands.
Example:
attr lamp1 rhasspySpecials colorForceHue2rgb:1
Keywords inRoom and outsideRoom can be used, each followed by comma separated types to give priority in GetNumeric. This may eleminate requests in case of several possible devices or rooms to deliver requested info type.
Example:
attr sensor_outside_main rhasspySpecials priority:inRoom=temperature outsideRoom=temperature,humidity,pressure
attr lamp1 rhasspySpecials scenes:scene2="Kino zu zweit" scene3=Musik scene1=none scene4=none
Explanation:
If set, the label provided will be sent to Rhasspy instead of the tech names (derived from available setters). Keyword none will delete the scene from the internal list, setting the combination all=none will exclude the entire device from beeing recognized for SetScene.
The following intents are directly implemented in RHASSPY code: