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

    Say room temperature and humidity

    Raspberry Pi
    raspberry pi alexa google assistan
    2
    9
    968
    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.
    • tuicemenT
      tuicemen
      last edited by tuicemen

      This was inspired by @hm123 thread google-assistant-say-the-raspberry-pi-temperature

      Things you will need for this
      You will need a DHT22 or DHT11 temperature/humidity sensor

      I used this tutorial https://www.thegeekpub.com/236867/using-the-dht11-temperature-sensor-with-the-raspberry-pi/ to help.

      I used the pi in my office so this is the trigger:

      {"trigger":"office con","command":"python3 /home/pi/scripts/DHT.py 4 22","ground":"background","voice":"Office conditions","voiceReply":"Current office conditions are {{result}} percent","allowParams": "false"},
       
      

      The python script allows for a DHT11 or DHT22 and to use different GPIO pins thus the 4(pin) and 22(the DHT) in the command.

      #Libraries
      import Adafruit_DHT as dht
      import sys
      import os
      #Set DATA pin
      Pin = sys.argv[1]
      DHT = int(sys.argv[2])
      if DHT == 11:
         #Read Temp and Hum from DHT11
        h,t = dht.read_retry(dht.DHT11 , Pin)
       #Print Temperature and Humidity on Shell window
        print('Temperature print={0:0.1f}  Humidity={1:0.1f}'.format(t,h))
        result = ('Temperature={0:0.1f}Humidity={1:0.1f}'.format(t,h))
        os.system('~/.TRIGGERcmdData/sendresult.sh ' + 'Temp={0:0.1f}  Humidity={1:0.1f}'.format(t,h))
      
      if DHT == 22:
         #Read Temp and Humidity from DHT22
         h,t = dht.read_retry(dht.DHT22 , Pin)
         #Print Temperature and Humidity on Shell window
         print('Temp={0:0.1f}  Humidity={1:0.1f}'.format(t,h))
         result = ('Temperature={0:0.1f}Humidity={1:0.1f}'.format(t,h))
         os.system('~/.TRIGGERcmdData/sendresult.sh ' + result)
      
      quit
      

      if you have the DHT hooked up correctly and you execute the script from the shell you should see a return something like this:
      Temp=20.1 Humidity=32.1
      sh: 1: /home/pi/.TRIGGERcmdData/sendresult.sh: not found
      pi@raspberrypi:~/scripts $

      RussR 1 Reply Last reply Reply Quote 0
      • RussR
        Russ @tuicemen
        last edited by

        @tuicemen, nice work! I don't see many examples that use the {{result}} placeholder to send back the result of a command using the sendresult script. It's good to see someone's using it.

        Russell VanderMey

        tuicemenT 1 Reply Last reply Reply Quote 0
        • tuicemenT
          tuicemen @Russ
          last edited by

          @russ, Thanks. I actually have several Ideas for {{result}} placeholder to send back the result of a command using the sendresult script.

          I remember some users on the x10 forums saying they wished Alexa could say different things when a command was asked. The routines work fine for simple replies but not if you need a specific value.

          RussR 1 Reply Last reply Reply Quote 0
          • RussR
            Russ @tuicemen
            last edited by

            @tuicemen , come to think of it, I think you would get the reply if you use the "custom" action in a routine with the Trigger Command skill.

            Russell VanderMey

            tuicemenT 1 Reply Last reply Reply Quote 0
            • tuicemenT
              tuicemen @Russ
              last edited by

              @russ Thanks I did play with routines a little this morning but may have given up to soon.
              I'll play a bit more to see if I can get that to work.

              RussR 1 Reply Last reply Reply Quote 0
              • RussR
                Russ @tuicemen
                last edited by Russ

                @tuicemen, I just tried it. It worked nicely.

                Here's my Alexa Routine config:

                result_test.png

                I'm using the TRIGGERcmd skill which works the same as the Trigger Command skill.

                I used a "Custom" action with this text: ask TRIGGER C M D to run result

                My command config looks like this:
                1f8b8041-27a9-405d-bdc3-91e26ca90b48-image.png

                My super basic python script looks like this:

                import os
                result = 'Nineteen'
                sts = os.system(os.environ['USERPROFILE'] + "\\.TRIGGERcmdData\\SendResult.bat "+str(result))
                

                Russell VanderMey

                tuicemenT 1 Reply Last reply Reply Quote 1
                • tuicemenT
                  tuicemen @Russ
                  last edited by

                  @russ, Thanks. It took me A few times to get it to work I was using TRIGGERcmd as one word needed the spaces ( C M D).

                  tuicemenT 1 Reply Last reply Reply Quote 1
                  • tuicemenT
                    tuicemen @tuicemen
                    last edited by tuicemen

                    @tuicemen I tested this again this morning and got the reply running on fire tv😖
                    This is what I was getting while trying to setup prior to it working. I've since switched to using Trigger command which worked reliably for me before setting up the routine. Time will tell if it continues to work flawlessly.

                    tuicemenT 1 Reply Last reply Reply Quote 0
                    • tuicemenT
                      tuicemen @tuicemen
                      last edited by

                      If your like me and find the decimal point in the return a bit confusing you can change the line

                       os.system('~/.TRIGGERcmdData/sendresult.sh ' + 'Temp={0:0.1f}  Humidity={1:0.1f}'.format(t,h))
                      

                      to

                      os.system('~/.TRIGGERcmdData/sendresult.sh ' + 'Temp={0:0.0f}  Humidity={1:0.0f}'.format(t,h))
                      

                      if you wish the return to send a Fahrenheit value instead of Celsius you can add the line

                      t = (t* 1.8) + 32
                      

                      just after the line

                      #Print Temperature and Humidity on Shell window
                      
                      1 Reply Last reply Reply Quote 1
                      • tuicemenT tuicemen referenced this topic on
                      • First post
                        Last post