• Register
    • Login
    • Search

    Solved Control of mute (unmute) function via recipe not working

    EXT-Volume
    2
    4
    23
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • D
      devtobi Donators last edited by

      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 payload true works fine. However, unmuting with payload false 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.
      
      1 Reply Last reply Reply Quote 0
      • bugsounet
        bugsounet Main Coder last edited by

        Hi,

        Warn:
        just like “volume”, “mute” is an internal command (ready to be used) from Google servers

        sample:
        Jarvis ... mute and Jarvis... 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 something

        Note with your code:
        just because i use regex when you says unmute to jarvis VOLUMEMUTE and VOLUMEUNMUTE are called because mute pattern match !
        That why I have correct with a complete regex

        My place in France Top committers of Github:
        committers.top badge

        1 Reply Last reply Reply Quote 0
        • D
          devtobi Donators last edited by

          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.

          1 Reply Last reply Reply Quote 1
          • bugsounet
            bugsounet Main Coder last edited by

            perfect !

            Happy use,
            @bugsounet

            My place in France Top committers of Github:
            committers.top badge

            1 Reply Last reply Reply Quote 1
            • First post
              Last post
            Powered by NodeBB | @bugsounet ©2023