Speed up trigger on Harmony

Hi there,
I am currently in the middle of switching over from FHEM to Home Assistant and currently working on “porting” my Harmony Hub related automations.

I have a few automations that react on certain activities being started on the hub and I notice that in HA there is a noticable delay of around 14 seconds before the trigger (new activity) is recognized.

I looked into the log (attached below) and saw, that immediately after starting the activity via the Harmony remote [2020-05-05 16:01:18], there is action registered by HA and written to the log, but only after said 14 seconds at [2020-05-05 16:01:32], the activity is noted as changed.

Would it be possible to trigger on that earlier event somehow?

In FHEM the harmony state would first change to “starting ActivityX” immediately after pressing the Harmony remote and then to “ActivityX” after a while (probably those 14 seconds). So I would always trigger on the “starting *” state to be early in the game. But I guess to make these intermediate states available to HA would require work on aioharmony module, right?

2020-05-05 16:01:18 DEBUG (MainThread) [aioharmony.hubconnector] 192.168.178.42: Response payload: {"type":"control.button?pressType","data":{"type":"short"}}
2020-05-05 16:01:18 DEBUG (MainThread) [aioharmony.responsehandler] Message received: {'type': 'control.button?pressType', 'data': {'type': 'short'}}
2020-05-05 16:01:18 DEBUG (MainThread) [aioharmony.responsehandler] No match for handler Activity_Changed
2020-05-05 16:01:18 DEBUG (MainThread) [aioharmony.responsehandler] No match for handler Notification_Received
2020-05-05 16:01:18 DEBUG (MainThread) [aioharmony.responsehandler] Checking for expired handlers
2020-05-05 16:01:18 DEBUG (MainThread) [aioharmony.hubconnector] 192.168.178.42: Response payload: {"type":"connect.stateDigest?notify","data":{"sleepTimerId":-1,"runningZoneList":[],"discoveryServerCF":"https:\/\/cf-svcs.myharmony.com\/Discovery\/Discovery.svc","activityId":"38774311","syncStatus":0,"time":1588678861,"stateVersion":445,"tzOffset":"7200","mode":3,"contentVersion":92,"hubSwVersion":"4.15.264","deviceSetupState":[],"tzoffset":"7200","isSetupComplete":true,"sequence":false,"configVersion":320,"discoveryServer":"http:\/\/svcs.myharmony.com\/Discovery\/Discovery.svc","activitySetupState":false,"activityStatus":1,"wifiStatus":1,"tz":"CET-1CEST,M3.4.0,M10.4.0\/3","runningActivityList":"","IPIRConversionDate":"2019-06-23T17:58:50.299Z","hubUpdate":false,"updates":{"97":"4.13.100"},"accountId":"xxxxxxx"}}
2020-05-05 16:01:18 DEBUG (MainThread) [aioharmony.responsehandler] Message received: {'type': 'connect.stateDigest?notify', 'data': {'sleepTimerId': -1, 'runningZoneList': [], 'discoveryServerCF': 'https://cf-svcs.myharmony.com/Discovery/Discovery.svc', 'activityId': '38774311', 'syncStatus': 0, 'time': 1588678861, 'stateVersion': 445, 'tzOffset': '7200', 'mode': 3, 'contentVersion': 92, 'hubSwVersion': '4.15.264', 'deviceSetupState': [], 'tzoffset': '7200', 'isSetupComplete': True, 'sequence': False, 'configVersion': 320, 'discoveryServer': 'http://svcs.myharmony.com/Discovery/Discovery.svc', 'activitySetupState': False, 'activityStatus': 1, 'wifiStatus': 1, 'tz': 'CET-1CEST,M3.4.0,M10.4.0/3', 'runningActivityList': '', 'IPIRConversionDate': '2019-06-23T17:58:50.299Z', 'hubUpdate': False, 'updates': {'97': '4.13.100'}, 'accountId': 'xxxxxxx'}}
2020-05-05 16:01:18 DEBUG (MainThread) [aioharmony.responsehandler] No match for handler Activity_Changed
2020-05-05 16:01:18 DEBUG (MainThread) [aioharmony.responsehandler] Match for Notification_Received
2020-05-05 16:01:18 DEBUG (MainThread) [aioharmony.helpers] Scheduling coroutine Notification_Received with UUID 37b0f8d3-ff0e-494c-be43-26be55f7adb7
2020-05-05 16:01:18 DEBUG (MainThread) [aioharmony.responsehandler] Checking for expired handlers
2020-05-05 16:01:18 DEBUG (MainThread) [aioharmony.harmonyclient] 192.168.178.42: Notification was received
2020-05-05 16:01:32 DEBUG (MainThread) [aioharmony.hubconnector] 192.168.178.42: Response payload: {"type":"connect.stateDigest?notify","data":{"sleepTimerId":-1,"runningZoneList":[],"discoveryServerCF":"https:\/\/cf-svcs.myharmony.com\/Discovery\/Discovery.svc","activityId":"38774311","syncStatus":0,"time":1588678861,"stateVersion":446,"tzOffset":"7200","mode":3,"contentVersion":92,"hubSwVersion":"4.15.264","deviceSetupState":[],"tzoffset":"7200","isSetupComplete":true,"sequence":false,"configVersion":320,"discoveryServer":"http:\/\/svcs.myharmony.com\/Discovery\/Discovery.svc","activitySetupState":false,"activityStatus":2,"wifiStatus":1,"tz":"CET-1CEST,M3.4.0,M10.4.0\/3","runningActivityList":"","IPIRConversionDate":"2019-06-23T17:58:50.299Z","hubUpdate":false,"updates":{"97":"4.13.100"},"accountId":"xxxxxxx"}}
2020-05-05 16:01:32 DEBUG (MainThread) [aioharmony.responsehandler] Message received: {'type': 'connect.stateDigest?notify', 'data': {'sleepTimerId': -1, 'runningZoneList': [], 'discoveryServerCF': 'https://cf-svcs.myharmony.com/Discovery/Discovery.svc', 'activityId': '38774311', 'syncStatus': 0, 'time': 1588678861, 'stateVersion': 446, 'tzOffset': '7200', 'mode': 3, 'contentVersion': 92, 'hubSwVersion': '4.15.264', 'deviceSetupState': [], 'tzoffset': '7200', 'isSetupComplete': True, 'sequence': False, 'configVersion': 320, 'discoveryServer': 'http://svcs.myharmony.com/Discovery/Discovery.svc', 'activitySetupState': False, 'activityStatus': 2, 'wifiStatus': 1, 'tz': 'CET-1CEST,M3.4.0,M10.4.0/3', 'runningActivityList': '', 'IPIRConversionDate': '2019-06-23T17:58:50.299Z', 'hubUpdate': False, 'updates': {'97': '4.13.100'}, 'accountId': 'xxxxxxx'}}
2020-05-05 16:01:32 DEBUG (MainThread) [aioharmony.responsehandler] No match for handler Activity_Changed
2020-05-05 16:01:32 DEBUG (MainThread) [aioharmony.responsehandler] Match for Notification_Received
2020-05-05 16:01:32 DEBUG (MainThread) [aioharmony.helpers] Scheduling coroutine Notification_Received with UUID 37b0f8d3-ff0e-494c-be43-26be55f7adb7
2020-05-05 16:01:32 DEBUG (MainThread) [aioharmony.responsehandler] Checking for expired handlers
2020-05-05 16:01:32 DEBUG (MainThread) [aioharmony.harmonyclient] 192.168.178.42: Notification was received
2020-05-05 16:01:32 DEBUG (MainThread) [aioharmony.hubconnector] 192.168.178.42: Response payload: {"type":"harmony.engine?startActivityFinished","data":{"activityId":"38774311","errorCode":"200","errorString":"OK"}}
2020-05-05 16:01:32 DEBUG (MainThread) [aioharmony.responsehandler] Message received: {'type': 'harmony.engine?startActivityFinished', 'data': {'activityId': '38774311', 'errorCode': '200', 'errorString': 'OK'}}
2020-05-05 16:01:32 DEBUG (MainThread) [aioharmony.responsehandler] Match for Activity_Changed
2020-05-05 16:01:32 DEBUG (MainThread) [aioharmony.responsehandler] No match for handler Notification_Received
2020-05-05 16:01:32 DEBUG (MainThread) [aioharmony.helpers] Scheduling coroutine Activity_Changed with UUID fddda0e0-4eb7-4a97-bd1c-684d0cccaa65
2020-05-05 16:01:32 DEBUG (MainThread) [aioharmony.responsehandler] Checking for expired handlers
2020-05-05 16:01:32 DEBUG (MainThread) [aioharmony.harmonyclient] 192.168.178.42: New activity was started
2020-05-05 16:01:32 DEBUG (MainThread) [aioharmony.harmonyclient] 192.168.178.42: New activity: AndroidTV(38774311)
2020-05-05 16:01:32 DEBUG (MainThread) [aioharmony.helpers] Calling callback new_activity_callback with UUID 192.168.178.42

2020-05-05 16:01:32 DEBUG (MainThread) [homeassistant.components.harmony.remote] Harmony: activity reported as: AndroidTV

2020-05-05 16:01:32 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=remote.harmony, old_state=<state remote.harmony=off; current_activity=PowerOff, friendly_name=Harmony, supported_features=0 @ 2020-05-05T16:00:39.249069+02:00>, new_state=<state remote.harmony=on; current_activity=AndroidTV, friendly_name=Harmony, supported_features=0 @ 2020-05-05T16:01:32.844119+02:00>>
2020-05-05 16:01:32 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.34642463696] Sending {'id': 2, 'type': 'event', 'event': <Event state_changed[L]: entity_id=remote.harmony, old_state=<state remote.harmony=off; current_activity=PowerOff, friendly_name=Harmony, supported_features=0 @ 2020-05-05T16:00:39.249069+02:00>, new_state=<state remote.harmony=on; current_activity=AndroidTV, friendly_name=Harmony, supported_features=0 @ 2020-05-05T16:01:32.844119+02:00>>}
2020-05-05 16:01:32 DEBUG (MainThread) [aioharmony.hubconnector] 192.168.178.42: Response payload: {"type":"connect.stateDigest?notify","data":{"sleepTimerId":-1,"runningZoneList":[],"discoveryServerCF":"https:\/\/cf-svcs.myharmony.com\/Discovery\/Discovery.svc","activityId":"38774311","syncStatus":0,"time":1588678861,"stateVersion":447,"tzOffset":"7200","mode":3,"contentVersion":92,"hubSwVersion":"4.15.264","deviceSetupState":[],"tzoffset":"7200","isSetupComplete":true,"sequence":false,"configVersion":320,"discoveryServer":"http:\/\/svcs.myharmony.com\/Discovery\/Discovery.svc","activitySetupState":false,"activityStatus":2,"wifiStatus":1,"tz":"CET-1CEST,M3.4.0,M10.4.0\/3","runningActivityList":"38774311","IPIRConversionDate":"2019-06-23T17:58:50.299Z","hubUpdate":false,"updates":{"97":"4.13.100"},"accountId":"xxxxxxx"}}
2020-05-05 16:01:32 DEBUG (MainThread) [aioharmony.responsehandler] Message received: {'type': 'connect.stateDigest?notify', 'data': {'sleepTimerId': -1, 'runningZoneList': [], 'discoveryServerCF': 'https://cf-svcs.myharmony.com/Discovery/Discovery.svc', 'activityId': '38774311', 'syncStatus': 0, 'time': 1588678861, 'stateVersion': 447, 'tzOffset': '7200', 'mode': 3, 'contentVersion': 92, 'hubSwVersion': '4.15.264', 'deviceSetupState': [], 'tzoffset': '7200', 'isSetupComplete': True, 'sequence': False, 'configVersion': 320, 'discoveryServer': 'http://svcs.myharmony.com/Discovery/Discovery.svc', 'activitySetupState': False, 'activityStatus': 2, 'wifiStatus': 1, 'tz': 'CET-1CEST,M3.4.0,M10.4.0/3', 'runningActivityList': '38774311', 'IPIRConversionDate': '2019-06-23T17:58:50.299Z', 'hubUpdate': False, 'updates': {'97': '4.13.100'}, 'accountId': 'xxxxxxx'}}
2020-05-05 16:01:32 DEBUG (MainThread) [aioharmony.responsehandler] No match for handler Activity_Changed
2020-05-05 16:01:32 DEBUG (MainThread) [aioharmony.responsehandler] Match for Notification_Received
2020-05-05 16:01:32 DEBUG (MainThread) [aioharmony.helpers] Scheduling coroutine Notification_Received with UUID 37b0f8d3-ff0e-494c-be43-26be55f7adb7
2020-05-05 16:01:32 DEBUG (MainThread) [aioharmony.responsehandler] Checking for expired handlers
2020-05-05 16:01:32 DEBUG (MainThread) [aioharmony.harmonyclient] 192.168.178.42: Notification was received

I was able to achieve the desired result by making changes to aioharmony. In case anybody is interested, here’s the pull-request: https://github.com/ehendrix23/aioharmony/pull/15

However as this is propably not the least intrusive way, I’d still be interested in a way of achieving this purely within HA.

If you want to purely do this in HA, you’d have to make a template switch for the activity and sync it with an input boolean. Also, you’d have to make an automation that toggles the input boolean based on the state of the current activity. Or have the integration keep a current activity in sync with the currently selected activity when the service is called.

Mine are instant using Harmony to trigger them directly rather than relying on HA watching for a status change.

Use Emulated Roku to create the link between the two, add a start up function to the activity in Harmony and then set the response to that in HA to trigger a script or toggle an input boolean and use the status change in that to trigger the automation.

I think I kind of understand what you mean, but I don’t fully understand how to read the state of the current activity, if HA only recognizes it when activityStatus changes to 2.

Ah! That sounds like a great plan!
However that means adding a new device to each of my activities via the harmony app …
Since my love for the harmony app is not exactly overwhelming, I’ll do this as soon as an update to aioharmony breaks my hack :slight_smile:

you have to think of it from the HA standpoint, not aioharmony.

In home assistant, there’s an attribute called current activity on the remote.

Do you also have a roku? I do, and wondering if it’s worth the hassle of setting up this process if harmony can only handle 1 roku.

Although, I could do this through emulated_hue.

Yes, but unfortunately current activity only changes after 14 seconds (when aioharmony reads activityStatus == 2).

The 14 seconds is probably the time that all the different actions in my activity startup take.

I would like to see from within HA that an activity is starting as soon as possible. The emulated_heroku / emulated_hue seems like the perfect solution!

for as smart as harmony is, it’s api is 100% shit. The fact that you can’t get a current activities device list is baffling.

Right, you aren’t understanding what I’m saying.

You yourself maintain a current activity. When you call the service to change the activity, you set both YOUR activity and harmonys activity.

Also, you need an automation that updates YOUR activity when harmonys activity changes.

Then you monitor YOUR activity only. You’ll have instant changes.

Adding a new device to an existing activity takes seconds using the desktop app rather than the rubbish mobile one.

Just run ‘Change your settings’, pick the new device and keep clicking next until done as it will keep everything you had previously. Then go to ‘Customize this activity’ and add the trigger.

Honestly, it’s so easy.

:rofl:

NOW I got you!
However this doesn’t help if I start the activity via the original remote, does it? Not unless I use emulated_watchamacallit

Correct. It does not. @Bobby_Nobble’s solution seems like it will.

1 Like

I don’t but Emulated Roku is not seen as a Roku to anything but Harmony and you can add multiples if you run out of buttons.

I used to use Emulated Hue as you mention but when Emulated Roku was created as a custom component ages ago I haven’t looked back, both for direct light and fan control etc from the remote buttons as well as triggering other scripts in HA as part of Activity startup/shutdown like the OP wants to do.

It’s very useful for adding functional play/pause buttons on the remote for a Chromecast and making a FireTV change to specific apps eg ‘Play Netflix’ activity does literally that using the ADB addon.

Yeah, I have alot of that setup without harmony but I have a few ‘holes’. I’ll see if harmony can accept a second roku later today. Seems like an easy fix. No way I’ll use emulated hue, it just doesn’t work well. Mainly because it’s an undocumented reverse engineered api where as roku’s api is well documented.

It definitely will unless you’ve hit the max number of devices, remember to ‘Scan for devices’ not ‘Add device’.

Just found that it won’t run on linux using wine…

However thanks to the both of you for the help and I will definitely setup that emulated_heroku in the future. Sounds very useful!

1 Like

Bummer, explains your hatred of setting it up.