Been at this for a while and can’t figure it out. It’s supposed to turn off all other input booleans then the one that was just turned on but it only works for the first two statements and the rest have zero effect on each other.
FWIW, the reason it didn’t work is because an if ... elif ... else statement will only pick one case, the first one that is true. You would need individual if statements, but that really won’t work because of the way templates and the entity_id parameter work.
Your first solution worked perfectly, I tried the second one but it would break functionality and in a pattern I couldn’t quite figure out. Also thanks for explaining why it didn’t work. I saw other examples of long If statements but didn’t think about that.
While I have your attention is there a way to use something like this
{{expand('group.tv_inputs') | map(attribute='entity_id') | list }}
It should be equivalent to the first. It uses the select filter to “pass through” only the elements of the list that are not equal (ne) to trigger.entity_id, then joins the elements of the resulting list using the string ',' using the join filter. It should work the same, but be a little more efficient, than the first solution.
But it’s really a question of style, so whichever you prefer.
You can’t use the expand function because it results in a list of State Objects, not entity_id’s. But you could do:
{% set l = state_attr('group.tv_inputs', 'entity_id') %}
Yeah, it just seems like you’re trying to make ‘radio’ buttons. I.E. Buttons that are on, but all other paired buttons are off.
And if this is the case, I recommend investigating template switches because you won’t be running into goofy issues. For example, if you attempt to use these booleans to turn on and off a harmony activity, you will run into circular feedback. You’ll attempt to turn on activity A which will turn off all the other activities. So then you send to your remote a turn on a, but also turn off b, c, d, e, etc. This causes all sorts of problems for the harmony.
That’s a good point. All of this is really just to get HaDashboard buttons that show what is and isn’t on currently. If there is a better way to do that I’d love to hear it
But if I don’t attach the off function of the harmony to the input_boolean I shouldn’t run into that issue right?
Yep, you are correct. But you could always just make a template switch for each activity. Each switch will work for on and off, and all the other switches will react.
No automation, all done in a single switch. Shows up as a single toggle in the UI.
EDIT: How it works:
Turning the switch on will call the turn_on service. Turning the switch off will call the turn_off service. The state that is displayed in the UI does not reflect you pressing on or off, it reflects the state of harmony. So if harmony’s current activity is equal to the activity in question, the switch will appear on. Therefore you won’t get a feedback loop like you would with input booleans. You also don’t need the automation in this thread.
Interesting I was looking at switches before I jumped into this, I am using scripts to augment the harmony and do a few extra things. I never really liked the Harmony interface for delays and triggering other things.
That might not be the best way of doing things.
It’s good to see things like this as I’m just starting out. There’s so many ways to do things in HA I’m constantly learning something that makes me rethink things I’ve already done.