I have an interesting situation and was hoping someone could help out here. I use a harmony remote but also use voice controls and a chromecast. My wife also uses the TV and the cable remote. The issue I was having was that the harmony remote would go out of sync due to all the other HDMI CEC (alexa for fire tv and chromecast controls) and my wife using other remotes. I got into Home Assistant to try to solve this issue.
In Home Assistant, I have created activities to set the harmony remote’s activity based on a state change of the TV’s (LG OLED C8) input e.g. if the TV input is changed to Xbox, then change the harmony’s remote activity to “Play Xbox”. This way, the Harmony remote doesn’t go out of sync. If I tell Alexa to play Ozark, the TV’s input changes to “Fire TV” and HomeAssistant runs an automation to turn on the Harmony remote’s “Watch Fire TV” activity.
It almost works fine. However, the BIG issue is I run into loops. As an example, if the TV’s last input before it got turned off was the Xbox and I use Alexa to play a show on the Fire TV,
The TV first turns on on its last input (“Xbox”)
The TV then switches to the “Fire TV”
The initial automation for the Xbox input then runs and turns on the “Play Xbox” activity on Harmony remote which switches the TV back to the Xbox input
The automation for the Fire TV input runs and turns on the “Watch Fire TV” activity on Harmony remote which switches the TV back to the Fire TV input
Steps 3 and 4 continue indefinitely
Also, the same effect occurs when we switch inputs between the time the automation is triggered and when it actually runs. I added delay conditions to the “trigger” component of the automation try to remedy this i.e. only run automation if TV has been on input for x seconds. However, that has 2 issues: a) if input is switched just after the delay but before automation is done running, the loop still occurs; b) if delay is too long, i can’t use harmony remote for a while till automation triggers.
The big issue is really that there’s a lag between when the automation is triggered and when it’s run. Does anyone have a better way to prevent this loop? I’m trying to prevent home assistant from running an automation if the TV input has changed from the input that triggered the automation.
The method above didn’t fix the issue. Please I’d love to hear suggestions if anyone has any.
Essentially, the problem is that during the time it takes for the automation (harmony activity) to run, the TV input might have changed and that ends up causing a loop. I thought about adding a condition in the “action” part of the automation to ensure the TV input is still the same input that caused the trigger before the trigger is completed but thinking about it, that is likely to also have issues. If it says it’s the same input but the input gets changed right after the condition is validated, I’d think the same issue would occur.
I solved this issue by programming the harmony remote to do everything, using voice commands to access the activities instead of individual devices, and hiding all the other remotes from my wife forcing her to learn the extremely easy to use harmony remote. We pretty much only use voice commands at this point, but it’s always an activity. And my wife now uses and learned the remote.
Thanks but there are some really cool voice commands that the Harmony can’t handle. Perfect example is “Alexa, watch Friends” and having the TV switch to the Fire TV input and start playing Friends where we stopped. Essentially, any form of searching is where the Harmony remote would be limited.
Thanks. I think I found Home Assistant from a post by you on Reddit actually detailing what you were doing with Chromecast!
I’m doing the exact same thing with the Chromecast actually. The Fire TV has similar states but they’re very unreliable. Most of the time, it’s actually in an “unknown” state.
I do use ARC and my TV has lossy Atmos with ARC so don’t plan to disable CEC.
So I noticed that the delay I was using was applied to the “trigger” i.e. trigger: - for: 8s. Now I’m thinking I should instead do
service: start Harmony activity
This way, it would wait about 10s after the input changes to see if the input has been on the new input for up to 8s before turning in the Harmony activity. I think this might prevent race conditions or at least, reduce the occurrence.
Right, thats great. I similar things. I have a routine that starts the harmony activity and I use other automation techniques via the harmony remote & home assistant that resume at that state.
I also use similar automations as @a3a, but with my receiver and harmony commands. Even with my current setup, the source is sometimes incorrectly selected and my automations correct that. The big takeaway here is that I always have the harmony activity start first. Otherwise you will get into an endless loop.
I guess the first thing I need to ask is, how are you setting your harmony activities in HA?
Well yes, but what are you using to detect the change in activity? an automation? a series of switches? A input select? I have an idea that I want to throw by but I need a little more input. If you aren’t detecting at all, then even better.
I’m using a state change in the input of the TV. I made the input a virtual device and every time the input changes, it starts an activity. An example is if the input state changes to HDMI2, it starts the “Watch For TV” activity. The only exception to this is with the Chromecast. For that, I’m using a state change to “playing” of the Chromecast itself.
So essentially, whenever there’s an input change to “Xbox”, if the input is still on “Xbox” 8s later, it turns on the “Watch Xbox” activity.
I’ve also toyed with:
- id: '1540083738053'
alias: Harmony Tivo
- entity_id: sensor.lg_tv_source
- delay: 00:00:08
- condition: state
Seems I’m doing the same thing. The issue is that if the TV’s input is changed after 8s but before the “Watch Xbox” activity is completed, I get into the loop. As an example, if everything is off and I tell Alexa to “Watch Bosch”,
My Fire TV would turn the TV on through HDMI-CEC
Initially, the TV’s input would be on whatever the last input was (let’s imagine that’s TiVo)
If it takes more than 8s to switch to the Fire TV’s input through but less than the time the harmony activity is completed:
a) The “Harmony Tivo” HA trigger would activate
b) The TV’s input would switch to “Fire TV Input”
c) The “Watch Tivo” Harmony activity would then complete and switch the TV back to the Tivo input
d) The “Harmony Fire TV” HA trigger would then activate (this is really because it takes Harmony a while to complete especially after starting from power off)
e) The “Watch Fire TV” Harmony activity would then complete and switch the TV back to the Fire TV input
f) Once again, if it takes more than 8s for Harmony to switch to “Fire TV” input, “Harmony Tivo” HA would trigger and say, we were on Tivo for more than 8s
g) “Watch Tivo” Harmony activity would run and switch back to the “Tivo” input
Typing it all out, it does appear the loop is caused because the delay I’m giving isn’t enough time for the Harmony Activity to get completed. Maybe if I made it 20s, I won’t run into this loop. Of course, I could still have issues of someone picking up the remote and changing the input right after 20s but before the harmony activity has been completed so the input of the TV changing back on them to the previous input but that’d be a less frequent issue and shouldn’t result in a loop.
Thanks. So this would ensure that before it changes to an activity, it’s not already on that activity. Harmony has a built-in check for that so I’m not sure it makes a difference i.e. if you call “Watch Tivo” when the Harmony is already on “Watch Tivo”, the Harmony remote simply ignores the request.