This project helps the user to know his/her current room temperature and suggests whether to turn on the Air conditioner or Heaters according to the temperature.
All of this is done with just an voice command to the Google Assistant "Hey Google ask wayscript trigger to run bolttemp" and the user gets the response in a matter of seconds. This can be integrated with other voice assistants like Alexa and Siri as well, here in this project I'm integrating with Google Assistant.
** 'bolttemp' is the name of my script on WayScript
ProcedureStep 1: Hardware setup1. Connect the VCC pin of LM-35 sensor to 5V pin of the Bolt device.
2. Connect the GND pin of LM-35 sensor to GND pin of the Bolt device.
3. Connect the analog output pin of LM-35 sensor to Analog input (A0) pin of the Bolt device.
- Make use of the male to female jumper wires to connect the temperature sensor to the bolt module
Power on the bolt module once all the connections are made. Ensure that there aren't any lose connections.
The blue LED indicates that the module is powered on and the green LED indicates that the module is connected to the bolt cloud via wifi.
Step 2: Getting the Bolt API key and Device IDLogin to cloud.boltiot.com and copy the device ID.
Head to the API section to find the API key (Enable the key if it's disabled and click on 'Generate API key').
Save the API key and Bolt ID safely in a text file for future use.
Step 3: Setting up WayScript for Google assistant triggerHead over to www.wayscript.com and create a free account. You can also sign up using LinkedIn or github.
Create a new script by clicking on the button on the top right corner of the screen.
1. Creating a trigger
Click on 'Add Trigger' and choose Google Assistant from the list. The first time you use this module, you will have to connect to your Google account and link it to WayScript.
2. Executing the python script to get data from the temperature sensor
Since we want this Google assistant trigger to execute a python script, click on add step and choose python and paste the below code.
Add boltiot to the requirments.txt file
from boltiot import Bolt
import json, time
API_KEY = 'Your API_KEY'
DEVICE_ID = 'Your BOLT_ID'
mybolt = Bolt(API_KEY, DEVICE_ID)
response = mybolt.analogRead('A0')
data = json.loads(response)
if str(data['value']) == 'Device is offline':
print("Device is offline ")
outputs[ 'MessageBack' ] = 'Device is offline'
else:
sensor_value = int(data['value'])
temp = round(((100*sensor_value)/1024),1) #converting sensor value to degrees celsius
print ("The current room temperature is", temp, "degrees celsius")
outputs[ 'temperature' ] = 'The current room temperature is ' + str(te mp) + ' degrees celsius'
'''Conditions to check the temperature and return the suitable response depending on the temperature range '''
if temp >= 30 and temp <= 40:
print ("Turn on the fan/Ac")
outputs[ 'MessageBack' ] = 'Turn on the fan/AC'
elif temp >= 18 and temp < 30:
print ("Enjoy the natural winds !!!")
outputs[ 'MessageBack' ] = 'Enjoy the natural winds !!!'
elif temp >= -10 and temp < 18:
outputs[ 'MessageBack' ] = 'Turn on the heaters'
else:
outputs[ 'MessageBack' ] = 'Please diagnose the temperature sensor'
By placing this under Google assistant trigger, this python script will execute any time a message is received and records temperature from the LM-35 sensor and passes data through the Bolt cloud. This code outputs 2 variables namely temperature and MessageBack.
Code Explanation
- Initialising the bolt module
mybolt = Bolt(API_KEY, DEVICE_ID)
- Getting the sensor value from the Analog input (A0) pin
response = mybolt.analogRead('A0')
- The response returned by the Bolt Cloud needs to be converted into a JSON object for ease of use. The following code converts the response from the Bolt Cloud into a JSON object.
data = json.loads(response)
- Simple formula to convert sensor value obtained from LM-35 sensor to temperature in degrees celsius and rounding it off to 1 decimal place for readability.
temp = round(((100*sensor_value)/1024),1)
3. Passing back the response
Now that we've created the response in the python module and received the sensor readings, let's pass it back to the user's Google assistant.
We can write the response that we want into the body of the message. Here lets pass the variables temperature and MessageBack to the user as text and speech.
This will return the python response directly back to the user when triggered from Google assistant.
Output Screenshots** BoltTemp is the name of my script on WayScript. You can provide any suitable name for your script.
Comments