You should be able to use the event trigger. You may have to delay the action by 30s or so to ensure that pyharmony has pulled the current activity first, but that’s not a huge issue.
The dashes denote a list in yaml, so it’s telling home assistant to do more than one action for the single trigger. It does them in order so it’ll wait for 30 seconds then update the input_select.
you will need the change the input_select name and the homehub name. Based on your code it should be like this i think:
Yeah, I was just coming back to edit that I discovered this, and now it works! So the reason mine doesn’t have dashes is because it’s only the one action (the service call) and the other items are just arguments for that action?
(Next step is going to be to redo these using the templating code. :))
Yeah, that’s correct. The trigger and condition dictate when the automation is started and the action part is what happens after. The action section is basically the same as a script.
I have strange but reproducible side-effects using your script and automation examples. My Harmony Ultimate remote now (after configuring it in HASS) often performs synchronization without apparent reason, does not enter screensaver after changing activities, starts a single device after PowerOff activity etc.
Has someone had similar problems?
As soon as I remove the ‘Remote external update living room’ automation from your example, the Harmony (outside of HASS) works as expected again.
Maybe my Hub is unable to cope with two activity commands at the same time:
When I hit the PowerOff button on the actual Ultimate remote, the HASS remote component state is updated. Then the ‘Remote external update living room’ automation sets the new value in the input select and the ‘Remote start activity from input select living room tv’ automation immediately triggers the very same activity as received from the state update (which might still be in progress)…?
I wondered about that as I was reading this. My first thought was to put a condition on the update automation so that it doesn’t send the command to the Harmony unless the new state (from the input_select) is different than the current state (from the remote). I haven’t actually tested that yet, but I’m guessing it should be possible.
I have been trying to set this new component up but it is not working correctly so looking for some help. The input select is displayed in the UI with all activities but they do not update when changing an activity on the remote and also do not change the activity if I select the activity from the HA input select. Here is my config.
configuration.yaml
remote:
- platform: harmony
name: Living Room Hub
host: 192.168.1.xxx
port: 5222
activity: Watch TV
input_select:
harmony_remote:
name: Harmony Remote
options:
- PowerOff
- Watch Amazon
- Watch Plex
- Watch Smart TV
- Watch DVD
- Watch PC
- Watch TV
initial: PowerOff
icon: mdi:television
- alias: 'Remote external update living room'
trigger:
platform: state
entity_id: remote.living_room_hub
action:
- service: input_select.select_option
data_template:
entity_id: input_select.living_room_hub
option: >
{{ states.remote.living_room_hub.attributes.current_activity }}
- alias: 'Remote start activity from input select living room hub'
trigger:
platform: state
entity_id: input_select.living_room_hub
action:
- service: script.turn_on
entity_id: script.input_select_harmony
I am seeing the following error in the log if this helps
18:55:38 homeassistant.components.sensor.template: UndefinedError: ‘None’ has no attribute ‘attributes’
Tried adding a condition to the script. But from the HASS log I can see it is still executed if I switch activities from the Ultimate. The problem with my PS3 switched on when I PowerOff still persists…
Thanks @mrtips sometimes you can’t see the obvious so appreciate your help with this. It is working OK now on an initial test but I will test some more later. Many thanks.
No worries, I actually did the same thing with the script part of the config and scratched my head for a day before seeing it.
Setting this up is actually non-trivial, could be good to have the default component make all the activities available as individual switches. I wonder if that’s possible, @iandday may know?
Perhaps that’ll be my Christmas project and first home assistant pull request if people think it would be a good idea?
Is there anything else on your network that can interact with the harmony hub or is it just HASS and the hub? This sounds like a feedback loop.
Also try putting the condition on the ‘Remote start activity from input select’ automation rather then the script itself so the script never gets launched if the input select is the same as the current activity.
It’s completely possible, during component setup you can loop through the list of detected activities and create a switch for each one. I didn’t want to clutter up the front-end with a large number of switches when they might not all be used. It’s on my to-do list and to create a variable that will be placed in the harmony section of the config.yaml to control if the individual switches are created
I moved the condition to the automation. And then I found an error in my condition… I compared to the input_select state object instead of the state string. Here is the correct condition:
Now my strange behaviors disappeared. All working as expected. So if someone else also encounters problems, here is the complete automation (as per iandday’s example) including the condition suppressing the feedback loop:
- alias: 'Remote start activity from input select living room tv'
trigger:
platform: state
entity_id: input_select.living_room_tv
condition:
condition: template
value_template: '{{ states.remote.living_room_tv.attributes.current_activity != states.input_select.living_room_tv.state }}'
action:
service: script.turn_on
entity_id: script.input_select_harmony
I had feedback loop issues on my RPi3 with the auto-correcting input_select and ended up going another route. Here’s what I have:
The majority of the code is the same, but rather than trying to correct the input_select anytime it changes, I instead directly display the current activity using a template sensor and have the input_select revert to Select Input after sending the start activity command to the harmony hub.
Be aware that that code will only work if your input select state names are identical to your harmony remote activity names. If you customise them you will have to do a bit more logic in that template.