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

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 

Último (20)

Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 

Home Automation with Android Things and the Google Assistant