I'm currently working my assignment to use google home to control the Led brghtness with pwm from raspberry pi 3. i've found some good tutorial on youtube and the internet, and now the connection beetwen google home and raspberry is connected with IFTTT and dataplicity (the ifttt send webhook JSON file to dataplicity, forwarded to port 80 raspberry, and forwarded again by nginx to port 5000 where my google home local raspberry server located). So let's just say there is no problem at the google home connection, i'll give you my entire code :

import RPi.GPIO as GPIO
import json
import os
from flask import Flask
from flask import request
from flask import make_response

app = Flask(__name__)

GPIO.setmode(GPIO.BOARD) ## Use board pin numbering
GPIO.setup(12, GPIO.OUT)

def index():
    req = request.get_json(silent=True, force=True)
    val = processRequest(req)
    r = make_response(json.dumps(val))
    r.headers['Content-Type'] = 'application/json'
    return r

def processRequest(req):
    device = req['device']
    state = json.loads(req['state'])
    if (device=='bedlamp'):  
        pwm_led = GPIO.PWM(12, 100)
        while True :
            if (device=='bedlamp low'):
    return {
    "speech": "it is done",
    "displayText": "it is done",
    # "data": data,
    # "contextOut": [],
    "source": "apiai-weather-webhook-sample"

if __name__ == '__main__':
    app.run(debug=True, host='', port=5000)

As you can see, the led can be controlled after the command turn the bedlamp on given to google home. and after the on command given, the pwm can be adjusted to low level (30), medium level (60) and high level (100). i've tried give turn on bedlamp, and it works. but when i tried to control the pwm it won't work (i think it's because the sequence of the "turn on bedlamp" have broken when i say another command to my google home). it just nothing happen, the pwm always stay at 100.

so how can i control my pwm with these sequence?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.