hass 0.43.2
Python 3.4.2
Having problem with send-packet service of broadlink component. All works fine with switches, so broadlink device and captured signal strings are fine. But when I try to use send-packet service, I get no results. Tried to use Development Tools to test this service, although I'm not sure about JSON syntax. Pasted it below, could someone please confirm this is correct?
{ "data" : { "packet" : "JgCMAJWRFDYUNxMRExITERMRFDYUERM2FDYUERMRFDYUERM3ExETNxMRExITERMSExETERQQFBEUNhQ1FDYUNxM3EzYUNhMABduUkxM3EzYUERMRFBETERM2FBITNhM2FBITEBQ2FBETNxMSEzUUERQRExITERMSExETEhMREzcTNxM1FDYUNhQ2FDYUAA0FAAAAAAAAAAAAAAAA" }}
My broadlink configuration:
> switch 2:
- platform: broadlink
host: 192.168.1.80
mac: 34:EA:34:F4:23:D9
timeout: 15
switches:
dvd_on_off:
friendly_name: "DVD"
command_on: 'JgCMAJWRFDYUNxMRExITERMRFDYUERM2FDYUERMRFDYUERM3ExETNxMRExITERMSExETERQQFBEUNhQ1FDYUNxM3EzYUNhMABduUkxM3EzYUERMRFBETERM2FBITNhM2FBITEBQ2FBETNxMSEzUUERQRExITERMSExETEhMREzcTNxM1FDYUNhQ2FDYUAA0FAAAAAAAAAAAAAAAA'
command_off: 'JgCMAJWRFDYUNxMRExITERMRFDYUERM2FDYUERMRFDYUERM3ExETNxMRExITERMSExETERQQFBEUNhQ1FDYUNxM3EzYUNhMABduUkxM3EzYUERMRFBETERM2FBITNhM2FBITEBQ2FBETNxMSEzUUERQRExITERMSExETEhMREzcTNxM1FDYUNhQ2FDYUAA0FAAAAAAAAAAAAAAAA'
Switch above works without any issues. Not sure what else can be checked.
Enable logging for the Broadlink component, and check your log
I also can't work out how to use send_packet in dev tools. {"packet":"foo"} results in logs that look the same as a script I've configured
2017-05-31 18:46:52 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: service_data=packet='JgBgAAABK5ISExITEhITExQREhITEhUREjcSNxM3EjcSNxM3EjgSNxM3EjcSNxMSEhQSEhMSEhMSExMSEhMSNxI3EzcSOBI3EwAFEgABKkkSAAw3AAEuRhIADDYAAS1HEgANBQAAAAAAAAAA'], service_call_id=34477458208-63, service=send_packet_192_168_1_1, domain=broadlink>
but I see nothing transmitted.
I also have the same issue described in https://community.home-assistant.io/t/script-service-call-for-many-heat-pump-ir-data-codes/14898/3 (the user there gave up trying to resolve it).
Sorry if there is an obvious answer to that, I'm still quite new to it.
Set logging with command
logger:
default: critical
logs:
homeassistant.components.switch.broadlink: debug
but cannot see anything in logs:
17-05-31 20:05:25 INFO (MainThread) [homeassistant.bootstrap] Home Assistant core initialized
17-05-31 20:05:25 INFO (MainThread) [homeassistant.loader] Loaded logger from homeassistant.components.logger
17-05-31 20:05:25 INFO (MainThread) [homeassistant.setup] Setting up logger
Nothing in log file after "Setting up logger" message, even after 20 minutes of HA working. No new entries when broadlink switch is triggered.
In case you haven't figured this out yet, I was having the same problem. The issue was that the send_packet command is expecting and array of packets. If you try this it should work:
{ "data" : { "packet" : ["JgCMAJWRFDYUNxMRExITERMRFDYUERM2FDYUERMRFDYUERM3ExETNxMRExITERMSExETERQQFBEUNhQ1FDYUNxM3EzYUNhMABduUkxM3EzYUERMRFBETERM2FBITNhM2FBITEBQ2FBETNxMSEzUUERQRExITERMSExETEhMREzcTNxM1FDYUNhQ2FDYUAA0FAAAAAAAAAAAAAAAA"] }}
Thanks jloutsenhizer,
Tried it but looks like I've got some issue with send_packet service, still no luck. In case you've got some experience with setting up logger, are you able to comment on my previous post? Using switches works fine, so device itself is OK.
I don't have experience with the logging, but I took a look at this on mine. It looks like the outer most "data" object is causing the issue. This one should work:
{ "packet" : ["JgCMAJWRFDYUNxMRExITERMRFDYUERM2FDYUERMRFDYUERM3ExETNxMRExITERMSExETERQQFBEUNhQ1FDYUNxM3EzYUNhMABduUkxM3EzYUERMRFBETERM2FBITNhM2FBITEBQ2FBETNxMSEzUUERQRExITERMSExETEhMREzcTNxM1FDYUNhQ2FDYUAA0FAAAAAAAAAAAAAAAA"] }
It works! Thank you. That proves that there's nothing wrong with device and broadlink component.
Still no luck with Alexa though. The only way I found to expose scripts to Alexa is via group. So I've created group:
Sky:
name: First
entities:
- script.hgtv
And then script:
hgtv:
sequence:
- service: broadlink.send_packet_192_168_1_80
data:
packet:
- "JgB4AAkbDjsKJAlbCicLKAogCkQJAAGqChsJFwkXCSUJFwlOCRcJFwkACl8JGwo/CSUJXAkpCSkJIApECQABqgoWDjwJOQslCRcJTgkXDRMJAApfCRcNQAklCVwJKQkpCSAJRQkAAasJGAw8CTsJJQkXCU4JFwkXCQANBQ=="
Alexa can see the group fine, but when called, nothing happens. Is that the right way to call script from the group?
Just wanted to chime in that I'm having the initial issue that was described here, even when using the correct format in the dev tools that @jloutsenhizer has in the previous comment. I can use the "learn_command" service just fine, which is how I have the packet to use. Sending packets never seems to work.
There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates.
Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment :+1:
Also experiencing this issue, can learn commands just fine, but can't send anything. Turned on debugging and checked the logs:
2017-11-08 19:47:58 INFO (SyncWorker_19) [root] Sending control command: KEY
2017-11-08 19:47:58 DEBUG (SyncWorker_19) [root] Control accepted.
2017-11-08 19:47:59 DEBUG (SyncWorker_10) [phue] GET /api/Vs1uJNWoIGc96MpACI0Jz8Yp67Co1Vc3knNGcKvp None
2017-11-08 19:47:59 DEBUG (MainThread) [homeassistant.components.websocket_api] WS 1944166928: Received {'type': 'call_service', 'domain': 'broadlink', 'service': 'send_packet_192_168_1_168', 'service_data': {'data': {'packet': ['JgBQAAABKpETExITEhIVNhISFRESExQQFTYUNRM3FRASOBU2EzYSOBU1FBEVEBI4FTUUERQREhMSExM3FDYSExITEzcUNhI4EgAFIQABKkgSAA0FAAAAAAAAAAA']}}, 'id': 11}
2017-11-08 19:47:59 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=broadlink, service=send_packet_192_168_1_168, service_data=data=packet=['JgBQAAABKpETExITEhIVNhISFRESExQQFTYUNRM3FRASOBU2EzYSOBU1FBEVEBI4FTUUERQREhMSExM3FDYSExITEzcUNhI4EgAFIQABKkgSAA0FAAAAAAAAAAA'], service_call_id=1964918960-11>
2017-11-08 19:47:59 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_executed[L]: service_call_id=1964918960-11>
2017-11-08 19:47:59 DEBUG (MainThread) [homeassistant.components.websocket_api] WS 1944166928: Sending {'id': 11, 'type': 'result', 'success': True, 'result': None}
There's nothing that suggests any errors in there from what I can see. It was triggered from the services page using the example in the docs:
{
"data": {
"packet": [
"JgBQAAABKpETExITEhIVNhISFRESExQQFTYUNRM3FRASOBU2EzYSOBU1FBEVEBI4FTUUERQREhMSExM3FDYSExITEzcUNhI4EgAFIQABKkgSAA0FAAAAAAAAAAA"
]
}
}
Also, just tried using https://github.com/davorf/BlackBeanControl and everything's working there too, think I definitely have an issue in my home assistant (Hass.io) setup somewhere. Is it possible to add more logging to the component? (I don't have much python experience).
I've just found this in the logs when starting up home assistant:
2017-11-13 12:54:55 ERROR (MainThread) [homeassistant.components.switch] Error while setting up platform broadlink
Traceback (most recent call last):
File "/usr/lib/python3.6/site-packages/homeassistant/helpers/entity_component.py", line 170, in _async_setup_platform
SLOW_SETUP_MAX_WAIT, loop=self.hass.loop)
File "/usr/lib/python3.6/asyncio/tasks.py", line 352, in wait_for
return fut.result()
File "/usr/lib/python3.6/asyncio/futures.py", line 244, in result
raise self._exception
File "/usr/lib/python3.6/concurrent/futures/thread.py", line 55, in run
result = self.fn(*self.args, **self.kwargs)
File "/usr/lib/python3.6/site-packages/homeassistant/components/switch/broadlink.py", line 150, in setup_platform
device_config.get(CONF_COMMAND_OFF)
File "/usr/lib/python3.6/site-packages/homeassistant/components/switch/broadlink.py", line 185, in __init__
self._command_on = b64decode(command_on) if command_on else None
File "/usr/lib/python3.6/base64.py", line 87, in b64decode
return binascii.a2b_base64(s)
binascii.Error: Incorrect padding
So it seems that your off command is invalid.
I copied it from the learn_command service, its setup like so:
command_off: 'JgBQAAABKJMTEhQREhMTNxITExITEhITEjgSOBM3EhMSOBM3EjcTOBISFRESExISFTYUEBMTEhMSNxM3EzgUNRIUEzYSOBM4EwAFIAABKUgVAA0FAAAAAAAAAAA'
I'll try changing it to something else and see if that makes a difference, thanks.
Figured it all out, the commands character count needs to be a multiple of 4. I had to pad it with = at the end to make it a multiple of 4, and it worked.
I think this issue can technically be closed, however, I think the following can be improved:
When the command on and offs aren't multiples of 4, the switch component cannot be created,
Thanks.
Good suggestion.
You are welcome to open a pull request.
Hi, I just ran into this problem due to what looks like an inconsistency with the documentation and the implementation. The documentation for broadlink.send_packet states as the description for the packet parameter:
String or list of strings that contain the packet data.
This says that the value of packet can be either a string or a list but when trying to use a single string it did not work. The documentation should either be updated to reflect that a list of strings is the only valid type or the implementation should be updated to support either - as is suggested by the current documentation. Personally, I would be in favour of the latter. A patch of homeassistant/components/switch/broadlink.py similar to below should achieve that - happy to submit this in a PR if desired.
packets = call.data.get('packet', [])
if isinstance(packets, str):
packets = [packets]
Most helpful comment
I don't have experience with the logging, but I took a look at this on mine. It looks like the outer most "data" object is causing the issue. This one should work: