Take a look here, especially the warning. state_attr(…) is better, because it doesn’t cause errors on startup when an entity is not available.
For the example you posted, can use is_state_attr(…)
{% if is_state_attr('remote.logitech_harmony', 'current_activity', 'PowerOff' %}
Personally I’d rewrite your automation and use a variable for the current_activity attribute and then check this variable for the possible states instead of repeating is_state_attr(…)
thank you for the rewrite. I will update it. in meanwhile I was testing my new part.
And thanks for the link, lots of info that makes more sense to understand things also!
it will be like this… you start with ( but there was no ) at the end
{% if is_state_attr('remote.logitech_harmony', 'current_activity', 'PowerOff') %}
I had the first line. You rewrite it to the second.
{% if state_attr('remote.logitech_harmony','current_activity') == "PowerOff" %}
{% if is_state_attr('remote.logitech_harmony', 'current_activity', 'PowerOff' %}
I can’t check out what different is. Output is same. Is there a reason to use the second line?
Better coding, or other reasons?
I have lot of lines like the first one, and if its better to change them also then I have something to do in my second Xmas Day haha
There’s no difference between these two methods, I just find the second one cleaner and it was created to exactly cover this use case.
You can leave it as it is,in the end of the day that’s more about preferwnce and readability,you need to maintain your code not me, so it has to be the way that is most convenient for you.