{"id":2195,"date":"2018-05-19T18:40:15","date_gmt":"2018-05-19T09:40:15","guid":{"rendered":"https:\/\/uda2.com\/blog\/?p=2195"},"modified":"2018-05-20T00:31:07","modified_gmt":"2018-05-19T15:31:07","slug":"alexa_raspberrypi","status":"publish","type":"post","link":"https:\/\/uda2.com\/blog\/alexa_raspberrypi\/","title":{"rendered":"Alexa\u3068RaspberryPi\u3067\u96fb\u6c17\u4ed8\u3051\u3066"},"content":{"rendered":"<p>\u4eca\u307e\u3067siri\u3092\u4f7f\u3063\u305f\u97f3\u58f0\u64cd\u4f5c\u3092\u3057\u3066\u3044\u305f\u306e\u3067HomePod\u3092\u5f85\u3063\u3066\u3044\u305f\u30022\u6708\u306b\u306a\u3063\u3066\u3088\u3046\u3084\u304f\u6d77\u5916\u3067\u767a\u58f2\u3055\u308c\u305f\u304c349\u30c9\u30eb\uff08\u57f7\u7b46\u6642\u306e\u70ba\u66ff\u3067\u7d0438,700\u5186\uff09\u3068\u304b\u306a\u308a\u9ad8\u4fa1\u306a\u306e\u3067\u8ae6\u3081\u3066Echo Dot\uff08\u30bb\u30fc\u30eb\u30674,980\u5186\uff09\u3092\u8cb7\u3063\u305f\u3002<br \/>\nAlexa\u3067\u5bb6\u96fb\u64cd\u4f5c\u3059\u308b\u65b9\u6cd5\u306f\u5927\u304d\u304f2\u3064\u3067\u81ea\u524d\u306e\u30b9\u30ad\u30eb\uff08\u30a2\u30d7\u30ea\uff09\u3092\u4f5c\u308b\u304bIFTTT\u3092\u4f7f\u3046\u304b\u306b\u306a\u308a\u307e\u3059\u304c\u4eca\u56de\u306fIFTTT\u3092\u4f7f\u3046\u4e8b\u306b\u3057\u307e\u3057\u305f\u3002<br \/>\nIFTTT\u306f\u69d8\u3005\u306a\u30b5\u30fc\u30d3\u30b9\u3092\u9023\u643a\u3055\u305b\u308b\u30b5\u30fc\u30d3\u30b9\u3067\u30b9\u30ad\u30eb\u3092\u4f5c\u308b\u3088\u308a\u306f\u7c21\u5358\u3060\u304c\u300c\u96fb\u6c17\u4ed8\u3051\u3066\u3092\u30c8\u30ea\u30ac\u30fc\u300d\u3068\u6700\u5f8c\u306b\u30c8\u30ea\u30ac\u30fc\u3068\u8a00\u3046\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<br \/>\n<!--more--><br \/>\n<strong>\u25a0siri\u306e\u6d41\u308c<\/strong><br \/>\nsiri \u2192 homebridge \u2192 irMagician<br \/>\n<strong>\u25a0IFTTT\u7d4c\u7531\uff08Alexa\uff09\u306e\u6d41\u308c<\/strong><br \/>\nAlexa \u2192 IFTTT \u2192 Beebotte \u2192 \u5e38\u99d0\u3055\u305b\u305f\u30b9\u30af\u30ea\u30d7\u30c8 \u2192 irMagician<\/p>\n<p>homebridge\u306e\u6642\u306f\u64cd\u4f5c\u3055\u308c\u308b\u5bb6\u96fb\u306e\u632f\u308a\u3092\u3059\u308b\u306e\u3067siri\u304b\u3089\u306e\u60c5\u5831\u304c\u76f4\u63a5\u53d6\u5f97\u51fa\u6765\u3066\u30b7\u30f3\u30d7\u30eb\u306a\u69cb\u9020\u3067\u3059\u304cAlexa\u306b\u306f\u305d\u3046\u3044\u3046\u306e\u306f\u307e\u3060\u958b\u767a\u3055\u308c\u3066\u306a\u3044\u306e\u3067\u8907\u96d1\u306b\u306a\u308a\u307e\u3059\u3002<br \/>\n\u307e\u305aIFTTT\u306b\u30a4\u30d9\u30f3\u30c8\u306e\u767a\u706b\uff08\u30c8\u30ea\u30ac\u30fc\uff09\u306e\u6307\u793a\u3092\u3057\u3066\u6307\u793a\u5185\u5bb9\u3092Beebotte\u306b\u9001\u308a\u307e\u3059\u3002<br \/>\nBeebotte\u306fMQTT\u3092\u4f7f\u3063\u305fIoT\u5411\u3051\u306e\u8efd\u91cf\u30e1\u30c3\u30bb\u30fc\u30b8\u30d6\u30ed\u30fc\u30ab\u30fc\u30b5\u30fc\u30d3\u30b9\u3067\uff11\u65e550000\u30e1\u30c3\u30bb\u30fc\u30b8\u307e\u3067\u306a\u3089\u7121\u6599\u3067\u4f7f\u3048\u307e\u3059\u3002<br \/>\nIFTTT\u306e\u6307\u793a\u304c\u6765\u308b\u3068\u30a6\u30c1\u306eraspberryPi\u306b\u901a\u77e5\u304c\u5c4a\u3051\u3066\u3082\u3089\u3044\u307e\u3059\u3002\u4eca\u56de\u306fraspberryPi\u304c\u975e\u516c\u958b\u306a\u306e\u3067MQTT\u3092\u4f7f\u3044\u307e\u3057\u305f\u304c\u516c\u958b\u3057\u3066\u305f\u3089HTTP\u7d4c\u7531\u3067\u3082\u3044\u3044\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002<br \/>\n\u901a\u77e5\u306e\u53d7\u3051\u53e3\u306fpaho-mqtt\u3068\u3044\u3046\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u3063\u3066Python\u3067\u66f8\u304d\u3001\u305d\u308c\u3092\u5e38\u99d0\u3055\u305b\u307e\u3059\u3002<br \/>\n\u6700\u7d42\u7684\u306b\u306f\u524d\u56desiri\u7528\u306b\u4f5c\u3063\u305f\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u5b9f\u884c\u3055\u305b\u3066\u5bb6\u96fb\u3092\u64cd\u4f5c\u3057\u307e\u3059\u3002<\/p>\n<p>\u305d\u308c\u3067\u306f\u30ec\u30b7\u30d4\u3067\u3059\u3002<br \/>\n\u307e\u305a\u306f<a href=\"https:\/\/beebotte.com\/\" target=\"_blank\">Beebotte<\/a>\u306b\u5165\u4f1a\uff08Sighn up\uff09\u3057\u307e\u3059\u3002<br \/>\n\u300cChannels\u300d\u306e\u53f3\u4e0a\u306e\u300cCreate new\u300d\u3092\u30af\u30ea\u30c3\u30af\u3057\u307e\u3059\u3002<br \/>\nChannel Name\u306b\u9069\u5f53\u306a\u540d\u524d\u3092\u5165\u308c<br \/>\nChannel Discription\u306b\u9069\u5f53\u306a\u8aac\u660e\u3092\u5165\u308c<br \/>\nResource Name\u306b\u9069\u5f53\u306a\u540d\u524d\u3092\u5165\u308c<br \/>\nResource Discription\u306b\u9069\u5f53\u306a\u8aac\u660e\u3092\u5165\u308c\u300cCreate Channel\u300d\u3092\u62bc\u3057\u307e\u3059\u3002<br \/>\nChannel Name\u3068Resource Name\u306f\u53d7\u3051\u53d6\u308b\u969b\u306b\u4f7f\u3044\u307e\u3059\u3002<br \/>\n\u51fa\u6765\u305fChannel\u306e\u540d\u524d\u3092\u30af\u30ea\u30c3\u30af\u3059\u308b\u3068\u300cChannel Token\u300d\u3068\u3044\u3046\u306e\u304c\u3042\u308a\u307e\u3059\u3002\u300cChannel Name\u300d\u300cResource Name\u300d\u3068\u4f75\u305b\u3066\u5f8c\u3067\u4f7f\u3046\u306e\u3067\u30e1\u30e2\u3057\u3066\u304a\u3044\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>\u6b21\u306b<a href=\"https:\/\/ifttt.com\/\" target=\"_blank\">IFTTT<\/a>\u306b\u5165\u4f1a\uff08Sighn up\uff09\u3057\u307e\u3059\u3002<br \/>\n\u30ed\u30b0\u30a4\u30f3\u3057\u305f\u3089\u53f3\u4e0a\u306e\u30e6\u30fc\u30b6\u30fc\u540d\u3092\u30af\u30ea\u30c3\u30af\u3057\u3066\u300cNewApplet\u300d\u3092\u9078\u3073\u307e\u3059\u3002<br \/>\n\u300cthis\u300d\uff08\u30c8\u30ea\u30ac\u30fc\uff09\u306b\u300cAmazonAlexa\u300d\u306e\u300cSay a pecific phrase\u300d\u3092\u8a2d\u5b9a\uff08\u521d\u56de\u306fAmazon\u306b\u30b5\u30a4\u30f3\u30a4\u30f3\u3055\u305b\u3089\u308c\u308b\uff09<br \/>\n\u300cWhat phrase?\u300d\u306b\u53f0\u8a5e\u3092\u5165\u308c\u308b\u3002\u4eca\u56de\u306f\u300c\u96fb\u6c17\u3092\u3064\u3051\u3066\u300d\u3068\u5165\u529b<br \/>\n\u300cthat\u300d\uff08\u30a2\u30af\u30b7\u30e7\u30f3\uff09\u306b\u300cWebhook\u300d\u306e\u300cMake a web request\u300d\u3092\u8a2d\u5b9a<br \/>\nURL\u3092<strong>https:\/\/api.beebotte.com\/v1\/data\/write\/\uff1cChannel Name\uff1e\/\uff1cResource Name\uff1e?token=\uff1cChannel Token\uff1e<\/strong><br \/>\nMethod\u3092<strong>POST<\/strong><br \/>\nContentType\u3092<strong>application\/json<\/strong><br \/>\nBody\u3092<strong>{&#8220;data&#8221;:[{&#8220;action&#8221;:&#8221;ON&#8221;,&#8221;device&#8221;:&#8221;Light&#8221;}]}<\/strong><br \/>\n\u3068\u3057\u3066\u304a\u304f<\/p>\n<p>\u305d\u3057\u3066RaspberryPI\u3002\u30a6\u30c1\u306fPython3\u306epip3\u304c\u5165\u3063\u3066\u7121\u304b\u3063\u305f\u306e\u3067\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u3002<br \/>\n<strong># sudo apt install python3-pip<\/strong><br \/>\nMQTT\u3092\u53d7\u3051\u308b\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<br \/>\n<strong># pip3 install paho-mqtt<\/strong><br \/>\n\u524d\u56de\u306esiri\u7528\uff08homebridge\uff09\u306b\u4f5c\u3063\u305f\u30d5\u30a9\u30eb\u30c0\u306b\u8a2d\u7f6e\u3057\u3066\u3044\u304f\u4e8b\u306b\u3059\u308b\u3002<br \/>\n<strong>$ cd .homebridge<\/strong><br \/>\nBeebotte\u306e\u8a3c\u660e\u66f8\u3092\u843d\u3068\u3057\u3066\u304a\u304f<br \/>\n<strong>$ wget https:\/\/beebotte.com\/certs\/mqtt.beebotte.com.pem<\/strong><br \/>\n<strong>$ vi mqtt_beebotte.py<\/strong><\/p>\n<pre><code># -*- coding: utf-8 -*-\r\n\r\nimport paho.mqtt.client as mqtt\r\nimport json\r\nimport subprocess\r\nimport os\r\n\r\nHOST = 'mqtt.beebotte.com'\r\nPORT = 8883\r\nCA_CERTS = '\/home\/hogehoge\/.homebridge\/mqtt.beebotte.com.pem'\r\n_TOKEN = '\uff1cChannel Token\uff1e'\r\nTOPIC = '\uff1cChannel Name\uff1e\/\uff1cResource Name\uff1e'\r\n\r\ndef on_connect(client, userdata, flags, respons_code):\r\n    print('status {0}'.format(respons_code))\r\n\r\ndef on_message(client, userdata, msg):\r\n    print(msg.topic + ' ' + str(msg.payload))\r\n    data = json.loads(msg.payload.decode(\"utf-8\"))[\"data\"][0]\r\n    print(msg.payload.decode(\"utf-8\"))\r\n    if data[\"device\"] == 'Light':\r\n        if data[\"action\"] == 'ON':\r\n            subprocess.call('python \/home\/hogehoge\/.homebridge\/data\/irm.py -p -f \/home\/hogehoge\/.homebridge\/data\/DLC303V-ON.json', shell=True)\r\n        elif data[\"action\"] == 'OFF':\r\n            subprocess.call('python \/home\/hogehoge\/.homebridge\/data\/irm.py -p -f \/home\/hogehoge\/.homebridge\/data\/DLC303V-OFF.json', shell=True)\r\n\r\nif __name__ == '__main__':\r\n    client = mqtt.Client()\r\n    client.on_connect = on_connect\r\n    client.on_message = on_message\r\n    client.username_pw_set('token:%s' %_TOKEN)\r\n    client.tls_set(CA_CERTS)\r\n    client.connect(HOST, PORT)\r\n    client.subscribe(TOPIC)\r\n    client.loop_forever()<\/code><\/pre>\n<p>\u203b\u30d1\u30b9\u306f\u30b5\u30fc\u30d3\u30b9\u5316\u3092\u898b\u8d8a\u3057\u3066\u30d5\u30eb\u30d1\u30b9\u306b\u3057\u3066\u307e\u3059\u306e\u3067\u8a2d\u7f6e\u5834\u6240\u306b\u5408\u308f\u305b\u3066\u5909\u66f4\u3057\u3066\u4e0b\u3055\u3044\u3002<\/p>\n<p>DLC303V-ON.json\u3084DLC303V-ON.json\u306e\u30d5\u30a1\u30a4\u30eb\u306f\u4ee5\u524d<a href=\"https:\/\/uda2.com\/blog\/homekit1\/\" target=\"_blank\">Raspberry Pi\u3067\u5148\u53d6\u308aHomekit<\/a>\u3067\u4f5c\u3063\u305f\u3082\u306e\u3092\u4f7f\u3063\u3066\u307e\u3059\u3002\u3082\u3061\u308d\u3093irm.py\u3082\u5f15\u304d\u7d9a\u304d<a href=\"http:\/\/netbuffalo.doorblog.jp\/archives\/4872290.html\" target=\"_blank\">netbuffalo<\/a>\u3055\u3093\u306e\u3082\u306e\u3092\u4f7f\u308f\u3057\u3066\u3082\u3089\u3063\u3066\u307e\u3059\u3002<br \/>\npython3\u306bpaho-mqtt\u3092\u5165\u308c\u3066python\u306bpyserial\u3092\u5165\u308c\u3066\u308b\u90fd\u5408\u4e0apython3\uff083.5\uff09\u306e\u30b9\u30af\u30ea\u30d7\u30c8\u304b\u3089python\uff082.7\uff09\u306e\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u547c\u3076\u3068\u3044\u3046\u4e0d\u601d\u8b70\u306a\u5f62\u306b\u306a\u3063\u3066\u3057\u307e\u3044\u307e\u3057\u305f\u304cpython\u306b\u8a73\u3057\u304f\u306a\u3044\u306e\u3067\u30b9\u30eb\u30fc\u3057\u307e\u3059\u3002<br \/>\n\u5b9f\u884c\u3057\u3066\u3001\u5b9f\u969b\u306balexa\u306b\u300c\u30a2\u30ec\u30af\u30b5\u3001\u96fb\u6c17\u4ed8\u3051\u3066\u3092\u30c8\u30ea\u30ac\u30fc\u300d\u3068\u8a00\u3063\u3066\u307f\u308b\u3002<br \/>\n<strong>$ python3 mqtt_beebotte.py<\/strong><br \/>\n\uff08\u6b62\u3081\u65b9\u5206\u304b\u3089\u306a\u3044\u306e\u3067\u30bf\u30fc\u30df\u30ca\u30eb\u3092\u7d42\u4e86\u3057\u307e\u3057\u305f\u3002\uff09<br \/>\n\u6b63\u3057\u304f\u52d5\u4f5c\u3057\u305f\u3089\u5e38\u99d0\u3055\u305b\u307e\u3059\u3002<br \/>\n<strong># vi \/lib\/systemd\/system\/alexa.service<\/strong><\/p>\n<pre><code>[Unit]\r\nDescription=Alexa Service\r\nAfter=multi-user.target\r\n\r\n[Service]\r\nType=idle\r\nExecStart=\/usr\/bin\/python3 \/home\/hogehoge\/.homebridge\/mqtt_beebotte.py\r\n\r\n[Install]\r\nWantedBy=multi-user.target<\/code><\/pre>\n<p><strong># chmod 644 \/lib\/systemd\/system\/alexa.service<\/strong><br \/>\n<strong># systemctl daemon-reload<\/strong><br \/>\n<strong># systemctl enable alexa.service<\/strong><br \/>\n\u5e38\u99d0\u3055\u308c\u3066\u308b\u304b\u518d\u8d77\u52d5\u3057\u3066\u78ba\u8a8d\u3059\u308b\u3002<br \/>\n<strong># reboot<\/strong><br \/>\n<strong># systemctl status alexa.service<\/strong><\/p>\n<p>\u3053\u308c\u3067iphone\u304b\u3089\u3082alexa\u304b\u3089\u3082\u64cd\u4f5c\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u3063\u305f\u304c\u300c\uff5e\u3092\u30c8\u30ea\u30ac\u30fc\u300d\u304c\u9762\u5012\u3067\u3059\u3002<br \/>\nalexa\u306e\u5b9a\u5f62\u30a2\u30af\u30b7\u30e7\u30f3\uff08siri\u3060\u3068\u30b7\u30fc\u30f3\uff09\u306bifttt\u3082\u767b\u9332\u51fa\u6765\u308b\u3088\u3046\u306b\u306a\u308b\u3053\u3068\u3092\u7948\u308a\u307e\u3059\u3002<\/p>\n<p><strong>\u53c2\u8003\u30b5\u30a4\u30c8<\/strong><br \/>\n<a href=\"https:\/\/qiita.com\/machu\/items\/122c8403b35748bd5f4c\" target=\"_blank\">Amazon Echo\u3067\u300c\u25cb\u25cb\u3092\u3064\u3051\u3066\u300d\u3068\u8a00\u3063\u3066\u5bb6\u96fb\u3092\u64cd\u4f5c\u3059\u308b<\/a><br \/>\n<a href=\"http:\/\/denpa-shinbun.com\/entry\/amazonecho-raspberrypi\" target=\"_blank\">Amazon Echo\u3068Raspberry Pi\u3067\u90e8\u5c4b\u306e\u7167\u660e\u3092\u5236\u5fa1\u3059\u308b #\u304a\u3046\u3061\u30cf\u30c3\u30af &#8211; \u3061\u304e\u3063\u3066\u306f\u6295\u3052\u308b\u30d6\u30ed\u30b0<\/a><br \/>\n<a href=\"https:\/\/qiita.com\/Guwashi\/items\/e1ea9c61af4715198edc\" target=\"_blank\">IFTTT, Beebotte, Mosquitto, SSL\/TLS \u3092\u4f7f\u3063\u3066, \u306a\u308b\u3079\u304f\u5b89\u5168\u306b Google Home \u304b\u3089 Raspberry Pi \u3084 ESP8266 \u3092\u64cd\u4f5c\u3059\u308b &#8211; Qiita<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4eca\u307e\u3067siri\u3092\u4f7f\u3063\u305f\u97f3\u58f0\u64cd\u4f5c\u3092\u3057\u3066\u3044\u305f\u306e\u3067HomePod\u3092\u5f85\u3063\u3066\u3044\u305f\u30022\u6708\u306b\u306a\u3063\u3066\u3088\u3046\u3084\u304f\u6d77\u5916\u3067\u767a\u58f2\u3055\u308c\u305f\u304c349\u30c9\u30eb\uff08\u57f7\u7b46\u6642\u306e\u70ba\u66ff\u3067\u7d0438,700\u5186\uff09\u3068\u304b\u306a\u308a\u9ad8\u4fa1\u306a\u306e\u3067\u8ae6\u3081\u3066Echo Dot\uff08\u30bb\u30fc\u30eb\u30674,980\u5186\uff09\u3092<\/p>\n","protected":false},"author":2,"featured_media":2204,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[205],"tags":[341,343,342,327],"class_list":["post-2195","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-creatorsdiary","tag-alexa","tag-beebotte","tag-ifttt","tag-raspberry-pi"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/uda2.com\/blog\/wp-json\/wp\/v2\/posts\/2195","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/uda2.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/uda2.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/uda2.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/uda2.com\/blog\/wp-json\/wp\/v2\/comments?post=2195"}],"version-history":[{"count":9,"href":"https:\/\/uda2.com\/blog\/wp-json\/wp\/v2\/posts\/2195\/revisions"}],"predecessor-version":[{"id":2205,"href":"https:\/\/uda2.com\/blog\/wp-json\/wp\/v2\/posts\/2195\/revisions\/2205"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/uda2.com\/blog\/wp-json\/wp\/v2\/media\/2204"}],"wp:attachment":[{"href":"https:\/\/uda2.com\/blog\/wp-json\/wp\/v2\/media?parent=2195"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/uda2.com\/blog\/wp-json\/wp\/v2\/categories?post=2195"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/uda2.com\/blog\/wp-json\/wp\/v2\/tags?post=2195"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}