Testers Needed - Harmony Hub Support Implemented in Python

I’ve been working on one of the many pyharmony forks and I think it’s finally at a point to request some outside testing. I have implemented a harmony component, harmony switch, and harmony sensor that will give your HASS installation:

  • Support for multiple hubs

  • A sensor to display each hub’s current activity

  • A switch for each activity programmed to each hub.

pyharmony package
HASS Branch

Sample configuration.yaml
harmony:
- name: Bedroom
username: EMAIL
password: PASSWORD
ip: 10.168.1.13
port: 5222
- name: Family Room
username: EMAIL
password: PASSWORD
ip: 10.168.1.16
port: 5222

I’m still not sure how to implement the functionality to send individual device commands as a HASS service. I’m torn between the following options:

  • Create it as a service for the sensor?
  • Create a new remote component with a harmony platform to handle the device command service?

The code is far from PR ready, I’m open to any suggestions, thanks for the feedback!

3 Likes

I’d love to test this but I’m going to have to wait until the segfault issues in the 29 release get resolved first; I don’t want to add anything to my setup that will further confuse the issue.

As far as your two options I’d vote for the second one.

Installed pyharmony, added the required harmony.py to /components/ /components/switch/ and components/sensor/ and added the following to my config:

harmony:
  name: Living Room
  username: !secret harmony_user
  password: !secret harmony_pass
  ip: 10.0.0.209
  port: 5222

and I receive the following error:

(hass_venv) hass@raspberrypi:~/.homeassistant $ hass --script check_config
Testing configuration at /home/hass/.homeassistant
Fatal error while loading config: 'module' object has no attribute 'DOMAIN'

any way you can post your config file? I copied what you have posted into mine and it passed the config check with no issues.

Sure.

If everything passed the config_check on your end, then there is a good chance I duffed the pyharmony install somewhere along the way.

this is going to sound stupid but I pasted the harmony portion from your config into a text editor and removed the comment symbol, it looks like all the values are only spaced one space off the left margin instead of two

I have it as 2 spaces from the left margin in Git. I’ll pull up my working copy and verify, but I don’t think that’s it…

Edit: Working copy on my RPi has 2 space indent, still fails.

harmony:
  name: Living Room
  username: !secret harmony_user
  password: !secret harmony_pass
  ip: 10.0.0.209
  port: 5222

(hass_venv) hass@raspberrypi:~/.homeassistant $ hass --script check_config
Testing configuration at /home/hass/.homeassistant
Fatal error while loading config: 'module' object has no attribute 'DOMAIN'

I’m an idiot. I installed pyharmony, but I didn’t install it into my virtual environment.

One of the side effects of having a 2 month old…

Here are the errors that it’s throwing in the logs.

16-10-04 01:25:49 homeassistant.components.sensor: Error while setting up platform harmony
Traceback (most recent call last):
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/helpers/entity_component.py", line 107, in _setup_platform
    discovery_info)
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/components/sensor/harmony.py", line 22, in setup_platform
    add_devices([HarmonySensor(hub[CONF_NAME],
TypeError: string indices must be integers
16-10-04 01:25:49 homeassistant.components.switch: Error while setting up platform harmony
Traceback (most recent call last):
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/helpers/entity_component.py", line 107, in _setup_platform
    discovery_info)
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/components/switch/harmony.py", line 22, in setup_platform
    activities = pyharmony.ha_get_activities(hub[CONF_USERNAME], hub[CONF_PASSWORD], hub[CONF_IP], hub[CONF_PORT])
TypeError: string indices must be integers

haha, whoops. I appreciate you playing along!

I made a few tweaks to pyHarmony and it’s now available for installation via PyPi (version 1.0.5) I also made some tweaks to the files you copied over, changed the input ‘IP’ value to “host” to fall inline with the other implemented components, and have implemented the remote component and the harmony platform.

Upon startup a text file will be written to the HASS config directory for the Hub and will include all programmed activities, devices, and device commands for use in the three implemented remote services.

Attached is a working config file
configuration.yaml (1.4 KB)

Would it be possible to trash the current venv and try again??

1 Like

tearing things apart and rebuilding now.’

EDIT: And we’re up and running. I’ll let you know if I notice anything out of the blue.

It freaks out after the 3rd or 4th command, or if it receives two commands too quickly.

16-10-06 05:16:00 homeassistant.core: WorkerPool:All 11 threads are busy and 37 jobs pending

16-10-06 05:16:00 homeassistant.core: WorkerPool:Current job started at 2016-10-06T00:13:00.542331-05:00: (<bound method EntityPlatform._update_entity_states of <homeassistant.helpers.entity_component.EntityPlatform object at 0x723718d0>>, datetime.datetime(2016, 10, 6, 5, 13, 0, 502384, tzinfo=))
16-10-06 05:16:00 homeassistant.core: WorkerPool:Current job started at 2016-10-06T00:13:30.528503-05:00: (<bound method EntityPlatform._update_entity_states of <homeassistant.helpers.entity_component.EntityPlatform object at 0x7234f4d0>>, datetime.datetime(2016, 10, 6, 5, 13, 30, 502428, tzinfo=))
16-10-06 05:16:00 homeassistant.core: WorkerPool:Current job started at 2016-10-06T00:14:00.514881-05:00: (<bound method EntityPlatform._update_entity_states of <homeassistant.helpers.entity_component.EntityPlatform object at 0x7234f4d0>>, datetime.datetime(2016, 10, 6, 5, 14, 0, 502842, tzinfo=))
16-10-06 05:16:00 homeassistant.core: WorkerPool:Current job started at 2016-10-06T00:14:00.528319-05:00: (<bound method EntityPlatform._update_entity_states of <homeassistant.helpers.entity_component.EntityPlatform object at 0x723542f0>>, datetime.datetime(2016, 10, 6, 5, 14, 0, 502842, tzinfo=))
16-10-06 05:16:01 homeassistant.core: WorkerPool:Current job started at 2016-10-06T00:14:00.598235-05:00: (<bound method EntityPlatform._update_entity_states of <homeassistant.helpers.entity_component.EntityPlatform object at 0x723718d0>>, datetime.datetime(2016, 10, 6, 5, 14, 0, 502842, tzinfo=))
16-10-06 05:16:01 homeassistant.core: WorkerPool:Current job started at 2016-10-06T00:14:01.901549-05:00: (<bound method ServiceRegistry._execute_service of <homeassistant.core.ServiceRegistry object at 0x75e2afb0>>, <homeassistant.core.Service object at 0x7640fee0>, <ServiceCall switch.turn_on: entity_id=[‘switch.harmony_living_room_watch_netflix’]>)
16-10-06 05:16:01 homeassistant.core: WorkerPool:Current job started at 2016-10-06T00:14:30.536499-05:00: (<bound method EntityPlatform._update_entity_states of <homeassistant.helpers.entity_component.EntityPlatform object at 0x723542f0>>, datetime.datetime(2016, 10, 6, 5, 14, 30, 501984, tzinfo=))
16-10-06 05:16:01 homeassistant.core: WorkerPool:Current job started at 2016-10-06T00:14:30.547487-05:00: (<bound method EntityPlatform._update_entity_states of <homeassistant.helpers.entity_component.EntityPlatform object at 0x7234f4d0>>, datetime.datetime(2016, 10, 6, 5, 14, 30, 501984, tzinfo=))
16-10-06 05:16:01 homeassistant.core: WorkerPool:Current job started at 2016-10-06T00:14:30.646292-05:00: (<bound method EntityPlatform._update_entity_states of <homeassistant.helpers.entity_component.EntityPlatform object at 0x723718d0>>, datetime.datetime(2016, 10, 6, 5, 14, 30, 501984, tzinfo=))
16-10-06 05:16:01 homeassistant.core: WorkerPool:Current job started at 2016-10-06T00:14:57.909499-05:00: (<bound method ServiceRegistry._execute_service of <homeassistant.core.ServiceRegistry object at 0x75e2afb0>>, <homeassistant.core.Service object at 0x7640fee0>, <ServiceCall switch.turn_on: entity_id=[‘switch.harmony_living_room_watch_smart_tv’]>)
16-10-06 05:16:01 homeassistant.core: WorkerPool:Current job started at 2016-10-06T00:15:07.950714-05:00: (<bound method EntityPlatform._update_entity_states of <homeassistant.helpers.entity_component.EntityPlatform object at 0x7234f4d0>>, datetime.datetime(2016, 10, 6, 5, 15, 0, 502007, tzinfo=))
16-10-06 05:16:23 homeassistant.core: BusHandler:Exception doing job
Traceback (most recent call last):
File “/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/core.py”, line 1164, in job_handler
func(*args)
File “/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/helpers/entity_component.py”, line 229, in _update_entity_states
entity.update_ha_state(True)
File “/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/helpers/entity.py”, line 156, in update_ha_state
state = STATE_UNKNOWN if self.state is None else str(self.state)
File “/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/components/sensor/harmony.py”, line 33, in state
return self.get_status()
File “/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/components/sensor/harmony.py”, line 37, in get_status
return str(self._harmony_device.state)
File “/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/components/harmony.py”, line 102, in state
return self.get_status()
File “/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/components/harmony.py”, line 114, in get_status
return pyharmony.ha_get_current_activity(self._email, self._password, self._ip, self._port)
File “/srv/hass/hass_venv/lib/python3.4/site-packages/pyharmony/main.py”, line 155, in ha_get_current_activity
current_activity_id = client.get_current_activity()
File “/srv/hass/hass_venv/lib/python3.4/site-packages/pyharmony/client.py”, line 59, in get_current_activity
result = iq_cmd.send(block=True)
File “/srv/hass/hass_venv/lib/python3.4/site-packages/sleekxmpp-1.3.1-py3.4.egg/sleekxmpp/stanza/iq.py”, line 233, in send
raise IqTimeout(self)
sleekxmpp.exceptions.IqTimeout:

How often is pyharmony polling the hub? I ask, because I have noticed a significant lag in the physical remote sending commands to my home theatre when the harmony component is active. I had to disable it after numerous complaints from my wife this morning.

I’m in! I’ll get it set up tomorrow and report back.

Both the remote and sensor platforms were polling the hub every thirty seconds. I’m half way through a rewrite after realizing I’m over complicating things. I’m going to only utilize the remote component which will expose all the necessary services that can be used to start activities and send commands, the remote’s state can be polled to find out what activity is currently running.

I’m planning on changing the configuration file routine to generate the necessary configuration file entries that will be needed to create a push button for each programmed activity.

I received that XMPP timeout error you did a few times during testing, I think I’ll have to add something to pyharmony to catch that error and retry it.

Hopefully i can get the next version out this weekend, I really appreciate the help!

Thanks for volunteering! would you mind holding off for a day or two until I finish the modifications from Bahnburner’s testing??

After the complaints from the wife, I reverted back to my old unidirectional ifttt based method. Let me know when you have any updates that need testing, and I’ll uncomment the component and give it a whirl.

Hopefully this go-round has a higher WAF. I realized the first attempt was polling the Harmony device way to much which was resulting in the slowdowns. I don’t use any remotes with the hub so I wasn’t able to catch that. I’ve also added a try except block to retry that timeout error you experienced.

I’ve removed the harmony component, harmony switch platform, and harmony sensor platform. Only the harmony remote platform remains. The file’s header includes a config example, automation example, and information on how add a template sensor to show the current activity if desired. The underlying pyharmony has also been updates to 1.0.7. Hopefully this works better!

Sample configuation.yaml entry:
remote:
  - platform: harmony
    name: Bedroom
    username: !secret username   (email addresse used to login to harmony website)
    password: !secret password   (password used to login to harmony website)
    host: 10.168.1.13            (Harmony device IP address)
    port: 5222                   (Harmony device port, 5222 is default)
    activity: BedroomTV          (activity to start if no activity is specified when turnon service is called, Optional)
  - platform: harmony
    name: Family Room
    username: !secret username
    password: !secret password
    host: 10.168.1.16
    port: 5222
    activity: Kodi

Configuration File
  Upon startup one file will be written to your HASS configuration directory per device in the following format:
    harmony_conf_REMOTENAME.txt.  The file will contain:
        A list of all programmed activity names and ID numbers
        A list of all programmed device names and ID numbers
        A list of all available commands per programmed device

Template sensors can be utilized to display current activity in the frontend by adding the following:
sensor:
  - platform: template
    sensors:
      family_room:
        value_template: '{{ states.remote.family_room.attributes.current_activity }}'
        friendly_name: 'Family Room'
      bedroom:
        value_template: '{{ states.remote.bedroom.attributes.current_activity }}'
        friendly_name: 'bedroom'

The remote's current activity can be utilized in automations as shown below.
    The example will turn on an input boolean switch on when the remote's state changes and the Kodi activity is started
    The second rule will turn off the same switch when the current activity is changed to PowerOff

automation:
- alias: "Watch TV started from harmony hub"
  trigger:
    platform: state
    entity_id: remote.family_room
  condition:
    condition: template
    value_template: '{{ trigger.to_state.attributes.current_activity == "Kodi" }}'
  action:
    service: input_boolean.turn_on
    entity_id: input_boolean.notify

- alias: "PowerOff started from harmony hub"
  trigger:
    platform: state
    entity_id: remote.family_room
  condition:
    condition: template
    value_template: '{{ trigger.to_state.attributes.current_activity == "PowerOff" }}'
  action:
    service: input_boolean.turn_off
    entity_id: input_boolean.notify

Supported services
  Turn Off:
    Turn off all devices that were switched on from the start of the current activity
  Turn On:
    Start an activity, will start the default activity from configuration.yaml if no activity is specified.
    The specified activity can either be the activity name or the activity ID from the configuration file written to
      your HASS config directory.  The service will respond faster if the activity ID is passed instead of the name
  Send Command:
    Send a command to one device, device ID and available commands are written to the configuration file at startup
  Sync:
    Syncs the Harmony device with the Harmony web service if any changes are made from the web portal or app

Updated and enabled the new remote component.

I’m not sure if I’m doing something wrong, or what, but after none of my activities would fire, I attempted to start an activity from the services screen and am receiving the error in the screenshot below. I’ve also attached a screenshot of the service call and my available activities from the harmonyConf.yaml.

Think your service call data needs to be

{"activity": "Watch DirecTV"}

I got my harmony hub. Will try to give this a go tonight.
Is it just this I need to install now? https://github.com/iandday/pyharmony/ (where does it go?)
And add your configuration examples?