Broadlink SP3S Power consumption sensor

Thx for the suggestion.
I have already tried but without success.
My sp2 and sp3 switches do show up in the frontend but don’t work.
The sensors do not even show up.

SP2 - If you see from the issue aboved. The temporary fix has been tested with sp2. So you might put the file wrong place.

Sensor - do you mean the temperature from broadlink as climate?

No, I meant sensor for power consumption.

As for the fix I put it in /home/pi/python-broadlink/broadlink/_ init_.py

for the file I put the link. It is located in the directory below / and this is for home assistant site packages directory not custom_component.

/etc/homeassistant/deps/lib/python3.6/site-packages/broadlink/init.py

For power consumption sensor if it is the custom_component then you have to check from where you get the custom_component from.

Hello guys,
Try updated component https://github.com/algirdasc/homeassistant-backup/blob/master/custom_components/sensor/broadlink_power.py. Problem should be solved.

Great!
I really put it in the wrong place.
I am running HA in virtualenv, so I had to put it in:
srv/homeassistant/homeassistant/venv/lib/python3.5/site-packages/broadlink/_ init_.py

As for the power sensor, this one is the post where I got the code…

I have updated the component.
I still get:
2018-04-24 12:23:56 ERROR (Thread-5) [homeassistant.util.package] Unable to install package broadlink==0.5: Could not find a version that satisfies the requirement pycrypto==1000000000.0.0 (from -c /srv/homeassistant/homeassistant_venv/lib/python3.5/site-packages/homeassistant/package_constraints.txt (line 18)) (from versions: 2.0.1, 2.1.0, 2.2, 2.3, 2.4, 2.4.1, 2.5, 2.6, 2.6.1)
No matching distribution found for pycrypto==1000000000.0.0 (from -c /srv/homeassistant/homeassistant_venv/lib/python3.5/site-packages/homeassistant/package_constraints.txt (line 18))
2018-04-24 12:23:56 ERROR (MainThread) [homeassistant.requirements] Not initializing sensor.broadlink_power because could not install requirement broadlink==0.5
2018-04-24 12:23:56 ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform sensor.broadlink_power: Could not install all requirements.

I got the broadlink_power custom component working on HA 0.67.1, running python 3.6.1 and the broadlink python module version 0.8.0 but it required an ugly hack.
As per your error : broadlink==0.5 requires pycrypto==1000000000.0.0. The version for pycrypto is set to version that will never be available to force you to migrate broadlink to 0.8 where pycryptodome is used instead.
Now the broadlink_power component has broadlink 0.5 as a requirement, which is bad seeing that broadlink 0.5 cannot be installed.
Solution :

  1. upgrade HA to 0.67.1 (https://www.home-assistant.io/docs/installation/hassbian/upgrading/)
  2. install broadlink 0.8 via cli (pip3 install broadlink --upgrade)
  3. update broandlink_power.py :
    line 43:
    self._device = broadlink.sp2((config.get(CONF_HOST), 80), mac_addr)
    to
    self._device = broadlink.sp2((config.get(CONF_HOST), 80), mac_addr , “0x947a”)
    (0x947a is SP3s according to the broadlink module)
  4. start hass using --skip-pip.
    Result :
    broadlink_power

Hi.
I followed your instructions bit I’ve had no luck.
Still: “2018-04-26 12:21:11 ERROR (Thread-10) [homeassistant.util.package] Unable to install package broadlink==0.5: Could not find a version that satisfies the requirement pycrypto==1000000000.0.0 (from -c /srv/homeassistant/homeassistant_venv/lib/python3.5/site-packages/homeassistant/package_constraints.txt (line 18)) (from versions: 2.0.1, 2.1.0, 2.2, 2.3, 2.4, 2.4.1, 2.5, 2.6, 2.6.1)
No matching distribution found for pycrypto==1000000000.0.0 (from -c /srv/homeassistant/homeassistant_venv/lib/python3.5/site-packages/homeassistant/package_constraints.txt (line 18))
2018-04-26 12:21:11 ERROR (MainThread) [homeassistant.requirements] Not initializing sensor.broadlink_power because could not install requirement broadlink==0.5
2018-04-26 12:21:11 ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform sensor.broadlink_power: Could not install all requirements.”

Might it be because I am running python 3.5?

Moreover… when I’ve tried to upgrade Broadlink in virtualenv it installed v0.9.
I reverted to 0.8.

You dont seem to be starting hass with the --skip-pip option (guessing you are using systemctl to start/stop manually). No worries, there is a “solution” for that.
In broadlink_power.py on line 12 where it says :
REQUIREMENTS = [‘broadlink==0.5’]
change it to :
REQUIREMENTS = [‘broadlink==0.8’]
Restart HA, you already have broadlink==0.8, it will just skip it.

It now works perfectly!!!
Many many thanks!!!

Just to aknowledge myself… you wereright in guessing I was restarting manually using systemctl.
How should I have done instead for starting with the --skip pip option?

Using systemctl ensures that the service is running at startup and other nice stuff (ex : logging, service statuses). Not that useful when you are doing “dev work”.
To run hass with extra parameters via systemctl you need to edit the service. For HA :

nano /etc/systemd/system/[email protected].
Look for the ExecStart line and add the extra parameters you want :
ExecStart=/srv/homeassistant/bin/hass --skip-pip

Please keep in mind that doing this is a permanent change and it might (rather will) mess up HA when you next upgrade. HA tries to satisfy all requirements of your components/switches/sensors by pulling specific versions via pip. If you --skip-pip by default, next time you upgrade you will need to manually satisfy those requirements (for example HA 0.68 might require broadlink==0.9 but you will have 0.8 installed and --skip-pip will make it so that HA will not pull version 0.9).

To run HA without servicectl:

$ sudo systemctl stop [email protected]
$ sudo su -s /bin/bash homeassistant
$ source /srv/homeassistant/bin/activate
(homeassistant) homeassistant@hassbian:/home/pi $ hass --skip-pip

This has the drawback that will not daemonize the process (unless you add --daemon, of course). Once the SSH session is terminated, so is HA. This is a good option for debugging.

Crystal clear!

thanks for your replies. I’ve fixed script and updated it in github using your notes.

I receive this error now

2018-06-11 12:01:16 ERROR (MainThread) [homeassistant.requirements] Not initializing sensor.broadlink_power because could not install requirement broadlink==0.5
2018-06-11 12:01:16 ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform sensor.broadlink_power: Could not install all requirements.
2018-06-11 12:01:17 INFO (SyncWorker_7) [xiaomi_gateway] Gateway discovery finished in 5 seconds
2018-06-11 12:01:17 INFO (SyncWorker_7) [xiaomi_gateway] Creating Multicast Socket
2018-06-11 12:01:17 DEBUG (SyncWorker_7) [homeassistant.components.xiaomi_aqara] Gateways discovered. Listening for broadcasts
2018-06-11 12:01:21 ERROR (SyncWorker_15) [homeassistant.util.package] Unable to install package broadlink==0.5: Could not find a version that satisfies the requirement pycrypto==1000000000.0.0 (from -c /usr/lib/python3.6/site-packages/homeassistant/package_constraints.txt (line 18)) (from versions: 2.0.1, 2.1.0, 2.2, 2.3, 2.4, 2.4.1, 2.5, 2.6, 2.6.1)
No matching distribution found for pycrypto==1000000000.0.0 (from -c /usr/lib/python3.6/site-packages/homeassistant/package_constraints.txt (line 18))
2018-06-11 12:01:21 ERROR (MainThread) [homeassistant.requirements] Not initializing sensor.broadlink_power because could not install requirement broadlink==0.5
2018-06-11 12:01:21 ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform sensor.broadlink_power: Could not install all requirements.
2018-06-11 12:01:30 ERROR (SyncWorker_18) [homeassistant.util.package] Unable to install package lxml==4.1.1: Command “/usr/bin/python3 -u -c “import setuptools, tokenize;file=’/tmp/pip-build-dwtlybtf/lxml/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-u4hkzi93-record/install-record.txt --single-version-externally-managed --prefix --compile --user --prefix=” failed with error code 1 in /tmp/pip-build-dwtlybtf/lxml/

2018-06-14 14:53:46 ERROR (MainThread) [homeassistant.requirements] Not initializing sensor.broadlink_power because could not install requirement broadlink==0.8
2018-06-14 14:53:46 ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform sensor.broadlink_power: Could not install all requirements.
2018-06-14 14:54:50 ERROR (SyncWorker_13) [homeassistant.util.package] Unable to install package broadlink==0.8: Command “/usr/bin/python3 -u -c “import setuptools, tokenize;file=’/tmp/pip-build-hpx54wly/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-wc9a3ikn-record/install-record.txt --single-version-externally-managed --prefix --compile --user --prefix=” failed with error code 1 in /tmp/pip-build-hpx54wly/pycryptodome/
2018-06-14 14:54:50 ERROR (MainThread) [homeassistant.requirements] Not initializing sensor.broadlink_power because could not install requirement broadlink==0.8
2018-06-14 14:54:50 ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform sensor.broadlink_power: Could not install all requirements.
2018-06-14 14:54:59

Does anyone have a mirror of https://github.com/algirdasc/homeassistant-backup/blob/master/custom_components/sensor/broadlink_power.py ?

The file has been removed.

Thanks!

1 Like

I found the file here:

https://raw.githubusercontent.com/bhaap/Broadlinkpower-home-assistant-component/master/broadlinkpower.py

Mirror: https://pastebin.com/nHGTBp4i

I think I made the right modifications to broadlinkpower.py but its not working for me. Do I need to modify _ init_.py ? Any ideas where I do that in a docker container?

Hey, sorry, I’ve migrated my repository. You can find sensor here: https://github.com/algirdasc/hass-components/tree/master/sensor

Hi all,

Sorry to bump this thread again. I’m trying to connect my SP3S (with power sensor) to my HA, but i ran into issues. First, let me inform you my running system :

  • Home Assistant 0.74.0 (Hass.io) running on Ubuntu server 18.04 virtual machine (vmware) under Windows 10
  • The virtual machine is bridged to the network

I can use the SP3S perfectly under Broadlink’s IHC app.

I also can add the SP3S as switch in configuration.yaml using broadlink platform. It works perfectly as switch, meaning I can turn on/off the switch from HA and the status will update in both HA and IHC. However, using this as switch won’t show any power usage information.

I then use your custom component, upload it under /usr/share/hassio/homeassistant/custom-components/sensor/broadlink_power.py change the platform type to broadlink_power and put it under sensor like this :

sensor:
  - platform: yr

  - platform: broadlink_power
    host: 192.168.0.140
    mac: '34:ea:34:75:c2:53'
    friendly_name: 'Water Heater' 

After HA restart, I get following error in the dev-info page :

Testing configuration at /config ERROR:homeassistant.scripts.check_config:BURB Traceback (most recent call last): File "/usr/local/lib/python3.6/site-packages/homeassistant/scripts/check_config.py", line 207, in check res['components'] = check_ha_config_file(hass) File "/usr/local/lib/python3.6/site-packages/homeassistant/scripts/check_config.py", line 372, in check_ha_config_file platform = loader.get_platform(hass, domain, p_name) File "/usr/local/lib/python3.6/site-packages/homeassistant/loader.py", line 59, in get_platform return get_component(hass, PLATFORM_FORMAT.format(domain, platform)) File "/usr/local/lib/python3.6/site-packages/homeassistant/loader.py", line 87, in get_component module = importlib.import_module(path) File "/usr/local/lib/python3.6/importlib/__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 994, in _gcd_import File "<frozen importlib._bootstrap>", line 971, in _find_and_load File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 665, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 674, in exec_module File "<frozen importlib._bootstrap_external>", line 781, in get_code File "<frozen importlib._bootstrap_external>", line 741, in source_to_code File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed File "/config/custom_components/sensor/broadlink_power.py", line 7 <!DOCTYPE html> ^ SyntaxError: invalid syntax Fatal error while loading config: invalid syntax (broadlink_power.py, line 7) Failed config General Errors: - invalid syntax (broadlink_power.py, line 7) Successful config (partial)
8:31 AM components/hassio/__init__.py (ERROR)


Log Details (ERROR)
Tue Jul 31 2018 08:31:55 GMT+0700 (Western Indonesia Time)

Testing configuration at /config
ERROR:homeassistant.scripts.check_config:BURB
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/scripts/check_config.py", line 207, in check
    res['components'] = check_ha_config_file(hass)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/scripts/check_config.py", line 372, in check_ha_config_file
    platform = loader.get_platform(hass, domain, p_name)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/loader.py", line 59, in get_platform
    return get_component(hass, PLATFORM_FORMAT.format(domain, platform))
  File "/usr/local/lib/python3.6/site-packages/homeassistant/loader.py", line 87, in get_component
    module = importlib.import_module(path)
  File "/usr/local/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 674, in exec_module
  File "<frozen importlib._bootstrap_external>", line 781, in get_code
  File "<frozen importlib._bootstrap_external>", line 741, in source_to_code
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/config/custom_components/sensor/broadlink_power.py", line 7
    <!DOCTYPE html>
    ^
SyntaxError: invalid syntax
Fatal error while loading config: invalid syntax (broadlink_power.py, line 7)
Failed config
  General Errors: 
    - invalid syntax (broadlink_power.py, line 7)

Successful config (partial)

I am new to both HA and linux environments, and so I suspect there’s something wrong with the file/folder location. Then I browse to /usr/local/lib/python3.6/ where I can’t found the site-package folder and only dist-package folder (which is empty).

Do you think this is the cause of my problem? If yes, how do I install the site-package to correct location?

FYI, I’ve also tried replacing init.py from https://github.com/mjg59/python-broadlink/blob/master/broadlink/init.py to /usr/share/hassio/homeassistant/deps/python-broadlink/broadlink but the error is still the same.

Please give me a clue on what’s wrong with the method, or how should I do it in order to make the power consumption appear in HA.

Thank you in advance, and sorry for my English!