I have installed the google assistant SDK on a raspberry pi 3 and have so far managed to get Spotify working, and managed to get IFTTT to run for lights. What I really want to know is whether it is possible to have google assistant run and interact with python scripts on the pi. By which I mean I have a script called sound_the_alarm.py which pulls news from different sources, gives updates on bitcoin etc, and then plays a random song from my library, and turns on a light via gpio. I would like to be able to say “ok google sound the alarm at 7:00 tomorrow and have it update the crib tab with an instance of the alarm. Is this possible? I have found nothing online suggesting so!
Thanks
Will
It is possible, but not directly, as I know.
I use IFTTT for that (check on youtube how easy it is).
The easiest way is to have public IP with your raspberry, but it is dangerous (see below for solution).
Log into ifttt.com and make an applet: Google Assistant Command to Webhook. It is a piece of cake. You will learn it in minutes (use youtube for tutorial).
You type as a webhook public IP of your raspberry with a link to PHP app.
Your PHP app fetches the info about command from Google Assistant and exec("Your command here");
Additional info:
It is probably possible to make fetching app in Python instead of PHP, but I am not a Python programmer, so I cannot help with it. I use PHP for that.
It is MUUUCH SAFER to make additional "Gate Server". Take the cheapest hosting provider. Make an APP on this server (probably in PHP :P). Your IFTTT sends a request to the Gate (instead of raspberry directly). And your raspberry pi contacts the gate checking if there are no any orders for it. If there is any, it follows the order. Because of that nobody knows your raspberry IP address. You can hide it behind the router so it is more less safe.
I hope my solution is understandable :).
K.
Related
I have machine A that just cranks out .png files. It gets synced to machine B and I view it on machine B.
Sometimes machine A crashes for whatever reason and stops doing the scheduled jobs, which means then files on machine B will be old.
I want machine B to run a script to see if the file is older than 1 day, and if it is, then reset the power switch on machine A, so that it can be cold booted. The switch is connected to Google Home but understand I have to use the Assistant API.
I have installed the google-assistant-sdk[samples] package. Can someone show me some code on how to query and return all devices then flip the switch on and off on that device?
Unfortunately, many smart home companies are building products for consumers, not developers. Google's SDK is letting developers stream consumer voice requests to their servers and turning that into actions. Gosund, similarly, is only interested in API access for Amazon and Google. They're API is probably not documented for public use.
To answer your specific question, if you want to use the Google Assistant SDK, you would name your switch something like "Server A Switch" and record a short clip of you saying "Turn off Server A Switch" and "Turn on Server A Switch" and send those two google. The way google matches the requests with your particular account is through OAuth2 tokens, which google will give you in exchange for valid sign in credentials.
If Gosund works with Google Assistant, it has a standard OAuth2 server endpoint as well as a Google Assistant compliant API endpoint. I only recommend this if you want to have some fun reverse engineering it.
In your Google Assistant app, if you try adding the Gosund integration, the first screen popup is the url endpoint where you can exchange valid Gosund account credentials for a one-time code which you can then exchange for OAuth2 access and refresh tokens. With the access token you can theoretically control your switch. The commands you'll want to send are standardized by Google. However, you'll have to figure out where to send them. The best bet here is probably to email their developers.
Are you familiar with OAuth2? If not, I don't recommend doing any of the above.
Your other option is to prevent Server A from hardware crashes. This is what I recommend as the least amount of work. You should start with a server that never crashes, keep it that way and add stuff on top of it. If you only have two servers, they should be able to maintain many months of uptime. Run your scheduled jobs using cron or systemctl and have a watchdog that restarts the job when it detects an error. If your job is crashing the server maybe put it in a VM like docker or something, which gives you neat auto-restart capabilities off the bat.
Another hacky thing you can do is schedule your gosund plug to turn off and on once a day through their consumer UI or app, or at whatever frequency you feel like is most optimal.
The google-assistant-sdk is intended for processing audio requests.
From the doc:
Your project captures an utterance (a spoken audio request, such as What's on my calendar?), sends it to the Google Assistant, and receives a spoken audio response in addition to the raw text of the utterance.
While you could use that with some recorded phrases it makes more sense to connect to the switch directly or use a service like IFTTT. What kind of switch is it?
I have multiple discord bots that I make and host for people. I was looking to make a page on my website to show the stdout, stderr and uptime of each of my bots on this page.
Each bot runs in a separate "screen", which is created using the screen package as provided: here
I can easily pipe the stdout and stderr to any file if needed.
I am running ubuntu 18.04 and I personally own the machine so there are little to no limitations on what I am able to do with it.
My python version is: Python 3.6.4
The discord bot API is discord.py v1.4.1 (rewrite) as seen: here
v1.5.0 is newly released so I'm waiting to update to it, while checking the changelog I didn't notice anything that could affect this project so there should be no issues
I am not concerned about the layout of the website as all styling will be done later, I just want to see if there is a way that I can take the values specified above and put them in a web page. I have some experience in js and am quite experienced in theoretical knowledge, so not knowing exactly how to code in it shouldn't be too much of a problem (I hope)
I have searched around for a while but couldn't find any solutions. Hope someone here can help :)
Uptime monitoring websites is not directly a feature of discord.py, because it would add a whole layer of complexity 😔.
You can write your own HTTP web server to serve your website's content (ie. to keep track of uptime, downtime, etc. by yourself 😫), but that would probably end up being overly complicated.
If you don't want this extreme complexity, you can use ⚒️ UptimeRobot (not affiliate link) to create a status page for you. All you have to do is open an HTTP endpoint on the same server that's running your Discord bot (preferably in the same process, maybe a different thread), so UptimeRobot knows when your Discord bot comes 🟢 online and goes 🔴 offline.
To create the HTTP endpoint, you can use the built in http.server module, or 🛠️ Flask. Note that, in order for UptimeRobot to make a connection with the server hosting the Discord bot, port forwarding needs to be done. If you don't have access to the network, you can use a service like 🧰 ngrok to publicly expose the port the server is running on.
All services mentioned above are free 🤑, and are not affiliate links. 🤗
I'm plenty proficient with Python's Selenium module which is for web interaction/automation. I have a Feit Electric Smart Wifi Plug that I'm looking to work with. Feit seems to have one mobile (barely decent) app but no desktop accessible website to control their products.
They do seem to work with Amazon Alexa and Google Assistant. I paired it up via the mobile Alexa app (you don't actually need to have an Alexa to pair the plug to the Alexa app). I learned Alexa has a web interface (alexa.amazon.com) but upon further investigation, it only shows the name of the device (Feit smartplug) and the option to remove it, it does not let me interact with it.
Google Assistant doesn't even have a website (as far as I can tell) otherwise I'd try that. Essentially what I'm looking for is a website to control this product with, it should be one of the following.
A better Amazon Alexa profile that lets me interact with the devices (unless someone can show me how to do that with the current one)
An online Google Assistant interface where I can control my device
Some type of Feit Electric online website to control my devices
I should add it works with Siri shortcuts, so if I can access Siri Shortcuts online, that would help as well.
From what I gather, it seems like you're looking for a web-based way to control this device and not necessarily integrate with one of the assistant platforms.
The assistant platforms mentioned are generally meant to be processed on a mobile device or speaker and don't necessarily have a web-based runner. Though there are some APIs meant for embedded devices, I don't think you'd want that.
Instead, I think what you'd probably want instead is to look at using a platform like Home Assistant, which provides a mechanism for controlling various smart home devices through various interfaces including web. There's one example of someone connecting the Feit bulbs to Home Assistant on top of the Tuya platform. That post includes how they set it up, and a handful of caveats they ran into.
I am relatively new to programming. I have a project where I need to control things like pumps and read data from sensors. I currently have a flask webserver set up on a raspberry and can access that website only from within my local network.
My objective is to change my flask webserver to a flask REST APi. Then I want to set up my raspberry pi on a cloud/iot platform and control my pi over the cloud via the flask REST api.
Any idea on how to best do this? Ive been researching it a lot and could use some help.
I would setup the api endpoints like you discussed. Those endpoints I assume would allow you to control the sensors and whatever other hardware is attached to the GPIO. Then as you mentioned you would expose that API to some sort of an IOT platform. AWS offers a nice solution however there are many.
I have come a relatively long way from what I knew when asking this question. For other new programmers trying to figure out how to bring their project/idea to reality here is what I did to deploy my local flask web server on the pi to "the cloud":
I used a company named linode to host my web server on, but there are many other cloud platforms you could choose from like digital ocean and heroku. All I did was purchase their entry level plan, connect via ssh to the new server, copy over the files containing my web server, and add security provisions. Then you can use ssh to connect to your server and use the terminal to do what you need. This was the processes that I followed to deploy to the cloud. There are an abundance of options and ways to do this, but I found this option relatively flexible and cost effective...giving me the chance to participate in the IoT world.
I know this information is obvious to a lot of experienced programmers, but for the ones just getting started I hope this explanation can provide some clarity on your way forward.
I have written a python code that I can run it on my computer. It gets stock data from a website by GET request. Then it does some calculations on upon these online data and decides to send a buy/sell request to my broker's account.
All of these works fine on my computer, but I like to upload my code on a web server to preventing electricity/internet disconnection. I think I should upload my code on a virtual server, but this is all the thing I know and I don't have more experience or knowledge about it. I don't know if it is what I need, how can I do that?
In my experience of making some simple web pages, we should put our main code inside the public.html file? So should I buy a web host and wrap my python code inside a .html file?
Sorry if they are simple/stupid questions but I couldn't find any answer or guidence for doung what I want, so I asked here!
With the info you provide I can't really be sure how your script is ran.
I presume you run it by shell in that case a simple vps should suffice.
No need to mess around with a webserver.
Maybe look at Digital Ocean. They are a market leader and the simple $5 option probably enough for your purpose.
When you set it up you can connect to it with ssh (preferably with a ssh key because you are working with financial data) and setup your python script as if it were your own computer.
Ps. I don't work for digital ocean or get money from the link. It is just an example, any vps will work.