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

Say room temperature and humidity

Raspberry Pi
raspberry pi alexa google assistan
2
9
1.1k
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.
  • T
    tuicemen
    last edited by tuicemen Jan 11, 2022, 9:59 PM Jan 11, 2022, 9:50 PM

    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 $

    R 1 Reply Last reply Jan 12, 2022, 2:26 AM Reply Quote 0
    • R
      Russ @tuicemen
      last edited by Jan 12, 2022, 2:26 AM

      @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

      T 1 Reply Last reply Jan 12, 2022, 12:34 PM Reply Quote 0
      • T
        tuicemen @Russ
        last edited by Jan 12, 2022, 12:34 PM

        @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.

        R 1 Reply Last reply Jan 12, 2022, 1:35 PM Reply Quote 0
        • R
          Russ @tuicemen
          last edited by Jan 12, 2022, 1:35 PM

          @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

          T 1 Reply Last reply Jan 12, 2022, 1:44 PM Reply Quote 0
          • T
            tuicemen @Russ
            last edited by Jan 12, 2022, 1:44 PM

            @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.

            R 1 Reply Last reply Jan 12, 2022, 11:25 PM Reply Quote 0
            • R
              Russ @tuicemen
              last edited by Russ Jan 12, 2022, 11:26 PM Jan 12, 2022, 11:25 PM

              @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

              T 1 Reply Last reply Jan 13, 2022, 1:52 AM Reply Quote 1
              • T
                tuicemen @Russ
                last edited by Jan 13, 2022, 1:52 AM

                @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).

                T 1 Reply Last reply Jan 13, 2022, 1:01 PM Reply Quote 1
                • T
                  tuicemen @tuicemen
                  last edited by tuicemen Jan 13, 2022, 1:05 PM Jan 13, 2022, 1:01 PM

                  @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.

                  T 1 Reply Last reply Jan 13, 2022, 5:16 PM Reply Quote 0
                  • T
                    tuicemen @tuicemen
                    last edited by Jan 13, 2022, 5:16 PM

                    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
                    • T tuicemen referenced this topic on Jan 26, 2022, 11:26 AM
                    8 out of 9
                    • First post
                      8/9
                      Last post