Testers Needed - Harmony Hub Support Implemented in Python

great to hear! My pull request was merged today and should be included in the next release:grin:

4 Likes

@iandday congratulations! 2 months to the day since this thread was opened :slight_smile:

Congrats @iandday!

Yeah I noticed that in my emails this morning - I have been checking the PR daily to see the progress and can’t wait to set it up!!

Congratulations, @iandday. This is going to be an excellent addition for remote support!

Very good work guys! I’ve installed the dev release and can issue commands successfully to my Harmony remote!

Now I am trying to turn on a switch only when a particular activity is on, but if it’s any other activity, turn the switch off.

How can I create an automation that triggers when the harmony remote switches to a particular activity? I am having issues defining the trigger part: should I use a custom event, a state trigger ? And if so, how would the config look like? Is current_activity a state ?

Thank you in advance!

I found it difficult to work out, but I ended up with the following to turn on my Home Theatre PC when I switch to one of the related activities. This is similar to what you want and should help you get started. Only issue is that the activation time varies a lot. Sometimes it is near instant, but sometimes it takes a long time (I would guess up to 30 seconds), not sure why.

remote harmony_ultimate:
  platform: harmony
  name: Woonkamer
  username: !secret harmony_username
  password: !secret harmony_password
  host: 192.168.178.14
  port: 5222

automation htpc_on_when_harmony_active:
  alias: Switch on HTPC on Harmony activity change
  trigger:
    platform: state
    entity_id: remote.woonkamer
  condition:
    condition: or
    conditions:
      - condition: template
        value_template: '{{ trigger.to_state.attributes.current_activity == "HTPC TV" }}'
      - condition: template
        value_template: '{{ trigger.to_state.attributes.current_activity == "HTPC Beamer" }}'
  action:
    service: switch.turn_on
    entity_id: switch.htpc

Thank you! That’s what I needed and it’s working good and reliably, despite the delay.

In case it matters to anybody, my goal was to use an Echo Dot attached to my entertainment center, but revert to its internal tiny speaker when my entertainment center is either off, or another receiver input (harmony activity) is selected, so I can still hear the echo when playing TV for instance.
Because Amazon didn’t implement any sort of dual channel in the Echo Dot (which would be ideal), my solution was to purchase a small BlueTooth receiver and a tp-link switch (which is not compatible with Harmony, but is reliable and I had it already). By using home-assistant and the automation below, when I switch to the EchoDot activity, the automation will turn-on the switch, turning on the BT receiver which is paired to Echo. When I select another activity, the bt receiver power is off, which causes Echo to revert back to its internal speaker. Although this solution is superior to using Alexa app to control my tp-link device, I wish tp-link switch eventually gets support from Harmony.

Here’s my automation:

automation:
alias: Turn on BT receiver switch if Harmony activity is “EchoDot”
trigger:
platform: state
entity_id: remote.myharmony
action:
service_template: >
{% if trigger.to_state.attributes.current_activity == “EchoDot” %}
switch.turn_on
{% else %}
switch.turn_off
{% endif %}
entity_id: switch.echodot

1 Like

Hello iandday,

I have a Raspbery Pi3 and used the All-in-One installer.
Currently i’m trying to set up the harmony remote with HASS 0.35.3

When I add the remote to my configuration.yaml file and restart HASS it does not go past the step:
‘Calling pyharmony.ha_get_toekn for remote at:’

See below the last part of the logs;
INFO:homeassistant.bootstrap:Setting up remote
INFO:homeassistant.components.remote:Setting up remote.harmony
DEBUG:sleekxmpp.xmlstream.resolver:Could not find dnspython package. Not all features will be available
DEBUG:homeassistant.components.remote.harmony:Loading Harmony platform: KroeseHarmonyHub
DEBUG:homeassistant.components.remote.harmony:Calling pyharmony.ha_get_token for remote at: 192.168.1.107:5222

I also tried installing pyharmony and to see if I could get that running without error, but there I get the following:

harmony --harmony_ip 192.168.1.107
Traceback (most recent call last):
File “/usr/local/bin/harmony”, line 9, in
load_entry_point(‘pyharmony==1.0.12’, ‘console_scripts’, ‘harmony’)()
File “/usr/local/lib/python3.4/dist-packages/pyharmony/main.py”, line 416, in main
sys.exit(args.func(args))
AttributeError: ‘Namespace’ object has no attribute ‘func’

Hopefully you can help me solving this.

I have the same error on a Pi 2 using the manual install method (in to a virtual environment).

Logs:

17-01-02 19:04:37 homeassistant.loader: Loaded remote.harmony from homeassistant.components.remote.harmony
17-01-02 19:04:37 homeassistant.bootstrap: Setting up remote
17-01-02 19:04:37 homeassistant.components.remote: Setting up remote.harmony
17-01-02 19:04:38 sleekxmpp.xmlstream.resolver: Could not find dnspython package. Not all features will be available
17-01-02 19:04:38 homeassistant.components.remote.harmony: Loading Harmony platform: LivingRoom
17-01-02 19:04:38 homeassistant.components.remote.harmony: Calling pyharmony.ha_get_token for remote at: 192.168.1.248:5222

From there HASS appears to hang. No web interface comes up. Commenting out the “remote:” section in the config file removes the problem and HASS comes up fine. Did you find the problem p.kroese?

1 Like

Hello efiniste ,

I did not get a response yet, so hopefully iandday can help us with this.

Can either one of you post debug logs for the remote component? I don’t run my instance of HASS on a raspi but ill try to help out

I have an automation set up to wake my HTPC if that activity is started. However, just like @Michel it sometimes takes a long time to respond. I would assume this has to do with the scan interval. I can increase it of course, but it seems overkill for only this application and I’m afraid it would make the hub unstable.

Is there any way (using pyharmony I assume) to get a message straight away if an activity has started?

Alternatively I guess I could use the bluetooth on my pi3 (maybe?) to connect to the hub and send a keystroke or something? Has anyone already got a satisfactory solution for this?

Hello iandday,

Regarding the debug log, do you mean the home-assistant.log with logger information homeassistant.components.remote: debug? or is there another log?
This is the only logging I could find regarding the remote component.

17-01-09 23:19:04 homeassistant.core: Bus:Handling <Event component_loaded[L]: component=logger>
17-01-09 23:19:04 homeassistant.bootstrap: Setting up http
17-01-09 23:19:05 homeassistant.core: Bus:Handling <Event component_loaded[L]: component=http>
17-01-09 23:19:05 homeassistant.bootstrap: Setting up history
17-01-09 23:19:05 homeassistant.core: Bus:Handling <Event component_loaded[L]: component=history>
17-01-09 23:19:05 homeassistant.bootstrap: Setting up api
17-01-09 23:19:05 homeassistant.core: Bus:Handling <Event component_loaded[L]: component=api>
17-01-09 23:19:05 homeassistant.bootstrap: Setting up websocket_api
17-01-09 23:19:05 homeassistant.core: Bus:Handling <Event component_loaded[L]: component=websocket_api>
17-01-09 23:19:05 homeassistant.bootstrap: Setting up frontend
17-01-09 23:19:05 homeassistant.core: Bus:Handling <Event component_loaded[L]: component=frontend>
17-01-09 23:19:05 homeassistant.bootstrap: Setting up logbook
17-01-09 23:19:05 homeassistant.core: Bus:Handling <Event service_registered[L]: service=log, domain=logbook>
17-01-09 23:19:05 homeassistant.core: Bus:Handling <Event component_loaded[L]: component=logbook>
17-01-09 23:19:05 homeassistant.bootstrap: Setting up sun
17-01-09 23:19:05 homeassistant.core: Bus:Handling <Event state_changed[L]: old_state=None, new_state=<state sun.sun=below_horizon; next_setting=2017-01-10T15:43:42+00:00, next_rising=2017-01-10T07:40:51+00:00, elevation=0, friendly_name=Sun, azimuth=0 @ 2017-01-09T23:19:05.217246+01:00>, entity_id=sun.sun>
17-01-09 23:19:05 homeassistant.core: Bus:Handling <Event component_loaded[L]: component=sun>
17-01-09 23:19:05 homeassistant.bootstrap: Setting up mqtt
17-01-09 23:19:05 homeassistant.core: Bus:Handling <Event service_registered[L]: service=publish, domain=mqtt>
17-01-09 23:19:05 homeassistant.core: Bus:Handling <Event component_loaded[L]: component=mqtt>
17-01-09 23:19:05 homeassistant.loader: Loaded remote.harmony from homeassistant.components.remote.harmony
17-01-09 23:19:05 homeassistant.bootstrap: Setting up remote
17-01-09 23:19:05 homeassistant.components.remote: Setting up remote.harmony
17-01-09 23:19:05 sleekxmpp.xmlstream.resolver: Could not find dnspython package. Not all features will be available
17-01-09 23:19:05 homeassistant.components.remote.harmony: Loading Harmony platform: KroeseHarmonyHub
17-01-09 23:19:05 homeassistant.components.remote.harmony: Calling pyharmony.ha_get_token for remote at: 192.168.1.109:5222

Hopefully this is uselfull to you.

Thanks in advanced.

Any update on this issue? I have the same.

Thanks

Ian, this code isn’t working for me in a script (using yours as template), any clue why?
bedroom_play:
sequence:
- service: remote.send_command
data_template:
# using a data template to have if brances for relavant device
# Always the same entity_id - the harmony hub
entity_id: remote.bedroom
# Always the same command - the Pause key
command: Play
# select device based upon the activity being undertaken.
device: >
# when in WATCH TV activity, the pause key relates to a TiVo, which is device 22987101
{% if is_state(“sensor.bedroom”, “WATCH TV”) %}{% raw %}
22987101
# when in WATCH APPLE TV activity, the pause key relates to an Apple TV, which is device 23002316
{% raw %}{% elif is_state(“sensor.bedroom”, “WATCH APPLE TV”) %}
23043122
{% endif %}

Post using preformatted text. Are you getting any errors in your logs?

Figured it out, had to not include {% raw %} thank you

You can setup an automation using a change in the remote’s current activity state to trigger a notification or execute a script to send a WOL packet

thanks for the logs, it looks like its failing in the first portion of setup, getting the authorization token from the remote hub. Can you run the command below from the path where you have downloaded pyharmony to?

PYTHONPATH="." python3 pyharmony --harmony_ip 192.168.1.107 show_config

the error about dnspython package missing is odd, have you tried installing that with pip3?

Hello iandday,

I’ve installed dnspython with pip3 and that error message is gone now.
But still HASS hangs.

I ran the command you mentioned; I see nothing happening, so when I after e.g. 1 minute press CTRL-C I get the following:
pi@raspberrypi:/usr/local/lib/python3.4/dist-packages $ PYTHONPATH="." python3 pyharmony --harmony_ip 192.168.1.109 show_config
^CTraceback (most recent call last):
File “/usr/lib/python3.4/runpy.py”, line 170, in _run_module_as_main
main”, mod_spec)
File “/usr/lib/python3.4/runpy.py”, line 85, in _run_code
exec(code, run_globals)
File “pyharmony/main.py”, line 420, in
main()
File “pyharmony/main.py”, line 416, in main
sys.exit(args.func(args))
File “pyharmony/main.py”, line 261, in show_config
client = get_client(args.harmony_ip, args.harmony_port)
File “pyharmony/main.py”, line 39, in get_client
token = harmony_auth.get_auth_token(ip, port)
File “/usr/local/lib/python3.4/dist-packages/pyharmony/auth.py”, line 71, in get_auth_token
login_client.connect(address=(ip_address, port),use_tls=False, use_ssl=False)
File “/usr/local/lib/python3.4/dist-packages/sleekxmpp/clientxmpp.py”, line 160, in connect
reattempt=reattempt)
File “/usr/local/lib/python3.4/dist-packages/sleekxmpp/xmlstream/xmlstream.py”, line 448, in connect
args=(reattempt,))
File “/usr/local/lib/python3.4/dist-packages/sleekxmpp/thirdparty/statemachine.py”, line 70, in transition
func=func, args=args, kwargs=kwargs)
File “/usr/local/lib/python3.4/dist-packages/sleekxmpp/thirdparty/statemachine.py”, line 111, in transition_any
return_val = func(*args,**kwargs) if func is not None else True
File “/usr/local/lib/python3.4/dist-packages/sleekxmpp/xmlstream/xmlstream.py”, line 547, in _connect
self.socket.connect(self.address)
KeyboardInterrupt

So it seems it hangs at xmlstream socket connect.

Does this give you a clue what this could mean?