Broadlink S1C Alarm Kit Custom Sensor Component

Apparently, pycrypto issue has been fixed. However, I can still see some errors.

 2018-03-08 00:18:30 DEBUG (MainThread) [custom_components.sensor.broadlink_s1c] starting platform setup
2018-03-08 00:18:31 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up platform broadlink_s1c
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/homeassistant/helpers/entity_platform.py", line 84, in async_setup
    SLOW_SETUP_MAX_WAIT, loop=hass.loop)
  File "/usr/lib/python3.6/asyncio/tasks.py", line 358, in wait_for
    return fut.result()
  File "/usr/lib/python3.6/asyncio/futures.py", line 245, in result
    raise self._exception
  File "/usr/lib/python3.6/asyncio/tasks.py", line 180, in _step
    result = coro.send(None)
  File "/usr/lib/python3.6/asyncio/coroutines.py", line 210, in coro
    res = func(*args, **kw)
  File "/config/custom_components/sensor/broadlink_s1c.py", line 91, in async_setup_platform
    conn_obj = HubConnection(ip_address, mac_addr, timeout)
  File "/config/custom_components/sensor/broadlink_s1c.py", line 171, in __init__
    self._hub = broadlink.S1C((ip_addr, 80), mac_addr)
AttributeError: module 'broadlink' has no attribute 'S1C'
2

Great news
Got it work
:grinning:

1 Like

Awesome!
Did you did anything else?

1 Like

The issue was the format of the IP and mac. Below is the correct format.

  - platform: broadlink_s1c
    ip_address: 172.x.x.x # set your s1c hub local ip address
    mac: '34:EA:34:XX:XX:XX' # set your s1c hub mac address

Another thing that I can confirm, it is working on S2C.

Thanks mate

2 Likes

That’s great!
Thanks for the QA. :wink:

@dearlk
We have a S2C confirmation!:grinning:

1 Like

ok, I tryed to follow your instructions but I get this error on my Hassio 0.62.1

2018-03-07 20:19:18 ERROR (SyncWorker_2) [homeassistant.util.package] Unable to install package https://github.com/TomerFi/python-broadlink/archive/master.zip#broadlink==0.6: Command "/usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-_0pzggns/pycryptodome/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-3wxbvvvr-record/install-record.txt --single-version-externally-managed --prefix  --compile --user --prefix=" failed with error code 1 in /tmp/pip-build-_0pzggns/pycryptodome/
2018-03-07 20:19:18 ERROR (MainThread) [homeassistant.setup] Not initializing sensor.broadlink_s1c because could not install dependency https://github.com/TomerFi/python-broadlink/archive/master.zip#broadlink==0.6
2018-03-07 20:19:18 ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform sensor.broadlink_s1c: Could not install all requirements.

Is it because I should update?

Cool. I will try over this weekend

Ok I can confirm it working perfectly with Hassio 0.64.3 with this change:

REQUIREMENTS = ['https://github.com/TomerFi/python-broadlink/archive/master.zip#broadlink==0.6']

Thank you so so much TomerFi!!!

1 Like

I think in your case it might be the opposite issue because of the version.
My referenced library required was updated to use pycryptodome instead of pycrypto because they are actually the same and they can’t work together and HA already works with pycryptodome.
Maybe 0.62.1 still works with pycrypto

Can you please try changing the assignment of the REQUIREMENTS to the original library:

REQUIREMENTS = ['https://github.com/mjg59/python-broadlink/archive/master.zip#broadlink==0.6']

Delete the cache file ‘broadlink_s1c.cpython-36.pyc’, restart HA and let us know if helped?

If it won’t help then maybe the quickest solution for you will be to upgrade, but I would prefer to try and figure out what’s the problem first.

1 Like

oh yes, now it works but I had to change my configuration exposing ip and mac like:

  - platform: broadlink_s1c
    ip_address: 192.168.1.77
    mac: '34:EA:34:XX:XX:XX'

because using the secrets.yaml file I kept receiving this error:
and the error I read is

2018-03-08 10:05:48 INFO (MainThread) [homeassistant.components.sensor] Setting up sensor.broadlink_s1c
2018-03-08 10:05:48 DEBUG (MainThread) [custom_components.sensor.broadlink_s1c] starting platform setup
2018-03-08 10:05:48 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up platform broadlink_s1c
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/homeassistant/helpers/entity_component.py", line 189, in _async_setup_platform
    SLOW_SETUP_MAX_WAIT, loop=self.hass.loop)
  File "/usr/lib/python3.6/asyncio/tasks.py", line 358, in wait_for
    return fut.result()
  File "/usr/lib/python3.6/asyncio/futures.py", line 245, in result
    raise self._exception
  File "/usr/lib/python3.6/asyncio/tasks.py", line 180, in _step
    result = coro.send(None)
  File "/usr/lib/python3.6/asyncio/coroutines.py", line 210, in coro
    res = func(*args, **kw)
  File "/config/custom_components/sensor/broadlink_s1c.py", line 93, in async_setup_platform
    conn_obj = HubConnection(ip_address, mac_addr, timeout)
  File "/config/custom_components/sensor/broadlink_s1c.py", line 173, in __init__
    self._hub = broadlink.S1C((ip_addr, 80), mac_addr)
AttributeError: module 'broadlink' has no attribute 'S1C'

Thank you very much for your help @TomerFi

2 Likes

I’m glad it’s working. :grinning:
I’ll try and update the component so that it will assign a different requirement based on the HA version.
That way it will support all versions until the original library will be updated aswell.

But I think the error message you’ve received module 'broadlink' has no attribute 'S1C'
was not caused by the use of the secrets.yaml file.
The error simply says that there is no S1C support in the imported broadlink library.
Which probably means its trying to work with the pre-existing broadlink 0.5 library and not the required broadlink 0.6 one.

A while ago I had a feeling that in some cases HA initiates newly added custom components before its done satisfying their requirements, which means that once the component was initiated it imported the broadlink 0.5 library instead of broadlink 0.6 which was not fully installed yet.

If that’s the case then I believe that now after the component was already initiated once and the cache file was created, this issue is resolved.

I also work with the secrets.yaml file and it works well.
If you can try reinserting the secret, restarting HA and confirming it for us, I’ll try and update the component so it will force the use of broadlink 0.6.

2 Likes

Would this also work with more than one S1C bridge?

I haven’t tried it because I only have one.
But I don’t see any problem with it, you’ll have to configure it like so:

sensor:
  - platform: broadlink_s1c
    ip_address: "xxx.xxx.xxx.xxx"
    mac: "xx:xx:xx:xx:xx:xx"
  - platform: broadlink_s1c
    ip_address: "yyy.yyy.yyy.yyy"
    mac: "yy:yy:yy:yy:yy:yy"

Just make sure the names of the sensors in the Braodlink app is not the same for more then one sensor.
I didn’t thought about the option of having two bridges each having a sensor with the same name,
So I create the entity id based on the name, I’m not sure what the result would be in this case.

1 Like

I have the same error home assistant 0.64.3 , upgraded to broadlink 0.6

Blockquote Error while setting up platform broadlink_s1c
Traceback (most recent call last):
File “/srv/homeassistant/homeassistant_venv/lib/python3.5/site-packages/homeassistant/helpers/entity_platform.py”, line 84, in async_setup
SLOW_SETUP_MAX_WAIT, loop=hass.loop)
File “/usr/lib/python3.5/asyncio/tasks.py”, line 400, in wait_for
return fut.result()
File “/usr/lib/python3.5/asyncio/futures.py”, line 293, in result
raise self._exception
File “/usr/lib/python3.5/asyncio/tasks.py”, line 239, in _step
result = coro.send(None)
File “/usr/lib/python3.5/asyncio/coroutines.py”, line 210, in coro
res = func(*args, **kw)
File “/home/homeassistant/.homeassistant/custom_components/sensor/broadlink_s1c.py”, line 93, in async_setup_platform
conn_obj = HubConnection(ip_address, mac_addr, timeout)
File “/home/homeassistant/.homeassistant/custom_components/sensor/broadlink_s1c.py”, line 173, in init
self._hub = broadlink.S1C((ip_addr, 80), mac_addr)
AttributeError: module ‘broadlink’ has no attribute ‘S1C’

any news how to bypass broadlink 0.5 and use 0.6 library?

I get a lot of these errors after a while:
Any idea?

Failed to connect. No retries.
1:02 AM /usr/lib/python3.6/site-packages/pychromecast/socket_client.py (ERROR)

max exceptions allowed in watch loop exceeded, stoping watch loop
4:20 PM custom_components/sensor/broadlink_s1c.py (ERROR)

Fri Mar 09 2018 16:20:03 GMT+0700 (SE Asia Standard Time)
exception while getting sensors status: Traceback (most recent call last):
  File "/config/custom_components/sensor/broadlink_s1c.py", line 262, in run
    current_status = self._hub.get_sensors_status()
  File "/config/deps/lib/python3.6/site-packages/broadlink/__init__.py", line 548, in get_sensors_status
    response = self.send_packet(0x6a, packet)
  File "/config/deps/lib/python3.6/site-packages/broadlink/__init__.py", line 286, in send_packet
    response = self.cs.recvfrom(2048)
socket.timeout: timed out

@dustardly2
I think I have a workaround.
I’m just testing it myself and if it works I’ll share it shortly.

@Marc_R
It’s kind of a “defense mechanism” ,
If you have too many network exceptions that prevent the connection to the bridge, the connection stops trying so it won’t overload your network or your HA log file.
I’m thinking about canceling it, but for now I’ve just adjusted it so it will allow more exceptions in a shorter amount of time.
I’ll share the new version shortly.

2 Likes

The fixed version is here.
Please try deleting your cache file before restarting to the new version.

@dustardly2
I’ve pushed the import broadlink further down the script, please let me know if it helps.

@Marc_R
I’ve change the exception limit to 50 exception in 1 minute will cause the bridge to stop,
Please let me no how is it working for you.

2 Likes

tested now and work perfect after a reboot, just one thing, all sensor are showed in the whater sensor menu, probably I need to edit configuration.yaml in another way?

I add sensor after this

Weather prediction

sensor:
I have 2 A1 broadlink
after I add ip and mac address of 5 (2 s1c and 3 s2c and all working but notify me in the high menu ) there is a way to show in a different menu?

Thanks a lot for your share!|

I’m sorry, I didn’t quite understand what are you trying to do.
Maybe you can share the yaml configuration so it will be more clear.