Some years back, I created the below Automation. Ultimately what I want to know… Is there a more effective, or better HA way to set this up? Is using input_select ‘appropriate’ in this case, or should I be using template & variables to accomplish this?
The Q really popped up when I wanted to generate and see on my dashboard, the status of my computer, ie. locked or unlocked. Adding this (see attached) simply creates a dropdown box. I understand this is appropriate for the type of Helper it is, making me wonder, should I not be using input_select in this manner?
The time to use any Input helper is when you want/need to have user input directly alter the state of the entity. If the state of the entity is really being decided by non-user events or states of other entities and you do not require the ability to manually override it*, then a template sensor seems more appropriate.
*With trigger-based template sensors manual override is actually still possible, just a little more complicated to set up.
The reason I went this direction initially was then I could use result in other automations, scripts, etc. Can I do the same with templates, or do I need to create this as a Condition in every one?
I would like to use variables of sort, ie. set ‘home’ as a conditional variable in a scene… If home then execute, otherwise ignore.
Can you clarify what you mean by “conditional variable” in a scene? I am unaware of any type of global variable or conditional logic available in scenes.
Since you have not posted an example, I’m assuming in scripts and automations you are currently using something like:
- condition: state
entity_id: input_select.home
state: "home"
A template sensor would be used the same way
- condition: state
entity_id: sensor.home
state: "home"
However, if you have person entities defined for all your people, you don’t actually need any supplementary entities (including the group) for triggers or conditions… you can just use the state of zone.home since the state of a zone is the number of person entities in that zone based on their assigned device trackers.
Wow, thank you. I never really have understood some of this. With regards to the variable in a scene, I was simply referring to how you presented the state/condition. Again, thanks!
You use a trigger-based template sensor. As a basic example, the following would create a sensor that tracks whether anyone is home based on the zone integration, but allows manual override by raising a custom event.
The template editor tool is only for testing templates and does not work with trigger-based templates, since there is no trigger for it to listen for. To create the sensor, you need to place the sensor configuration in your configuration.yaml file then reload the configuration.
When I add this to an Automation, why is it that binary_sensor.home_occupied is not listed as a State to select in a Condition? Do I need to separately create the actual sensor?