Solved Control of mute (unmute) function via recipe not working
-
I created a small recipe to control mute/unmute of the MMM-Volume plugin via voice commands. (see code below)
Muting the speaker via voice command and payloadtrue
works fine. However, unmuting with payloadfalse
does not work as expected and also mutes the speaker. Thus, I cannot unmute the speaker with voice commands.var recipe = { transcriptionHooks: { VOLUMEMUTE: { pattern: "Mute", command: "VOLUMEMUTE", }, VOLUMEUNMUTE: { pattern: "Unmute", command: "VOLUMEUNMUTE", }, }, commands: { VOLUMEMUTE: { notificationExec: { notification: "EXT_VOLUME-SPEAKER_MUTE", payload: true, }, }, VOLUMEUNMUTE: { notificationExec: { notification: "EXT_VOLUME-SPEAKER_MUTE", payload: false, }, }, }, }; exports.recipe = recipe; // Don't remove this line.
-
Hi,
Warn:
just like “volume”, “mute” is an internal command (ready to be used) from Google serverssample:
Jarvis ... mute
andJarvis... volume 10
are a natural vocal commands (with no recipes)To correct your recipe (in order to learn)
var recipe = { transcriptionHooks: { VOLUMEMUTE: { pattern: "^(mute)($)", command: "VOLUMEMUTE", }, VOLUMEUNMUTE: { pattern: "^(unmute)($)", command: "VOLUMEUNMUTE", } }, commands: { VOLUMEMUTE: { notificationExec: { notification: "EXT_VOLUME-SPEAKER_MUTE", payload: () => { return true } } }, VOLUMEUNMUTE: { notificationExec: { notification: "EXT_VOLUME-SPEAKER_MUTE", payload: () => { return false } } } } }; exports.recipe = recipe; // Don't remove this line.
pattern
is a regex pattern (It’s seams you develop too, I think you will understand)
payload: () => { return <value> }
is the best way to return somethingNote with your code:
just because i use regex when you saysunmute
to jarvisVOLUMEMUTE
andVOLUMEUNMUTE
are called becausemute
pattern match !
That why I have correct with a complete regex -
Hi, thank you for that fast reply. I changed my pattern to a different string (“Speaker on” and “Speaker off”) to not collide with the Google internal commands. I also changed the payload to using an anonymous function, as you suggested. It now works as expected.
-
perfect !
Happy use,
@bugsounet