I try it with
sorry, I have the translator going
Wonderful. So this works when running from the “Execute Command” for the remote in PaperUI. For anyone that is struggling, this is the rest of my setup. I used the on/off for my aircon for this example.
Items
Switch ac_power (AC)
String ac_power_string { channel=‘miio:unsupported:03EE3156:actions#commands’ }
Sitemap
Frame label="Air conditioner" {
Switch item=ac_power icon="heating"
}
Rules
rule "Aircon On using miIO.ir_play"
when
Item ac_power received command
then
if (ac_power.state == ON ) {
ac_power_string.sendCommand('miIO.ir_play {"freq": 38400, "code": "Z6WVADkCAADAAgAAmAYAAB4HAADlCwAAxxAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABEVCAAIBAAIAAwAAAAMAAAADAAACAwACAgMAAAIDAAAAAQAAAAEAAAADAgIAAwICAgEAAAIBAgACAQAAAgECAAABAAIAAQICAgAAA="}')
}
else if (ac_power.state == OFF ) {
ac_power_string.sendCommand('miIO.ir_play {"freq": 38400, "code": "Z6WVADgCAADMAgAAlwYAAAoHAAAmBwAA4wsAAAoMAACqEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABVdiAAIBAAIABAAAAAQAAAABAAACBAACAgQAAAIBAgICAQAAAAEAAAAEAgIAAwICAgEAAAIBAgACAQAAAgECAAABAAIAAQIAAgIAA="}')
}
end
That is it. If anyone needs help to find the codes for their devices I will be happy to share my technique using mirobo on the Openhabian command line.
Any information shared, it is always very welcome
Write a tutorial
I have created a string item linked to the IR remote Execute Command Action in Paper UI but there is no input box for commands.
Can someone help?
As this is an unsupported item you will have to get each command code and then send these codes to your Remote using a rule.
You need to install miio on a Linux system.
sudo pip3 install python-miio
If you don’t have python or pip then you have to install them first. I struggled a lot to get this working so looking back I’m not 100% sure what I did that had no effect. For instance, I installed python 2.7 and 3.5 and both versions of pip. If you don’t have pip just get both.
sudo apt-get install pip3
sudo apt-get install pip
sudo apt-get install python3-pip
sudo apt-get install python-pip
I’m sure you already have your token if not then run this command.
sudo mirobo discover
This command will show you “ChuangmiIr” as supported with the IP Address and the token.
Now there are three commands you will need to get the codes you need to operate the Remote.
miIO.ir_learn ‘{“key”: “1”}’
miIO.ir_read ‘{“key”: “1”}’
miIO.ir_play
First, you need to teach it the command, then read it back so you can record the code then test to see if the code works. I will give you an example. Let’s say you want to record the On/Off switch for your TV.
mirobo --ip [device ip here] --token [your token here] -d raw-command miIO.ir_learn ‘{“key”: “1”}’
Example: mirobo --ip 172.20.1.130 --token ed61gfda545bc675819r0e0y39u43e5s -d raw-command miIO.ir_learn ‘{“key”: “1”}’
You will then point your remote at the IR Remote and press the On switch. I have found on devices like Airconditioners it always best to position the IR Remote between you and the device you want to control. This way I found that I got very few codes that did not work.
You can then use the read command to get the code you just executed.
mirobo --ip 172.20.1.130 --token ed61gfda545bc675819r0e0y39u43e5s -d raw-command miIO.ir_read ‘{“key”: “1”}’
Your output should be somthing like:
Sending cmd miIO.ir_read with params {‘key’: ‘1’}
{‘code’: ‘Z6UnASwCAACSBgAAgREAADS3AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEBAQABAQEDAiEBAQAAAAAAAQEBAAAAAAABAAAAAQAAAAABAQEAAQEBAwIhAQEAAAAAAAEBAQAAAAAAAQAAAAEAAAAAAQEBAAEBAQMCIQEBAAAAAAABAQEAAAAAAAEAAAABAAAAAAEBAQABAQEDAiEBAQAAAAAAAQEBAAAAAAABAAAAAQAAAAABAQEAAQEBAA’, ‘key’: ‘1’}
One trick I learned was to store these codes on your system rather than copy and paste them elsewhere. I created a folder for my room and a subfolder for the device and then piped the read command to that folder. Example. In /home/openhabian/ I created a folder “Livingroom” and a subfolder TV. This is for all my TV commands for the Livingroom TV. So my read command become something like this:
mirobo --ip 172.20.1.130 --token ed61gfda545bc675819r0e0y39u43e5s -d raw-command miIO.ir_read ‘{“key”: “1”}’ > /home/openhabian/LivingRoom/TV/ON
Now you need to copy and paste the code to the play command to see if it works:
mirobo --ip 172.20.1.130 --token ed61gfda545bc675819r0e0y39u43e5s raw-command miIO.ir_play '{“code” : “Z6UnASwCAACSBgAAgREAADS3AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEBAQABAQEDAiEBAQAAAAAAAQEBAAAAAAABAAAAAQAAAAABAQEAAQEBAwIhAQEAAAAAAAEBAQAAAAAAAQAAAAEAAAAAAQEBAAEBAQMCIQEBAAAAAAABAQEAAAAAAAEAAAABAAAAAAEBAQABAQEDAiEBAQAAAAAAAQEBAAAAAAABAAAAAQAAAAABAQEAAQEBAA”}
If this turns the TV On then your command works. You need to do this for all commands.
Now to get back to OpenHAB. I will assume you created a item linked to your IR Remote. It should look something like this:
String IRRemoteCommand { channel=‘miio:unsupported:01SF1563:actions#commands’ }
Now you can use your rules to execute these commands. I will give you a few examples.
rule “Sound Remote LivingRoom SoundRemoteLivingRoomOnSwitch using miIO.ir_play”
when
Item SoundRemoteLivingRoomOnSwitch received command
then
IRRemoteCommand.sendCommand(‘miIO.ir_play {“freq”: 38400, “code”: “Z6VTABACAABeAgAAbwYAAL8IAAChEQAAOyMAAHibAAAseAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABFASEhISEhIQEhAQEBAQEBIQEhASEBIQEBIQEhASEBISFhNXE1cTVxNQE=”}’)
end
In this example “SoundRemoteLivingRoomOnSwitch” is just an item defined as a Switch. The rule above is just an example. You would do better to use a Lambda to return the codes. Let me know if you need help with that.
yes, that seems to happen sometimes. I don’t actually know why the UI does not allow you to enter a value.
One way around is by going to the OH console and one send a command from the console
smarthome:send plug1_cmd 'get_prop["over_heat"]'
(obviously replacing it with your item and your command)
once that is send you will see the - in the UI replaced with the response. From then, you can just send the command via paperIU
Thank you very much - this was very helpful.
Mine required an underscore in raw_command but this may just be the system.
I’m glad I could help. I am amazed that so few people are using them. They are cheap and work great. They have 6 IR led’s inside spaced around the perimeter so placing them in the centre of a room gives you 20 - 30 meters of coverage in all directions.
Hello,
Can you please help!
I have got the token and this is the result
INFO:miio.discovery:Found a supported 'ChuangmiIr' at 192.168.1.100 - token: d005f14fde43dd010356ff27c2263bda
/usr/local/lib/python3.5/dist-packages/miio/discovery.py:101: UserWarning: Pleas e consider using python-yeelight for more complete support.
dev = device_cls(ip=addr)
But when I am going to execute learn command
mirobo --ip 192.168.1.100 --token d005f14fde43dd010356ff27c2263bda -d raw-command miIO.ir_learn '{“key”: “1”}'
The result is
[18:58:08] openhabian@ioniq:~$ mirobo --ip 192.168.1.100 --token d005f14fde43dd010356ff27c2263bda -d raw-command milO.ir_learn '{“key”: “1”}'
INFO:miio.vacuum_cli:Debug mode active
DEBUG:miio.vacuum_cli:Connecting to 192.168.1.100 with token d005f14fde43dd010356ff27c2263bda
Traceback (most recent call last):
File "/usr/local/bin/mirobo", line 11, in <module>
sys.exit(cli())
File "/usr/local/lib/python3.5/dist-packages/miio/click_common.py", line 54, in __call__
return self.main(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 717, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 1137, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 956, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 555, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/click/decorators.py", line 64, in new_func
return ctx.invoke(f, obj, *args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 555, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/miio/vacuum_cli.py", line 622, in raw_command
params = ast.literal_eval(parameters)
File "/usr/lib/python3.5/ast.py", line 46, in literal_eval
node_or_string = parse(node_or_string, mode='eval')
File "/usr/lib/python3.5/ast.py", line 35, in parse
return compile(source, filename, mode, PyCF_ONLY_AST)
File "<unknown>", line 1
{“key”: “1”}
^
SyntaxError: invalid character in identifier
Try editing your command:
mirobo --ip 192.168.1.100 --token d005f14fde43dd010356ff27c2263bda -d raw-command miIO.ir_learn '{“key”: “1”}'
I would manually enter the " around the key and 1. Sometimes when you copy and paste those characters are replaced with another character that looks like double quotes but are not.
Yes the problem was in the quotes,
I wrote the command and press the ON/OFF switch of the remote control and this is the result,I think there is a problem here.
INFO:miio.vacuum_cli:Debug mode active
DEBUG:miio.vacuum_cli:Read stored sequence ids: {'seq': 6, 'manual_seq': 0}
DEBUG:miio.vacuum_cli:Connecting to 192.168.1.100 with token 205ea083b10445a79cac8a5b3eb47fc1
Sending cmd miIO.ir_learn with params {'key': '1'}
DEBUG:miio.protocol:Unable to decrypt, returning raw bytes: b''
DEBUG:miio.device:Got a response: Container:
data = Container:
value = b'' (total 0)
offset2 = 32
length = 0
data = b'' (total 0)
offset1 = 32
header = Container:
value = Container:
length = 32
unknown = 0
device_id = b'\x06z\x96f' (total 4)
ts = 1970-01-01 00:01:30
offset2 = 16
length = 16
data = b'!1\x00 \x00\x00\x00\x00\x06z\x96f\x00\x00\x00Z' (total 16)
offset1 = 0
checksum = b' ^\xa0\x83\xb1\x04E\xa7\x9c\xac\x8a[>\xb4\x7f\xc1' (total 16)
DEBUG:miio.device:Discovered 067a9666 with ts: 1970-01-01 00:01:30, token: b'205ea083b10445a79cac8a5b3eb47fc1'
DEBUG:miio.device:192.168.1.100:54321 >>: {'params': {'key': '1'}, 'id': 7, 'method': 'miIO.ir_learn'}
DEBUG:miio.device:192.168.1.100:54321 (ts: 1970-01-01 00:01:30, id: 7) << {'result': 0, 'id': 7}
0
DEBUG:miio.vacuum_cli:Writing {'seq': 7, 'manual_seq': 0} to /home/openhabian/.cache/python-miio/python-mirobo.seq
I have not had this issue but there are 2 things I can suggest. Are you sure about the token? If you reset the device the token will change. Make sure to run:
sudo mirobo discover
Also check the version you are running. I have version 0.4.2. You can do this by running:
sudo mirobo --version
Some people have also reported that they had to change the “raw-command” to “raw_command”. Try it with the underscore also.
- I checked the token and it is wright.
- my mirobo version is 0.4.4, Does this have an effect?
- I tried this “raw_command” but it is wrong
I would suggest having a look on the creators GitHub page for similar issues. If you find no answers there then log a issue. He will be in a better position to help you as I have exhausted my knowledge on this subject.
Ok
Thank you!
I installed 0.4.4 and also get the same errors as you. However, my commands still work. This leads me to believe that the script still works but reports that it has a problem. This may be because the IR Remote is still an “Unsupported” item. The key to learning commands for me was to press the button for a long time (few seconds) until the blue light stops flickering. Then play the code back with
raw-command miIO.ir_play
and see if it triggers the device. You could also go back to version 0.4.2. This one did not have these issues.
sudo pip install python-miio==0.4.2
Is there a way to store the learned key as a variable for use? I’ve tried executecommand.state and it’s null
One thing that I did was to pipe the command to a file. Like this:
mirobo --ip 172.20.1.130 --token ed61gfda545bc65645666r0e0y39u43e5s -d raw-command miIO.ir_read ‘{“key”: “1”}’ > /home/openhabian/LivingRoom/TV/ON
If you mean that you want to execute the command in a rule. This is what I did. I created a lambda function. This built the command I wanted to execute. See below:
val Functions$Function2<String, String, String> IRCode = [DeviceName, Button |
var irCode = ""
if (DeviceName == "LivingRoomSound") {
switch(Button) {
case "AUDIO1":
irCode = "Z6VLABcCAABAAAAABFASEBISEhIQEhASEBAQEBISEBIQEBISEBASEBISEBAQFhNXE1AQ=="
case "AUDIO2":
irCode = "Z6VLABcCAABAAAAABFASEBISEhIQEhASEBAQEBISEBIQEBISEBASEBISEBAQFhNXE1AQ=="
case "AV1":
irCode = ""Z6VLABcCAABAAAAABFASEBISEhIQEhASEBAQEBISEBIQEBISEBASEBISEBAQFhNXE1AQ=="
}
}
if (irCode != "") {
return 'miIO.ir_play {"freq": 38400, "code": "' + irCode + '"}'
} else {
return '{}'
}
]
I would then call it like this:
ac_power_string.sendCommand(IRCode.apply(“LivingRoomSound”,“AUDIO1”))
Within my items I had “ac_power_string” setup like this:
String ac_power_string { channel=‘miio:unsupported:03EF3156:actions#commands’ }
Hope it makes it clear. Ask if I can help some more.
Cheers
Jo