Broadlink IR Media Player (For old, dump TVs)

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)

Hi,

What is the possibility of sending more than one signal at a time? for example 5 + 3 + 9?

Thanks

Hi! Please take a look here:
https://github.com/vpnmaster/homeassistant-custom-components/issues/47

1 Like

Hello ,your media_player can you add play button?

Hi @Vassilis,

I followed your istruction but I can’t figure out how to manage power_consumption_threshold.

My dump TV is connected through a tp-link hs110 (with power meter). I’ve setup the component as following with a threshold of 28 w:

media_player:
  - platform: broadlink
    name: TV Cucina
    host: 192.168.2.205
    mac: '78:0F:77:5A:CB:78'
    ircodes_ini: 'broadlink_media_codes/philips.ini'
    power_consumption_entity: switch.presa_tpl1
    power_consumption_threshold: 28

The switch works but the status of media player doesn’t change.

Can you please support me?

Thank you in advance!

Doesn’t work anymore in 0.84.0b0

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.

EDIT: Got it
https://github.com/home-assistant/home-assistant/pull/17270

Fixed. Thanks for the hint.

1 Like

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'

my config:

media_player:
  - platform: broadlink
    name: Livingroom TV
    host: 192.168.1.4
    mac: 'NOPE'
    ircodes_ini: 'broadlink_media_codes/livingroom.ini'
    ping_host: 192.168.1.15

any ideas?

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

I bet that’s it! I have the latest code from Github

hello I cloned your git in home / homeassistant / .homeassistant

media_player:

  • platform: broadlink
    name: Sony
    host: 192.160.1.7
    mac: '78: 0F: 77: 32: 12: A6 ’
    ircodes_ini: ‘broadlink_media_codes / sony.ini’
    ping_host: 192.168.1.4

but the error configuration:
Component not found: broadlink
Platform not found: media_player.broadlink

why?
what should I do?

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.

The file should be in
.homeassistant/custom_components/media_player/broadlink.py

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…

1 Like

Now it tells me only Platform media player not found…
I have done the same with Climate and it’s all right
With media player not found instead

Hi, it seems to be fixed 12 hours ago.

replying to my self, for reference:

this is solved: Custom component to declare/set variables

yes thanks, installed and running in .84.1

up?

Anyone use power_consumption_threshold?

Yes, it’s not workin in 0.84.1