I really like this project! Many thanks to @Vassilis
As I’m kind of new to building custom components and not a very expertised python programmer I have a question.
Would it be possible to control a switch which is available in home assistant, from a custom component script? What would the code look like?
In my case I have a TV connected to a Sonoff outlet so instead of turning the TV on and off via an ir-signal I’d like to just turn on and off the Sonoff switch because that’s why more reliable in my setup.
Thanks in advance!
This is my basic idea but I guess I need some type of import or something…
def turn_off(self):
self.send_ir('general', 'turn_off')
self._state = STATE_OFF
self.schedule_update_ha_state()
#This is where my idea starts I know that it doesn't work at all...
service_data = {'entity_id': 'switch.steckdose_1' }
hass.services.call('light', 'turn_off', service_data, False)
2018-12-06 14:32:58 ERROR (MainThread) [homeassistant.loader] Error loading custom_components.media_player.broadlink. Make sure all dependencies are installed
Traceback (most recent call last):
File "/srv/ha/lib/python3.6/site-packages/homeassistant/loader.py", line 92, in get_component
module = importlib.import_module(path)
File "/usr/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 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/homeassi/.homeassistant/custom_components/media_player/broadlink.py", line 20, in <module>
from homeassistant.helpers.restore_state import async_get_last_state
ImportError: cannot import name 'async_get_last_state'
2018-12-06 14:32:58 ERROR (MainThread) [homeassistant.loader] Unable to find component media_player.broadlink
I think it has something to do with last states stored in .storage/core.restore_state, but cant find any PR at the moment.
Getting the following error after initial install.
Sat Dec 08 2018 21:41:17 GMT-0600 (Central Standard Time)
Error loading custom_components.media_player.broadlink. Make sure all dependencies are installed
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/homeassistant/loader.py", line 92, 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 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/config/custom_components/media_player/broadlink.py", line 21, in <module>
from homeassistant.helpers.restore_state import RestoreEntity
ImportError: cannot import name 'RestoreEntity'
Hi, you are using the latest code which is compatible only with the upcoming version 0.84.X. Please use this code instead, but remember to update again when you install 0.84
SO, by going back to the previous version of broadlink.py solved the original problem but now I get an error that the hassio: component failed to load. Also, the media player now shows up in the UI but nothing works.
Hi!
Since you’ve been able to fix this, maybe you could hint as to how you did it? We also experience this same issue in the custom component variable, see: Custom component to declare/set variables,
which has been working flawlessly over the last 13 months, and hasn’t changed…