Operate home appliances with Python and IRKit

After studying Python, hit the IRKit API to operate home appliances. See below for IRKit itself and API specifications. Simply put, a device that remembers the infrared rays of the remote control and allows you to hit them over the net.

http://getirkit.com/

Overview

ca3258ff-0d29-d8f6-1ddf-568b3ca4aa02.png

code

#!/usr/bin/env python
# coding: utf-8

import requests
import json


class IrkitInternetAPI:
    endpoint = "https://api.getirkit.com/1"
    clientkey = ""
    deviceid = ""

    def __init__(self, clientkey, deviceid):
        self.clientkey = clientkey
        self.deviceid = deviceid

    def get_messages(self):
        params = {
            'clientkey': self.clientkey,
        }

        headers = {'X-Requested-With': "irkit-python"}
        url = self.endpoint + "/messages"

        r = requests.get(url, headers=headers, params=params)

        if r.status_code == 200:
            return r.json()

    def post_messages(self, data):
        message = {
            "format": "raw",
            "freq": 38,
            "data": data
        }
        message = json.dumps(message)

        params = {
            'clientkey': self.clientkey,
            'deviceid': self.deviceid,
            'message': message
        }

        url = self.endpoint + "/messages"
        headers = {'X-Requested-With': "irkit-python"}
        r = requests.post(url, headers=headers, params=params)


def main():
    clientkey = "your_clientkey"
    deviceid = "your_deviceid"

    irkit = IrkitInternetAPI(clientkey, deviceid)

	#Get the latest infrared signal (it will disappear soon, so just before that, point the remote control at IRKit)
    messages = irkit.get_messages()
    data = messages['message']['data']

    #Call it again as it is
    irkit.post_messages(data)


if __name__ == '__main__':
    main()

For the time being, the lights turned on and off. It is interesting to be able to control home appliances from the program!

If you hit it with curl, you don't have to write this much code, but this time it's practice.

reference

Recommended Posts

Operate home appliances with Python and IRKit
Operate ECHONET Lite appliances with Python
Operate Blender with Python
Operate Excel with Python (1)
Operate Excel with Python (2)
Operate Excel with Python openpyxl
Encryption and decryption with Python
Operate TwitterBot with Lambda, Python
Python and hardware-Using RS232C with Python-
[Note] Operate MongoDB with Python
[Python] [SQLite3] Operate SQLite with Python (Basic)
python with pyenv and venv
Get home directory with python
Works with Python and R
Shining life with Python and OpenCV
Operate a receipt printer with python
Robot running with Arduino and python
Neural network with OpenCV 3 and Python 3
AM modulation and demodulation with python
[Python] font family and font with matplotlib
Scraping with Node, Ruby and Python
Scraping with Python, Selenium and Chromedriver
Try to operate Facebook with Python
Scraping with Python and Beautiful Soup
JSON encoding and decoding with python
Hadoop introduction and MapReduce with Python
[GUI with Python] PyQt5-Drag and drop-
Reading and writing NetCDF with Python
I played with PyQt5 and Python3
Reading and writing CSV with Python
Multiple integrals with Python and Sympy
Coexistence of Python2 and 3 with CircleCI (1.0)
Easy modeling with Blender and Python
Sugoroku game and addition game with python
FM modulation and demodulation with Python
Operate Jupyter with REST API to extract and save Python code
Link SORACOM, home appliances and LINE Bot [Python / Flask / Raspberry Pi]
Operate Firefox with Selenium from python and save the screen capture
Communicate between Elixir and Python with gRPC
Data pipeline construction with Python and Luigi
Calculate and display standard weight with python
Monitor Mojo outages with Python and Skype
FM modulation and demodulation with Python Part 3
[Automation] Manipulate mouse and keyboard with Python
Passwordless authentication with RDS and IAM (Python)
Python installation and package management with pip
Using Python and MeCab with Azure Databricks
Operate smartlife power supply with python (de-IFTTT)
POST variously with Python and receive with Flask
Capturing images with Pupil, python and OpenCV
A memo with Python2.7 and Python3 on CentOS
Use PIL and Pillow with Cygwin Python
Create and decrypt Caesar cipher with python
CentOS 6.4 with Python 2.7.3 with Apache with mod_wsgi and Django
Reading and writing JSON files with Python
Dealing with "years and months" in Python
[GCP] Operate Google Cloud Storage with Python
I installed and used Numba with Python3.5
Tweet analysis with Python, Mecab and CaboCha
Linking python and JavaScript with jupyter notebook
Traffic monitoring with Kibana, ElasticSearch and Python