I’m trying to build a sensor that will check the status of several input booleans. If any of them are on, the sensor should return true.
I’ve never really done any programming or coding before, so please forgive my butchery of this code. I’m trying here to insert my (likely flawed) understanding of the required logic in the context of the value_template… So does the below make sense as to what I’m trying to achieve?
should_receiver_be_on:
friendly_name: "Should Reciever Be On?"
value_template: '{{ states.input_boolean.appletv OR states.input_boolean.nintendo_switch OR states.input_boolean.nintendo_wiiu OR states.input_boolean.nintendo_switch | ARE ON? }}'
and if this does make sense, could anyone please help get the logic & syntax right?
Wow thanks for the super fast reply Adam. I really appreciate how you provided a couple potentially simpler approaches before giving a specific answer to my problem. I posted this after a long evening trying to get this and several other parts of my system up and running, so I need to take myself to bed now. I’ll have a go at implementing your automation suggestion tomorrow. For now, I just wanted to say thanks for the help.
Other than ask question on here, what would I type in a search engine to learn more about examples like this please i.e. what language is this? I’m not looking to get to the level of understanding the likes of you , Petro etc have, I’m guessing you’ve all studied this for a long time. I’m just interested to expand the art of the possible.
Jinja is a fast, expressive, extensible templating engine. Special placeholders in the template allow writing code similar to Python syntax. Then the template is passed data to render the final document.
No I don’t think so because the if the first condition is True the the template just skips past the other input_booleans and evaluates to True, it doesn’t even listen to the others. However, if the first is False, it listens to that input_boolean and every subsequent one until it finds a condition that is True.
I love how the Template editor shows you what entities are being listened to now! Very helpful.
no, if anyone of them are on it would be true. If all of them are on jinja would evaluate the first statement and exit before even checking the others.
Thank you all so much, I was just able to get great functionality working using groups of input booleans. There was a little bit of frustration where I’d used capitalisation on “On” and “Off” and I spent way too long figuring out that was my error, but I got there I the end.
Now I have a nice setup where all I need to do is choose an input source and all my other home theatre equipment (projector and receiver) will turn on with the right source selected. This is all done via IR on a Broadlink RM Mini 3. When I choose a different input source in my group, the setup knows to leave the projector and receiver on. Those components only turn off if the whole group is off.
The only annoying thing is that when everything is off, hitting the group switch does awful awful things because it turns everything on, triggering a whole lot of nasty. Does anyone know if there’s a way to dictate which input booleans are turned on by default when a group is activated?
Yes, I’d take a completely different approach. Make template switches instead of automations. Seeing as this is like harmony activities, only 1 can be on at a time, make an input_select.
input_select
input_select:
rm_mini:
name: Current Activity
initial: 'Off'
options:
- Apple TV
- Wii U
- PlayStation
- Nintendo Switch
- 'Off'
So basically, you’ll end up with switches that you use for the UI. The value_template for the switch will determine if the switch is on or off. So you don’t need to keep the other switches in sync by turning them off. They’ll turn off based on the value_template returning true or false, which is updated when the input_select changes.
Oh wow, this sounds cool petro, I’ll take a crack at fully understanding and implementing your solution tomorrow. Thanks for taking a bit of a deeper dive into this with me. I’ll let you know how I go. Also, thanks again Adam for your help too
Hey Petro, I just wanted to extend a huge thank you for your ideas here. This is really helpful stuff, and turns out to be perfect for my situation, so again, Thanks