SlideShare una empresa de Scribd logo
1 de 92
Home Automation with
Android Things and the
Google Assistant
Android is everywhere
Google Assistant Shoebox Robot(01)
(01)
http://nilhcem.com/android-things/create-your-google-assistant-robots
In your Home?
OK Google,
Philips Hue Bridge
https://developers.google.com/actions/
OAuth2 server
Device Actions
• SYNC
• EXECUTE
• QUERY
SYNC Request:
{
"requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
"inputs": [{
"intent": "action.devices.SYNC"
}]
}
SYNC Response:
{
"requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
"payload": {
"devices": [{
"id": "1",
"type": "action.devices.types.LIGHT",
"traits": [
"action.devices.traits.OnOff",
"action.devices.traits.ColorSpectrum"
],
"name": {
"name": "Lightbulb"
},
"willReportState": true
}]
}
}
Device types:
Camera Refrigerator
Dishwasher Switch
Dryer Thermostat
Light Vacuum
Outlet Washer
Device traits:
Brightness OnOff
CameraStream RunCycle
ColorSpectrum Scene
ColorTemperature StartStop
Dock TemperatureSetting
Modes Toggles
"Ok Google,
"
Smart Home Device Traits(03)
(03)
https://developers.google.com/actions/smarthome/traits/
https://cloud.google.com/functions/?hl=ja
exports.ha = function(req, res) {
if (!isAuthTokenValid(req)) return;
let intent = req.body.inputs[0].intent;
switch (intent) {
case 'action.devices.SYNC':
sync(req, res);
break;
case 'action.devices.EXECUTE':
execute(req, res);
break;
case 'action.devices.QUERY':
query(req, res);
break;
}
};
function sync(req, res) {
res.status(200).json({
requestId: req.body.requestId,
payload: {
devices: [{
id: 'lightbulb',
type: 'action.devices.types.LIGHT',
traits: [
'action.devices.traits.OnOff',
'action.devices.traits.ColorSpectrum'
],
name: {
name: 'Lightbulb'
},
willReportState: true
}]
}
});
}
$ gcloud beta functions deploy ha --trigger-http
https://us-central1-your-id.cloudfunctions.net/ha
Device Actions
• SYNC
• EXECUTE
• QUERY
EXECUTE Request:
{
"requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
"inputs": [{
"intent": "action.devices.EXECUTE",
"payload": {
"commands": [{
"devices": [{
"id": "lightbulb"
}],
"execution": [{
"command": "action.devices.commands.OnOff",
"params": {
"on": true
}
}]
}]
}
}]
}
EXECUTE Response:
{
"requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
"payload": {
"commands": [{
"ids": ["lightbulb"],
"status": "SUCCESS",
}]
}
}
Device Actions
• SYNC
• EXECUTE
• QUERY
QUERY Request:
{
"requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
"inputs": [{
"intent": "action.devices.QUERY",
"payload": {
"devices": [{
"id": "lightbulb"
}]
}
}]
}
QUERY Response:
{
"requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
"payload": {
"devices": {
"lightbulb": {
"on": false,
"online": true,
"color": {
"spectrumRGB": 16777215
}
}
}
}
}
Raspberry Pi 3
FirestoreLiveData.kt
class FirestoreLiveData : LiveData<Device>() {
override fun onActive() {
authenticateWithFirebase { user ->
listenForFirestoreChanges("users/${user.uid}/devices") { change ->
postValue(change)
}
}
}
}
const admin = require('firebase-admin');
admin.initializeApp({
credential: admin.credential.applicationDefault()
});
var db = admin.firestore();
var docRef = db.doc(`users/${userId}/devices/lightbulb`);
docRef.set({ on: true, spectrumRGB: 255 });
Lightbulbs
Bluetooth lightbulbs
Reverse engineering
Bluetooth Low Energy devices(04)
(04)
http://nilhcem.com/iot/reverse-engineering-simple-bluetooth-devices
Capture Bluetooth packets
$ adb pull /sdcard/Android/data/btsnoop_hci.log
• Value: 56RRGGBB00f0aa
• Characteristic: ffe9
• Service: ffe5
Android Things app
Converting a color to a ByteArray
private fun colorToByteArray(color: Int): ByteArray {
val red = Color.red(color)
val green = Color.green(color)
val blue = Color.blue(color)
return byteArrayOf(0x56, red, green, blue, 0x00, 0xf0, 0xaa)
}
Send the color data to the lightbulb
private fun writeCharacteristic(gatt: BluetoothGatt, color: Int) {
val service = gatt.getService(SERVICE_UUID) // 0xFFE5
val characteristic = service.getCharacteristic(CHARACTERISTIC_UUID) // 0xFFE9
characteristic.value = colorToByteArray(color)
gatt.writeCharacteristic(characteristic)
}
MainActivity.kt
firestoreLiveData.observe({ lifecycle }) { device ->
when (device) {
is Lightbulb -> lightbulb.updateState(device)
}
}
Update Firestore
Fan + Relay module
Android Things GPIO API
viewModel.firestoreLiveData.observe({ lifecycle }) { device ->
when (device) {
is Lightbulb -> lightbulb.onStateChanged(device)
is Fan -> relay.value = device.isOn
}
}
Radio-controlled Power Outlets
Radio Frequency Emitter / Receiver(05)
(05)
https://github.com/Nilhcem/home-automation-talk-resources/tree/master/radio-power-outlet
Android Things UART API
private fun on() = sendUart('1')
private fun off() = sendUart('0')
private fun sendUart(char: Char) {
uartDevice?.write(byteArrayOf(char.toByte()), 1)
}
private fun openUart() {
uartDevice = PeripheralManagerService().openUartDevice(UART_NAME).apply {
setBaudrate(9600)
setDataSize(8)
setParity(UartDevice.PARITY_NONE)
setStopBits(1)
}
}
Infrared blaster
Infrared Receiver (VS1838B)(06)
(06)
https://github.com/Nilhcem/home-automation-talk-resources/tree/master/infrared-lamp/01-arduino_receiver
Infrared Receiver (VS1838B)
Infrared dump
Encoding : UNKNOWN
Code : E318261B (32 bits)
Timing[67]:
+8950, -4550 + 500, - 650 + 500, - 650 + 500, - 650
+ 500, - 650 + 500, - 650 + 500, - 650 + 500, - 650
+ 500, - 650 + 500, -1750 + 500, -1700 + 500, -1800
+ 450, -1750 + 450, -1800 + 450, -1750 + 450, -1750
+ 500, -1750 + 450, -1750 + 500, - 650 + 500, -1750
+ 500, - 650 + 500, - 650 + 500, - 650 + 500, -1750
+ 450, - 700 + 450, - 700 + 450, -1750 + 500, - 700
+ 450, -1750 + 500, -1700 + 500, -1750 + 500, - 650
+ 500, -1750 + 450
unsigned int rawData[67] = {8950,4550, 500,650, 500,650, 500,650, 500,650,
500,650, 500,650, 500,650, 500,650, 500,1750, 500,1700, 500,1800, 450,1750,
450,1800, 450,1750, 450,1750, 500,1750, 450,1750, 500,650, 500,1750, 500,650,
500,650, 500,650, 500,1750, 450,700, 450,700, 450,1750, 500,700, 450,1750,
500,1700, 500,1750, 500,650, 500,1750, 450}; // UNKNOWN E318261B
ESP8266(07)
(07)
https://github.com/Nilhcem/home-automation-talk-resources/tree/master/infrared-lamp/03-
esp8266_transmitter
Retrofit call
@GET("color/{code}")
fun setBulbColor(@Path("code") code: Char): Call<Any>
Takeaway
• Actions on Google for chatbots & smart home apps. For
companies & individuals
• Android Things simplifies building secured & advanced IoT
devices
• Create your own devices, or hack existing ones for
interoperability
• Easier than it seems
Additional information
• Source code for all the projects:
https://github.com/Nilhcem/home-automation-talk-resources
• Home automation with the Google Assistant:
http://nilhcem.com/android-things/google-assistant-smart-home
• Actions on Google Smart Home documentation:
https://developers.google.com/actions/smarthome/
• Reverse engineering BLE devices:
http://nilhcem.com/iot/reverse-engineering-simple-bluetooth-devices
• Reverse engineering IR devices:
http://nilhcem.com/iot/reverse-engineering-ir-rgb-bulb
Home Automation with
Android Things and the
Google Assistant
• Twitter: @Nilhcem

Más contenido relacionado

La actualidad más candente

bullismo e scuola primaria
bullismo e scuola primariabullismo e scuola primaria
bullismo e scuola primaria
imartini
 
Interactive Music II ProcessingとSuperColliderの連携 -2
Interactive Music II ProcessingとSuperColliderの連携 -2Interactive Music II ProcessingとSuperColliderの連携 -2
Interactive Music II ProcessingとSuperColliderの連携 -2
Atsushi Tadokoro
 
Riga DevDays 2017 - The hitchhiker’s guide to Java class reloading
Riga DevDays 2017 - The hitchhiker’s guide to Java class reloadingRiga DevDays 2017 - The hitchhiker’s guide to Java class reloading
Riga DevDays 2017 - The hitchhiker’s guide to Java class reloading
Anton Arhipov
 

La actualidad más candente (20)

The Ring programming language version 1.5.1 book - Part 45 of 180
The Ring programming language version 1.5.1 book - Part 45 of 180The Ring programming language version 1.5.1 book - Part 45 of 180
The Ring programming language version 1.5.1 book - Part 45 of 180
 
Java final project of scientific calcultor
Java final project of scientific calcultorJava final project of scientific calcultor
Java final project of scientific calcultor
 
bullismo e scuola primaria
bullismo e scuola primariabullismo e scuola primaria
bullismo e scuola primaria
 
Raspberry Pi with Java (JJUG)
Raspberry Pi with Java (JJUG)Raspberry Pi with Java (JJUG)
Raspberry Pi with Java (JJUG)
 
When Bad Things Come In Good Packages
When Bad Things Come In Good PackagesWhen Bad Things Come In Good Packages
When Bad Things Come In Good Packages
 
Powered by Python - PyCon Germany 2016
Powered by Python - PyCon Germany 2016Powered by Python - PyCon Germany 2016
Powered by Python - PyCon Germany 2016
 
CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak
CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak   CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak
CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak
 
Using Redux-Saga for Handling Side Effects
Using Redux-Saga for Handling Side EffectsUsing Redux-Saga for Handling Side Effects
Using Redux-Saga for Handling Side Effects
 
Interactive Music II ProcessingとSuperColliderの連携 -2
Interactive Music II ProcessingとSuperColliderの連携 -2Interactive Music II ProcessingとSuperColliderの連携 -2
Interactive Music II ProcessingとSuperColliderの連携 -2
 
WebXR if X = how?
WebXR if X = how?WebXR if X = how?
WebXR if X = how?
 
Python Coroutines, Present and Future
Python Coroutines, Present and FuturePython Coroutines, Present and Future
Python Coroutines, Present and Future
 
Unbreakable: The Craft of Code
Unbreakable: The Craft of CodeUnbreakable: The Craft of Code
Unbreakable: The Craft of Code
 
Kinect de-theremin
Kinect de-thereminKinect de-theremin
Kinect de-theremin
 
Extending grimoirelab
Extending grimoirelabExtending grimoirelab
Extending grimoirelab
 
Internet of Things Magic Show
Internet of Things Magic ShowInternet of Things Magic Show
Internet of Things Magic Show
 
Cluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in CCluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in C
 
ES6 patterns in the wild
ES6 patterns in the wildES6 patterns in the wild
ES6 patterns in the wild
 
Python meetup: coroutines, event loops, and non-blocking I/O
Python meetup: coroutines, event loops, and non-blocking I/OPython meetup: coroutines, event loops, and non-blocking I/O
Python meetup: coroutines, event loops, and non-blocking I/O
 
Riga DevDays 2017 - The hitchhiker’s guide to Java class reloading
Riga DevDays 2017 - The hitchhiker’s guide to Java class reloadingRiga DevDays 2017 - The hitchhiker’s guide to Java class reloading
Riga DevDays 2017 - The hitchhiker’s guide to Java class reloading
 
Metaprogramming and Reflection in Common Lisp
Metaprogramming and Reflection in Common LispMetaprogramming and Reflection in Common Lisp
Metaprogramming and Reflection in Common Lisp
 

Similar a Home Automation with Android Things and the Google Assistant

HTML pour le web mobile, Firefox OS - Devfest Nantes - 2014-11-07
HTML pour le web mobile, Firefox OS - Devfest Nantes - 2014-11-07HTML pour le web mobile, Firefox OS - Devfest Nantes - 2014-11-07
HTML pour le web mobile, Firefox OS - Devfest Nantes - 2014-11-07
Frédéric Harper
 
JavaZone 2022 - Building Kotlin DSL.pdf
JavaZone 2022 - Building Kotlin DSL.pdfJavaZone 2022 - Building Kotlin DSL.pdf
JavaZone 2022 - Building Kotlin DSL.pdf
Anton Arhipov
 

Similar a Home Automation with Android Things and the Google Assistant (20)

Firefox OS, fixing the mobile web - FITC Toronto - 2014-04-28
Firefox OS, fixing the mobile web - FITC Toronto - 2014-04-28Firefox OS, fixing the mobile web - FITC Toronto - 2014-04-28
Firefox OS, fixing the mobile web - FITC Toronto - 2014-04-28
 
TechShift: There’s light beyond LAMP
TechShift: There’s light beyond LAMPTechShift: There’s light beyond LAMP
TechShift: There’s light beyond LAMP
 
Firefox OS, HTML5 to the next level - Python Montreal - 2014-05-12
Firefox OS, HTML5 to the next level - Python Montreal - 2014-05-12Firefox OS, HTML5 to the next level - Python Montreal - 2014-05-12
Firefox OS, HTML5 to the next level - Python Montreal - 2014-05-12
 
Firefox OS, une plateforme à découvrir - IO Saglac - 2014-09-09
Firefox OS, une plateforme à découvrir - IO Saglac - 2014-09-09Firefox OS, une plateforme à découvrir - IO Saglac - 2014-09-09
Firefox OS, une plateforme à découvrir - IO Saglac - 2014-09-09
 
HTML, not just for desktops: Firefox OS - Congreso Universitario Móvil - 201...
HTML, not just for desktops: Firefox OS - Congreso Universitario Móvil - 201...HTML, not just for desktops: Firefox OS - Congreso Universitario Móvil - 201...
HTML, not just for desktops: Firefox OS - Congreso Universitario Móvil - 201...
 
HTML for the Mobile Web, Firefox OS - All Things Open - 2014-10-22
HTML for the Mobile Web, Firefox OS - All Things Open - 2014-10-22HTML for the Mobile Web, Firefox OS - All Things Open - 2014-10-22
HTML for the Mobile Web, Firefox OS - All Things Open - 2014-10-22
 
GraphQL - APIs The New Way
GraphQL - APIs The New WayGraphQL - APIs The New Way
GraphQL - APIs The New Way
 
Connecting Pebble to the World
Connecting Pebble to the WorldConnecting Pebble to the World
Connecting Pebble to the World
 
HTML pour le web mobile, Firefox OS - Devfest Nantes - 2014-11-07
HTML pour le web mobile, Firefox OS - Devfest Nantes - 2014-11-07HTML pour le web mobile, Firefox OS - Devfest Nantes - 2014-11-07
HTML pour le web mobile, Firefox OS - Devfest Nantes - 2014-11-07
 
AWS IoTで家庭内IoTをやってみた【JAWS DAYS 2016】
AWS IoTで家庭内IoTをやってみた【JAWS DAYS 2016】AWS IoTで家庭内IoTをやってみた【JAWS DAYS 2016】
AWS IoTで家庭内IoTをやってみた【JAWS DAYS 2016】
 
GraphQL: APIs the New Way.
GraphQL: APIs the New Way.GraphQL: APIs the New Way.
GraphQL: APIs the New Way.
 
apidays Paris 2022 - France Televisions : How we leverage API Platform for ou...
apidays Paris 2022 - France Televisions : How we leverage API Platform for ou...apidays Paris 2022 - France Televisions : How we leverage API Platform for ou...
apidays Paris 2022 - France Televisions : How we leverage API Platform for ou...
 
Socket.IO
Socket.IOSocket.IO
Socket.IO
 
mobl
moblmobl
mobl
 
Monitoring Your ISP Using InfluxDB Cloud and Raspberry Pi
Monitoring Your ISP Using InfluxDB Cloud and Raspberry PiMonitoring Your ISP Using InfluxDB Cloud and Raspberry Pi
Monitoring Your ISP Using InfluxDB Cloud and Raspberry Pi
 
FrenchKit 2017: Server(less) Swift
FrenchKit 2017: Server(less) SwiftFrenchKit 2017: Server(less) Swift
FrenchKit 2017: Server(less) Swift
 
OpenStack API's and WSGI
OpenStack API's and WSGIOpenStack API's and WSGI
OpenStack API's and WSGI
 
JavaZone 2022 - Building Kotlin DSL.pdf
JavaZone 2022 - Building Kotlin DSL.pdfJavaZone 2022 - Building Kotlin DSL.pdf
JavaZone 2022 - Building Kotlin DSL.pdf
 
The Latest on ORCID API v2
The Latest on ORCID API v2 The Latest on ORCID API v2
The Latest on ORCID API v2
 
Introduction to Coding
Introduction to CodingIntroduction to Coding
Introduction to Coding
 

Último

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Último (20)

Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 

Home Automation with Android Things and the Google Assistant