Say room temperature and humidity
-
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 sensorI 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 $ -
@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.
-
@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.
-
@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.
-
@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. -
@tuicemen, I just tried it. It worked nicely.
Here's my Alexa Routine config:
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:
My super basic python script looks like this:
import os result = 'Nineteen' sts = os.system(os.environ['USERPROFILE'] + "\\.TRIGGERcmdData\\SendResult.bat "+str(result))
-
@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).
-
@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. -
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
-