That’s because the notify.xxx service supports templates (directly) in its message parameter, whereas remote.send_command does not support templates (directly) in its device parameter. However, you can still use templates for it in a service call from an automation or script (because scripting supports templates for any parameter via its data_template option):
@pnbruckner, hi and many thanks for your reply.
I used your code sample for testing (in order to understand better), and my automation now looks like this:
- id: '1551008851122'
alias: Test
trigger:
- entity_id: remote.harmony
platform: state
to: 'on'
action:
- service: remote.send_command
entity_id: remote.harmony
data:
command: Mute
data_template:
device: >
{% if is_state_attr('remote.harmony', 'current_activity', 'Apple-TV') %}
29903080
{% else %}
29038741
{% endif %}
The syntax seems OK as no errors are generated, but it does not work as expected. No matter what I type as current activity (i.e. Apple-TV) the test appears to always result in true, thus device 29903080 is muted - always.
Hmm, well then I can’t explain it. So are you sure you want to trigger the automation with the state of remote.harmony changing to ‘on’? Or do you want to trigger it when the current_activity attribute changes? (I don’t use this type of entity so I don’t know how it behaves.)
In any case, it would seem that whenever remote.harmony’s state changes to ‘on’ its current_activity attribute is equal to ‘Apple-TV’. That’s the only way to explain (that I can see at this point) why device is always 29903080.
@pnbruckner, Sir, I just discovered some important news (to me, at least); I actually have to restart HA everytime I make a change to the if-then-else statement in automations.yaml for it to recognize the change!
I had no idea! So, in fact it does work!
Still though, your comment about the trigger is very relevant. I had no idea what trigger to use, so I just chose ‘on’ in place of anything better. Now that I finally have an automation that works, it’s time to put it to good use. Any suggestions?
Depending on how you have your configuration laid out it might be possible to use one of the reload buttons on the general configuration page. But certainly restarting HA will definitely get it to read the config files again.
It all depends on what you’re ultimately trying to do, and how your remote.harmony entity behaves. Since I don’t use that it’s kind of hard for me to say. I’d suggest watching that entity to see how it changes in response to your usage. Then it should become obvious what trigger to use, etc. Without a lot more detail I’m not sure I can make any useful suggestions. But if you have any more specific questions, we’re always glad to try and help.