In a domoticz telegram chat we developed an approach to use the xiaomi's chuangmi ir universal remote. Since didnt find any approach in domoticz I made this little script
Steps to make it work :
1 /
Install python-miio from these tutorial.
https://python-miio.readthedocs.io/en/l ... stallation
2/
With the python miio installed check it works with these command
Code: Select all
mirobo discover
Create the scripts
Code: Select all
#!/usr/bin/python3
import sys
import ipaddress
from typing import Any
from miio import ChuangmiIr,DeviceException
import time
import json
import os
import os.path
fichero ='./codes.txt'
ip= '192.168.1.128'
token = 'b14fd53b79ab7d17991e0093264b21aa'
try:
os.stat("codes.txt")
print ('Existe el fichero codes.txt')
except:
print ('No existe codes txt vamos a crearlo')
file = open("codes.txt", "w")
num_lines = sum(1 for line in open('codes.txt'))
print ('Stored Ir Keys ->'+ str(num_lines) )
id = num_lines + 1
ir = ChuangmiIr(ip,token)
ir.learn(key=1)
time.sleep(10)
print (ir.read(key=1).get("code"))
with open('codes.txt', 'a') as file:
try:
file.write(ir.read(key=1).get("code")+ '\n')
except:
print('cant save the Ir code readin error')
To send the ir codes we use the next script irsend.py. You have to specify a number which is the line number in codes.txt, for example if you want to use the tv off wich is the third line.
Code: Select all
python3 irsend.py 3
Code: Select all
#!/usr/bin/python3
import sys
import ipaddress
from typing import Any
from miio import ChuangmiIr,DeviceException
import time
############################################
##
## Config
##############################################
ip = 'device ip'
token = 'token'
####################NO MODIFICAR NADA MAS A PARTIR DE AQUI######
f=open('codes.txt')
codeline=f.readlines()
id = codeline[int(sys.argv[1])-1]
print('vamos a enviar el codigo numero'+ id)
try:
ir = ChuangmiIr(ip,token)
except:
print ('esto ha petado sin decir nada flipa!')
print('conexion con el ir Ok procedemos a enviar el codigo ->' )
ir.play(id,frequency='')
print ('todo ha ido bien creo!')
now you can link it to a dummy device to send your desired commands
Now the wifis plugs
the same check the devices with
Code: Select all
mirobo discover
and then to turn on the plug :
Code: Select all
miplug --ip [device ip] --token [device token] on
Code: Select all
miplug --ip [device ip] --token [device token] off