Event at start of Harmony activity?

Hi all,

Some weeks ago I switched over from using FHEM as my primary home automation system to HA (with a short stop at OpenHab) and never looked back so far.

However, there is one scenario, I could not yet fully cover in HA:

I am using a Harmony Elite remote (incl. hub). When I was using FHEM, at the start of each activity (e.g. “Watch TV”) a first event was reported by FHEM (“Starting activity ‘Watch TV’”), immediately after the respective button press. A second event (“Activity started ‘Watch TV’”) was sent after all of my devices have been turned on.

I have used this to make my devices completely powerless with a smart plug and turn on that smartplug once the first event (“Starting activity ‘Watch TV’”) was triggered by the remote.

If I interpret the home assistant logs and events correctly, HA only receives the second event (“Activity started ‘Watch TV’”), which is not suitable as a trigger for my scenario.

So the steps were as follows:

  1. Me pushing the button.
  2. Event Starting activity ‘Watch TV’
    –> My Ha automatically powering on my smart plug
  3. All devices being turned on by Harmony
  4. Event Activity started ‘Watch TV’

Is this really true or am I missing something? The event seems to be generated by the Harmony remote, because it is reported to FHEM. Is it really not visible in HA?

Many thanks for your ideas! I really love home assistant and this community and could solve all problems and tasks by my own.

Best regards
Oliver

Hi Oliver,

you’re right. There is no “Starting Activity”. My workaround looks like this. Not so smart like in Fhem but it works.

sensor:
  - platform: template
    sensors:
      harmony_activity:
        value_template: >
          {% if is_state("remote.harmony", 'on') %}
            {{ states.remote.harmony.attributes.current_activity }}
          {% else %}
            PowerOff
          {% endif %}

And my scripts.yaml

playstart:
  sequence:
  - service: media_player.turn_on
    entity_id: media_player.playstation_4
  - service: switch.turn_on
    entity_id: switch.toaster
  - delay:
      seconds: 5
  - service: remote.turn_on
    entity_id: remote.harmony
    data: 
      activity: 'playstation'

fernsehscript:
  sequence:
  - service: switch.turn_on
    entity_id: switch.toaster
  - service: remote.turn_on
    entity_id: remote.harmony
    data: 
      activity: 'Fernsehen'

playoff:
  sequence:
  - service: remote.turn_off
    entity_id: remote.harmony
  - service: media_player.turn_off
    entity_id: media_player.playstation_4
  - delay:
      # supports seconds, milliseconds, minutes, hours
      seconds: 10
  - service: switch.turn_off
    entity_id: switch.toaster

Maybe you can use it.

To make it work faster I’m rather checking the status of devices directly (e.g. media_player.denon) - status of harmony activity changes to on at the end of sequence, but some devices are on earlier… depends on what you want to achieve.

I have now solved this by integrating an Emulated Roku device to my Harmony activities. This gets started at the very beginning of the activity and I use its start to turn my smart plugs on. Works for now. However, I would really appreciate getting more events from Harmony.

The problem is that I want to use the start to turn on smart plugs. If the Denon has no power it makes no sense to check its status.

Thanks, Michael! This generally means that you take some logic out of the Harmony app and put them into HA. Good idea.

Problem with Harmony hub is that they only report activity to HA at the end of running the power-on sequence.

Would be nice to learn of a work-around. Perhaps an input-boolean entity that Harmony can change at its start of activity?
eg Configure this on Harmony:

  1. Turn on exposed entity in HA first
  2. wait 1s. HA turns on plugs, does other things
  3. Harmony do its normal activity sequence

My problem is: I’d turn on Shield TV activity, and then while it’s going through its sequence, I’d start chromecast. But my chromecast-start automation will fire, because its condition “harmony activity = powered off” was still true.
Unfortunately, I don’t have other networked devices in my old-ish media setup I can use to check :frowning:

As for power management, I got around this by using a dumb IR receiver plug, using it as it was intended for turning on TV. It gets linked to the TV power IR signal. I then tell Harmony to turn on TV twice and not power off when switching activity.

If FHEM can do it, Home Assistant should also be able to. This might depend on using XML or WebSocket mode. I am not sure what Home Assistant currently does but I remember them being different about activity events. Maybe @ehendrix has some insight?

FHEM offers this with WebSocket mode. I am not sure about XML.

The Hub sends out notifications when change of activity is being triggered. It will first still show the “current” activity as it is powering things off, and then the new activity as it is powering on. Once all completed it then notifies that starting activity is finished. Only once the starting activity is finished will it update what now the new activity is in HA.

Within HA WebSockets are used right now. There is a newer version of the module to allow both XMPP (Logitech supported method) and websockets (works but can break in the future). It prefers XMPP when enabled on the HUB and falls back to web sockets otherwise.
However there is currently an open issue with the XMPP library in HA that this then relies upon and until that is fixed the newer version of aioharmony can’t go in.
See https://github.com/home-assistant/home-assistant/issues/20860

Thanks. So it should indeed be possible to fire a Home Assistant event at the start of an activity change.

Yes. But would then need to be a configuration setting with the default being current behavior.

Would be best to be implemented with newer aioharmony version. For that however https://github.com/home-assistant/home-assistant/issues/20860 has to be resolved first.

I meant adding an actual event, I don’t think any configuration is needed for that.

But yeah, I can see that is one tricky issue :-/

Curious if this event was ever added. I used the “activity starting” even in homeseer (I actually wrote the plugin over there so I know it’s possible).

I don’t need a configuration to have it set the value an event would do and I actually prefer it. I have automations in homeseer that fire off both events based on the scenario.

I.e. turn on the living room TV and the ceiling fan immediately comes on. But turning it off it waits till the power off event to turn off any lights/fans.

I don’t mind chipping in on the code and may take a peep later when I’m at my computer.

So I just checked this. At least now in 2023, the ha devices value is changing on activity start, not on activity complete. If I had to chose between the two I would rather this option.

I just wanted to report back in case anyone else found this thread.

I also checked the events and there is an attribute called “activity_starting” that seems to change to the name of the starting activity and appears to go null when the activity is done. I think I can use this.

The docs should be update, but also having this as a specific event instead of having to depend on attribute changing would be nice. I will check out the integration and see if I can add that and submit a PR for consideration.