Closed tota-5 closed 4 years ago
Wow this is awesome! Just caught up on the thread. Will give the latest code a test when I get home.
@elafargue You need to ensure the local capabilities of the device:
- Remove the device from the official app
- Reset the device
- Add the device to your local network
- Do not set up a cloud
Please let me know if you have any problems after doing this.
Just to add further, for anyone wanting to test the code; if you reset your device back to ap mode and then use Broadlink Manager to add it to your network, I think it should work ok.
Command sending is not working. This update should do the trick. Do you guys confirm that the code is being sent after learning?
For me both both test 8 and the previous (debug.py) seem to send the code after learning. I test with a led strip remote on and off function. This is the file from test 8: debug.txt
@felipediel Tested now, it learn and send code (power toggle on Samsung TV). debug.txt
Is there a way to test it in home assistant?
Excellent. This issue is solved. The solution is tested and waiting to be merged.
@SpyrosKyriazos The debug is working because I changed the file for new tests. Sorry about that. @goose2600 I don't think it's necessary because we haven't modified the interface. But if you want to do it anyway, feel free to copy the modified file in the PR and paste it into the local python-broadlink folder.
I did a test with home-assistant. (I run it with docker in unraid) I placed the init.py file from the pull request in " /usr/local/lib/python3.7/site-packages/broadlink" inside the docker (Here is the file in case I got it wrong). After restarting home-assistant I got the following in the logs:
2020-03-06 01:28:03 ERROR (MainThread) [homeassistant.components.switch] Error while setting up broadlink platform for switch
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 179, in _async_setup_platform
await asyncio.wait_for(asyncio.shield(task), SLOW_SETUP_MAX_WAIT)
File "/usr/local/lib/python3.7/asyncio/tasks.py", line 442, in wait_for
return fut.result()
File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/usr/src/homeassistant/homeassistant/components/broadlink/switch.py", line 148, in setup_platform
broadlink_device.auth()
File "/usr/local/lib/python3.7/site-packages/broadlink/__init__.py", line 207, in auth
response = self.send_packet(0x65, payload)
File "/usr/local/lib/python3.7/site-packages/broadlink/__init__.py", line 237, in send_packet
packet[0x24] = self.devtype & 0xff
TypeError: unsupported operand type(s) for &: 'NoneType' and 'int'
I can't do any more tests right now, I'll try again tomorrow.
@SpyrosKyriazos Thanks! I just realized that Home Assistant does not initialize this value correctly, so I decided to keep a default value to avoid problems with the code that is already working. Could anyone check if the problem is solved now?
What is the correct path for Broadlink folder in Hassio raspberry?
@felipediel I got the same error of @SpyrosKyriazos Just made a test with the new version and the error is gone!
Edit: tested the remote.learn_command in home assistant and looks likes is not working (no blinking led and log says no signal received). Also tried to send a command and the led does not blink (no errors shown in the log).
@luisfosoares I don't know if you can do it on Hassio. @goose2600 Weird. The API is working correctly. This seems to be another problem. I will take a look.
I just found the problem. It is related to the problem we just solved. Tomorrow I will put the solution here for testing.
I think this PR will finish the job. Could you help me to test it? Don't forget to add the device type in the configuration file.
Good morning @felipediel, thank you again for your work! Should I change also the remote.py to test it?
@goose2600 Yes.
Unfortunately I am testing from my mobile. Could @felipediel or someone else give me the links to the right raw files? Thanks
Edit: If someone wants to test, these should be the files: https://raw.githubusercontent.com/mjg59/python-broadlink/0ef417a6c73890f69a084e02e392dd2056745f58/broadlink/__init__.py
Edit: I can confirm both learn and send command are working in Home Assistant!
Tested with the files @goose2600 linked and with the following config:
remote:
- platform: broadlink
name: RM
host: 192.168.1.16
mac: '24:df:a7:7a:dd:ff'
type: 0x5f36
Both remote.learn_command and remote.send_command work correctly. Nice solution @felipediel. Thanks again for your effort.
Great! We are done! The update is coming soon. And who doesn't want to wait, do it like @goose2600 and @SpyrosKyriazos. Thanks guys! It was really cool to work with you on this solution!
Might be doing something dumb here @felipediel, but when I try to use the updated code in the config/custom_components/
directory, I get the following error...
Platform error remote.broadlink - cannot import name 'DOMAIN' from 'custom_components.broadlink' (/config/custom_components/broadlink/__init__.py)
I dropped the Broadlink files from Home Assistant Core into custom_components/broadlink
and then replaced the __init__.py
and remote.py
files with the raw files linked by @goose2600. This should override the internal broadlink integration with the files in the custom_components
directory.
I didn't try replacing the files directly in docker yet so might give this a go. But thought I would just mention this incase it is something that needs looking at. Other than that I am happy just to wait for the official update.
Finally I will say congratulations @felipediel you did a superb job! It was great to work with you and everyone else on this and I am very glad we found a solution, as I have two of these newer RM Mini devices and I don't need any more paperweights! 😂
Hey @felipediel, Just letting you know that the changes to the Broadlink python module might also break the Broadlink Home assistant integrations for sensor and switch. I use "Switch" because I use another HA helper called SmartIR which only supports "Switch" type integration of the RM Mini and it crashed because it wouldn't except "None" as a device type. Maybe the default type of 0x272A should be put in the python module or alternatively, the Switch and Sensor files need to be uplifted to support a default type as well. I've done a dirty fix by editing the switch.py:
RM_TYPES_0x5f36 = [ "rm_mini_0x5f36", ]
SWITCH_TYPES = RM_TYPES + RM_TYPES_0x5f36 + SP1_TYPES + SP2_TYPES + MP1_TYPES
if switch_type in RM_TYPES:
broadlink_device = broadlink.rm((ip_addr, 80), mac_addr, **0x272A**)
hass.add_job(async_setup_service, hass, ip_addr, broadlink_device)
switches = []
for object_id, device_config in devices.items():
switches.append(
BroadlinkRMSwitch(
object_id,
device_config.get(CONF_FRIENDLY_NAME, object_id),
broadlink_device,
device_config.get(CONF_COMMAND_ON),
device_config.get(CONF_COMMAND_OFF),
retry_times,
)
)
elif switch_type in RM_TYPES_0x5f36:
broadlink_device = broadlink.rm((ip_addr, 80), mac_addr, **0x5f36**)
hass.add_job(async_setup_service, hass, ip_addr, broadlink_device)
switches = []
for object_id, device_config in devices.items():
switches.append(
BroadlinkRMSwitch(
object_id,
device_config.get(CONF_FRIENDLY_NAME, object_id),
broadlink_device,
device_config.get(CONF_COMMAND_ON),
device_config.get(CONF_COMMAND_OFF),
retry_times,
)
)
Hi guys. Thanks for the tests. I just added 0x5f36 to switch.py. You can grab the file here.
The configuration of the switch is a little different because I kept the syntax that was already being used.
switch:
- platform: broadlink
host: 192.168.0.12
mac: 34:EA:36:B2:44:C3
type: 'rm_mini3_5f36'
switches:
tv_phillips:
friendly_name: "Phillips Tv Power"
command_on: 'JgAcAB0dHB44HhweGx4cHR06HB0cHhwdHB8bHhwADQUAAAAAAAAAAAAAAAA='
command_off: 'JgAaABweOR4bHhwdHB4dHRw6HhsdHR0dOTocAA0FAAAAAAAAAAAAAAAAAAA='
@felipediel
To use do I need to install anything new in the Home Assistant? Or do I need to download a file and include it in a Home Assistant directory?
@Siytek I think you put the __init__.py
file in the wrong folder. If you are using a virtual envinronment the folder is venv/lib/python3.7/site-packages/broadlink
.
You can also use Git to pull these files from my repositories, I just didn't want to make it even more complicated for those who don't know the tool.
@jhonathas The solution will come out-of-the-box, but if you don't want to wait you can download the files and replace them.
Hey @felipediel Thank you for your amazing work. I added the patched files to my own hass instance and connecting and learning commands through cli works fine. Unfortunately, when I try to learn a command through Hass, the RM Mini 3 won't turn on to do anything. After a few seconds Hass times out and returns: "[homeassistant.components.broadlink.remote] Failed to learn 'Turn on/television': no signal received"
@kgorszczyk Did you replace __init__.py
in the folder I mentioned above? Replaced switch.py
and remote.py
in the integration folder? Did you put the correct device type in the configuration file?
Just to be safe I redownloaded all files. The type is the same I used with the cli learning (python broadlink_cli --type 0x5f36 --host 192.168.178.40 --mac ......a7df24 --learn):
remote:
- platform: broadlink
name: Broadlink
host: 192.168.178.40
mac: '24:DF:A7: ....'
type: 0x5f36
Unfortunately still no response from the RM Mini 3.
@felipediel, I use it on a Raspberry pi and installed it via docker (https://www.home-assistant.io/hassio/installation/#preparation). In that case do you know where I should overwrite? I looked here and didn't find it. Is it possible to do the procedure with the environment installed via docker?
How to test it on your computer?
cd YOUR_TEST_FOLDER
git clone -b devtype https://github.com/felipediel/home-assistant.git
cd home-assistant
python3.7 -m venv venv
source venv/bin/activate
script/setup
pip install git+git://github.com/felipediel/python-broadlink.git@patch-1
mkdir config
hass -c config
Finally figured it out. I'm using pyenv to manage several Python Versions and I thought, that Hass would use the globally installed site-packages and use Hass specific packages from the config folder. Well, it's the other way around. Now everything works perfectly. Thanks!
Hey All,
For those who are having some trouble with implementing this change in HA (I'm using HassIO) I've shared the steps I've used:
Placing the broadlink folder in the custom_components folder will override the built in HA integration once you restart HA. It's a much easier way to temporarily override the integration until it's included natively in HA. There's no temporary way to override the python-broadlink module however as far as I know.
Hey All,
For those who are having some trouble with implementing this change in HA (I'm using HassIO) I've shared the steps I've used:
- First get Dev SSH access with instruction here.
- Access the shell with "login" first then "docker exec -it homeassistant /bin/bash"
- Replace the python-broadlink module by first backing up /usr/local/lib/python3.7/site-packages/broadlink/init.py (I'm using HassIO, path may vary).
- Put the updated init.py in its place from here.
- If you want to copy the file, assuming you have the samba-share addon installed, copy the new python-broadlink to your /config folder via the share, then move it after alternatively just paste it into the SSH shell via VI.
- That updates the python Broadlink module, you now need to update the HA Broadlink integration. I suggest downloading HA's source from @felipediel branch here and copy the core-83b1e6e4055471939f9b8470d767ee77c596f968.zip\core-83b1e6e4055471939f9b8470d767ee77c596f968\homeassistant\components\broadlink folder to your /config/custom_components folder in the HA container or via samba: \hassio\config\custom_components
Placing the broadlink folder in the custom_components folder will override the built in HA integration once you restart HA. It's a much easier way to temporarily override the integration until it's included natively in HA. There's no temporary way to override the python-broadlink module however as far as I know.
Superstar @dennisadvani! Yes I was being dumb, of course python-broadlink needed replacing as well as the HA integration in custom_components
. I am super-pleased to report that learning and sending codes now works for me in Home Assistant!! 🎉🥳
@dennisadvani Dude, you are hero, I have to thank you again. The headers I found in your captures enabled me to extend our support to the entire RM4 series.
, is the RM3 integration also broken?, im asking because i cant connect to my mini after an update . tks
@gnkarn You may be experiencing this issue, which is different from the one we just solved here. I still need to do some tests to understand this new problem that came up with the update. But it has nothing to do with this issue. This case is closed. Go to the right place and I will be glad to help you.
Hi guys
What is the status today? Are the PRs merged? Any ETA if not ?
@luisfosoares I think it will take a while because we still need to approve the PR in the API. If you're in a hurry, don't hesitate to follow @dennisadvani's walkthrough.
@felipediel I would like to follow it but im unable
i don't have the folder python3.7 in the path /usr/local/lib
I can find a the folder site-packages inside the "lib" folder but not in "local" . And my python is not 3.7, its 3.8! - so I have the path /usr/lib/python3.8/site-packages
Inside of it there is no "Broadlink"
I find it weird, I tried all folders but can't find it
Im using lates version of Hassio os raspberry pi4
Thanks
Hi guys. Sorry to be bothering you again, but I've made some updates to improve code maintenability and improve Home Assistant support for API changes. So we will not need to approve two PRs in the future. Things will happen faster. Could you test these updates? I tested it on my venv with a RM Pro and it worked well, but I would like to make sure that your devices are also working.
@luisfosoares What system are you using? I can't help you find this folder right now because I'm working on a venv. My folder is at /venv/lib/python3.7/site-packages/broadlink
. So you replace venv with your folder, I don't know where it is.
If I wanted to install the latest version of the API here I would use the following command:
pip install git+git://github.com/felipediel/python-broadlink.git@patch-1
I don't know if you can use this command on your system. If you want to try make sure to stop Home Assistant first. Ah, you may need to use sudo
before the command.
Hi @felipediel, thank you again for your effort. I am running my home assistant into a docker container and I should install git in order to test the patch. Could you please link the raw file?
@goose2600 __init__.py
@felipediel im running hassio hassos v3.12 on raspberry pi 4 with homeassistant v 0.106.6
@luisfosoares Go the the root directory and type:
find . -name broadlink
Nothing is found...weird!
I tried any other folder that i know exists and it works
@luisfosoares If you have python-broadlink installed this folder exists somewhere. Maybe you don't have access to it. Did you try pip? pip install git+git://github.com/felipediel/python-broadlink.git@patch-1
(or the sudo
variation).
You can also try to create the folder /usr/lib/python3.8/site-packages/broadlink
with the __init__.py
inside.
@felipediel Unfortunately my home assistant stops working, I reinstalled it and now I get an error related to some variables missing in broadlink constant.py. Tomorrow I will reinstall and will try your new init.py
@goose2600 What variables?
The variables are DEFAULT_PORT, DEFAULT_RETRY, DEFAULT_TIMEOUT.
I tried to set them and I get this error:
2020-03-14 01:20:31 ERROR (MainThread) [homeassistant.components.remote] Error while setting up broadlink platform for remote Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 179, in _async_setup_platform await asyncio.wait_for(asyncio.shield(task), SLOW_SETUP_MAX_WAIT) File "/usr/local/lib/python3.7/asyncio/tasks.py", line 442, in wait_for return fut.result() File "/usr/src/homeassistant/homeassistant/components/broadlink/remote.py", line 107, in async_setup_platform hass.async_add_executor_job(api.auth), remote.async_load_storage_files() File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run result = self.fn(*self.args, **self.kwargs) File "/usr/local/lib/python3.7/site-packages/broadlink/__init__.py", line 211, in auth response = self.send_packet(0x65, payload) File "/usr/local/lib/python3.7/site-packages/broadlink/__init__.py", line 277, in send_packet self.cs.sendto(packet, self.host) TypeError: an integer is required (got type str)
Maybe I just need to make a fresh install
@goose2600 You helped me find an error, wait a second, I will fix it.
Done (I replaced the files not in the custom_componets folder, but in /usr/src/homeassistant/homeassistant/components/broadlink/ as before home assistant stops working).
Now I get this error: `Platform error: remote
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/config.py", line 752, in async_process_component_config
platform = p_integration.get_platform(domain)
File "/usr/src/homeassistant/homeassistant/loader.py", line 277, in get_platform
f"{self.pkg_path}.{platform_name}"
File "/usr/local/lib/python3.7/importlib/init.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "
The different (I don't know if it's new or not) RM Mini colored red does not work with broadlink component.
I used broadlink_cli to try to get it into learning mode and got the following:
AttributeError: device instance has no attribute 'enter_learning'
In home assistant, the commands just don't execute in the device, altho the buttons goes from on to off normally.
The firmware on this is 44057 Model: RM mini 3 FCC ID: 2ACDZ-RMMINI3-RM
On intelligent home center app from broadlink, the devices work as intended. It has no firmware upgrades available for it. On e-control app, it shows as unrecognized device, but shows.
Using broadlink manager gives the following:
It seems that even tho it's looks like exactly the same model, it operates differently and has a different model number and api to authenticate and recieve learn and send signals.