Problem: Choose always takes the same route, even if the conditions are not met. What I am trying to do: I want an automation to perform different actions based on if another automation is running What I have tried:
Extracting attribute state from configuration.yaml and using a choose for that binary attribute based on whether it’s 1 or 0
Using another automation to turn on a helper. The helper (switch) works great but then choose still takes the exact same route, regardless of what the helper is doing.
Using an If/Then. Exact same problem with the helper or the state attribute.
checked the spelling/case of all entities many many times
I feel like I must be doing something wrong, I just don’t know what
I think it is how I wrote it in my configuration.yaml file. I cannot get rid of the hvac_status portion of it. However, I have copy/pasted the unique entity ID.
This is also the reason I tried using the switch helper in the choose. Regardless of the switch being on or off, it always takes the same route.
#Attribute for secure house automation running status
- platform: template
sensors:
automation_status:
unique_id: "secure_house_automation_running"
friendly_name: secure house automation status
value_template: >-
{{ state_attr('automation.secure_house', 'current')}}
Hello all, incase anyone stumbles on this, I found the root cause of the problem.
In the automation I am calling to trigger the same automation that I am checking the status of, for some reason this makes everything not work properly. As soon as I disable the step of triggering the same automation, the choose proceeds as normal. I’m sure there is a work around but I anticipate it being complicated.
If this only has the states 1 and 0 you should be using a binary sensor. Also you should be using the new template integration for new template sensors. The legacy template sensor platform is not getting new features (though it does continue to be supported).
e.g. replace that with this in your configuration.yaml file (not sensors.yaml or binary_sensors.yaml)
template:
- binary_sensor:
- name: Secure House Automation Status
device_class: running
state: "{{ is_state_attr('automation.secure_house', 'current','1') }}"
You can then use this condition in your choose action:
Thank you for taking the time to help me @tom_l. I had no idea I was using legacy templating. I did implement your method but the state would never change. I found an alternate method before I was able to determine/fix the problems with implementing what you suggested (I was likely doing something wrong).
Anyways, I found the solution to my original problem. I have changed entity names from the above description however the core concept remains the same and the mistake was very simple.
The problem is you cannot use the service call Script: “script_name_here” after you check if a script is running. The same applies for automations and the example is below:
service: script.securing_house_test
data: {}
The above example is wrong and will not work
The method that worked for me to determine if the script/automation is running and then shut it off if it is or turn it on if its not running is below.
Two important takeaways in the above example. 1, when using a script, you have to use the “script turn on service call” to activate the script. 2, quotation marks will automatically be added around the “1” and the “0” The quotation marks must be removed manually for the above example to work.
Entire code is below in the event it helps someone: