Operate ECHONET Lite appliances with Python

Introduction

I will post the sample code of home appliance operation by ECHONET Lite with python.

What i want to do

  1. ON / OFF control of home appliances
  2. Acquisition of the operating status of home appliances

The Ruby version can be found in Controlling ECHONET Lite Home Appliances with Ruby, so please have a look there.

environment

● Air purifier (compatible with ECHONET Lite)  ⇒ Sharp KI-EX100 ● Windows 7 ● Python 2.7.11

Turn on the operating state

ip = Please use the IP of your device for the "192.168. ○. ○" part.

ON_send.py


# coding: utf-8
import socket

ip = "192.168.2.166"
ECHONETport = 3610

message = "1081000005FF010135016101800130"
msg = message.decode("hex")

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.sendto(msg, (ip, ECHONETport))

Turn off the operating state

OFF_send.py


# coding: utf-8
import socket

ip = "192.168.2.166"
ECHONETport = 3610

message = "1081000005FF010135016101800131"
msg = message.decode("hex")

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.sendto(msg, (ip, ECHONETport))

What is different in the above program Only in the message variable on the 7th line

When ON message = "1081000005FF010135016101800130"

When OFF message = "1081000005FF010135016101800131"

Check the operating status

With a program that sends a request for the operating status of home appliances The explanation is divided into programs that receive the operating status from home appliances.

Send program

get_send.py


# coding: utf-8
import socket

ip = "192.168.2.166"
ECHONETport = 3610

message = "1081000005FF0101350162018000"
msg = message.decode("hex")

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.sendto(msg, (ip, ECHONETport))

Receiving program

receive.py


# coding: utf-8
import socket

port = 3610
bufsize = 4096

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind(("0.0.0.0", port))
data = sock.recvfrom(bufsize)
print data[0].encode('hex')
print data
sock.close()

If you can receive it well, the following message should be displayed The correct information is on the first line. The second line is not encoded in hexadecimal and will not be displayed correctly. I just wanted to tell you something useful because recvform tells you the IP of the source. This time I put the 11th line of the sample code for testing, but please delete it because it is unnecessary code.

図1.jpg

By the way, the 9th line of the sample code

data[0].endode("hex")

Seems to work only with python2 series. So I haven't tried 3 series, so please find and execute the encoding method to make it a hexadecimal number by yourself.

If you don't understand what you are saying, such as 3 or 2, execute the following at the command prompt or terminal.

$ python --version

The display is In the case of python 2. ○. ○, it is 2 system In the case of python 3. ○. ○, it is 3 series

Recommended Posts

Operate ECHONET Lite appliances with Python
Operate home appliances with Python and IRKit
Operate Kinesis with Python
Operate Blender with Python
Operate Excel with Python (1)
Operate Excel with Python (2)
* Python * Controls ECHONET Lite compatible home appliances (emulators)
Operate Excel with Python openpyxl
Operate TwitterBot with Lambda, Python
[Note] Operate MongoDB with Python
[Python] [SQLite3] Operate SQLite with Python (Basic)
Operate a receipt printer with python
Try to operate Facebook with Python
[GCP] Operate Google Cloud Storage with Python
[Pyto] Operate iPhone Taptic Engine with Python
[Python] Automatically operate the browser with Selenium
FizzBuzz with Python3
Scraping with Python
Scraping with Python
Python with Go
Twilio with Python
Integrate with Python
Play with 2016-Python
AES256 with python
Tested with Python
python starts with ()
with syntax (Python)
Bingo with python
Zundokokiyoshi with python
Excel with Python
Microcomputer with Python
Cast with python
Serial communication with Python
Zip, unzip with python
Django 1.11 started with Python3.6
Python with eclipse + PyDev.
Socket communication with Python
Data analysis with python 2
Scraping with Python (preparation)
Try scraping with Python.
Learning Python with ChemTHEATER 03
Sequential search with Python
"Object-oriented" learning with python
Operate Redmine using Python Redmine
Handling yaml with python
Solve AtCoder 167 with python
Serial communication with python
[Python] Use JSON with Python
Learning Python with ChemTHEATER 05-1
Learn Python with ChemTHEATER
Run prepDE.py with python3
1.1 Getting Started with Python
Collecting tweets with Python
Binarization with OpenCV / Python
3. 3. AI programming with Python
Kernel Method with Python
Scraping with Python + PhantomJS
Drive WebDriver with python
Try to operate DB with Python and visualize with d3
[Python] Redirect with CGIHTTPServer
Voice analysis with python