• Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Register
  • Login
TRIGGERcmd
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Register
  • Login

Pass color and brightness parameters using TRIGGERcmd Smart Home Alexa skill

Announcements
alexa
4
10
830
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.
  • R
    Russ
    last edited by Russ Feb 6, 2022, 7:33 PM Feb 6, 2022, 7:31 PM

    Thanks to @tuicemen's suggestion, now you can use commands that accept brightness or color as a parameter via the TRIGGERcmd Smart Home Alexa skill.

    • Brightness will be a number from 1 to 100.
    • Color will be red, blue, brown, green, pink, purple etc.

    To test it, you could enable parameters on your notepad command like this:

    874113e6-7786-4b22-a2e4-857fc0bfa44a-image.png

    Then say something like: "Alexa, turn notepad red"

    I'll look into adding on Google Assistant too, but so far this only works with the TRIGGERcmd Smart Home Alexa skill.

    Alexa devices for existing commands (created before 2/6/2022) will need to be deleted and re-discovered, or you can change the command's name and change it back so it will be re-created with the new color and brightness properties.

    Russell VanderMey

    1 Reply Last reply Reply Quote 1
    • T
      tuicemen
      last edited by tuicemen Feb 6, 2022, 9:29 PM Feb 6, 2022, 9:06 PM

      Just awesome!
      For the Dim commands you can say something like "Alexa, office light 50%" or "Alexa set office light to 50"
      This should allow control of other things that rely on a number value as well.
      You can say Dim in a Alexa call but brighten doesn't seem to work Alexa says OK but nothing happens. (at least not in my tests)

      1 Reply Last reply Reply Quote 0
      • J
        Javier Rilova 0
        last edited by Apr 4, 2022, 8:46 PM

        Awesome, looking forward to this to be implemented for Google Home too, can't wait!

        R 1 Reply Last reply Apr 4, 2022, 9:11 PM Reply Quote 0
        • R
          Russ @Javier Rilova 0
          last edited by Russ Apr 4, 2022, 9:12 PM Apr 4, 2022, 9:11 PM

          @javier-rilova-0, this works on Google Home now too. Please try it.

          Russell VanderMey

          1 Reply Last reply Reply Quote 0
          • M
            Moacir Vilela Sêga
            last edited by Apr 6, 2022, 7:25 PM

            Did it stop working? I used this to control my computer volume, and I think since yesterday it isnt working anymore, even after deleting the devices

            R 1 Reply Last reply Apr 7, 2022, 8:51 PM Reply Quote 0
            • R
              Russ @Moacir Vilela Sêga
              last edited by Apr 7, 2022, 8:51 PM

              @moacir-vilela-sêga , not that I know of. Are you using the Google Assistant or Alexa?

              Are you using a script? If so can you paste it here?

              Do you have parameters enabled on the command?

              Is your script logging the parameter? If you run the script manually with a number parameter does it work?

              Russell VanderMey

              M 1 Reply Last reply Apr 7, 2022, 10:30 PM Reply Quote 0
              • M
                Moacir Vilela Sêga @Russ
                last edited by Apr 7, 2022, 10:30 PM

                @russ I am using Alexa. I did a simple python script

                import pyttsx3
                import threading
                import sys
                from pycaw.pycaw import AudioUtilities, IAudioEndpointVolume, IAudioEndpointVolumeCallback
                from comtypes import CLSCTX_ALL, COMObject
                
                from ctypes import POINTER, cast
                
                class fala:
                    def __init__(self,msg,voice=0):
                        threading.Thread(target=self.thread,args=(msg,voice,)).start()
                    def thread(self,msg,voice):
                        tts = _TTS(voice)
                        tts.start(msg)
                        del(tts)
                    
                class _TTS:
                    engine = None
                    rate = None
                    def __init__(self,voice):
                        self.engine = pyttsx3.init()
                        self.engine.setProperty('volume',1.0)
                        voices = self.engine.getProperty('voices')
                        self.engine.setProperty('voice', voices[voice].id)
                    def start(self,text_):
                        self.engine.say(text_)
                        try:
                            self.engine.runAndWait()
                        except:
                            fala(text_)
                
                
                class AudioEndpointVolumeCallback(COMObject):
                    _com_interfaces_ = [IAudioEndpointVolumeCallback]
                
                    def OnNotify(self, pNotify):
                        print('OnNotify callback')
                
                list2 = sys.argv[1:]
                devices = AudioUtilities.GetSpeakers()
                interface = devices.Activate(IAudioEndpointVolume._iid_, CLSCTX_ALL, None)
                volume = cast(interface, POINTER(IAudioEndpointVolume))
                callback = AudioEndpointVolumeCallback()
                volume.RegisterControlChangeNotify(callback)
                
                
                
                try:
                    if isinstance(int(sys.argv[1]),int):
                        fala('volume definido para ' + str(int(sys.argv[1])))
                        volume.SetMasterVolumeLevelScalar(int(sys.argv[1])/100,None)
                except:
                    fala(' '.join(list2))
                
                
                

                So if I say a number it changes the volume, but if I say a color or "Turn on/off" it says On, Off or the Color. (Basically it tries to say it out loud if the parameter is not a number)

                Now, it only works during On and Off. All the colors or the numbers are not working as valid parameters.

                This is how it is coded in TriggerCMD currently:

                 {
                  "trigger": "Protocolo",
                  "command": "python \"D:\\Programming\\Python\\teste vozes.py\"",
                  "offCommand": "",
                  "ground": "foreground",
                  "voice": "Protocolo",
                  "voiceReply": "",
                  "allowParams": "true"
                 }
                
                R 1 Reply Last reply Apr 9, 2022, 2:06 AM Reply Quote 0
                • R
                  Russ @Moacir Vilela Sêga
                  last edited by Apr 9, 2022, 2:06 AM

                  @moacir-vilela-sêga , will you please try this simpler script that just prints and logs the first parameter?

                  import os, sys
                  
                  f = open(os.path.dirname(os.path.realpath(__file__)) + "\log.txt", "a")
                  msg = "first arg is " + sys.argv[1] + "\n"
                  print(msg)
                  f.write(msg)
                  f.close()
                  

                  Also, please try running your script from a cmd prompt with red or 80 as the parameter to see if it's erroring. I wonder if it's erroring and you're just not seeing the output so you don't see the error.

                  Russell VanderMey

                  M 1 Reply Last reply Apr 10, 2022, 5:01 PM Reply Quote 0
                  • M
                    Moacir Vilela Sêga @Russ
                    last edited by Apr 10, 2022, 5:01 PM

                    @russ I dont know what to tell you now. It is just working normally now. I didn't change neither my script nor tried to re-add the device.
                    I decided to test it before changing to your script and it worked.

                    R 1 Reply Last reply Apr 11, 2022, 12:12 PM Reply Quote 0
                    • R
                      Russ @Moacir Vilela Sêga
                      last edited by Apr 11, 2022, 12:12 PM

                      @moacir-vilela-sêga , strange. I don't know what fixed it either.

                      Russell VanderMey

                      1 Reply Last reply Reply Quote 0
                      • First post
                        Last post