I’m working on building dashboard displays and notifications based on the Waste Collection Schedule integration. Everything works great, however I want an automation to prepare a input_text helper to support the displays and notifications.
Below is the YAML of what I have, and attached is an image of what the trace shows me. For whatever reason, even though one of the sensors referenced does fall into the trigger critera, the actions are skipped.
id: '1706717504758'
alias: System | Update Next Rubbish Collection
description: ''
trigger:
- platform: template
value_template: |-
{% if states('sensor.rubbish_collection_pink') > 8 %}
{% endif %}
id: Green
- platform: template
value_template: |-
{% if states('sensor.rubbish_collection_green') > 8 %}
{% endif %}
id: Pink
condition: []
action:
- choose:
- conditions:
- condition: trigger
id:
- Green
sequence:
- service: input_text.set_value
target:
entity_id: input_text.home_next_rubbish_collection
data:
value: GREEN
- conditions:
- condition: trigger
id:
- Pink
sequence:
- service: input_text.set_value
target:
entity_id: input_text.home_next_rubbish_collection
data:
value: PINK and BLACK
Note I’ve also tried to set the trigger critera by referencing the entities themselves, not by template, and I get the same result.
From the trace, it looks like you executed the automation manually, didn’t you?
Then, there is no trigger being used, so all trigger conditions return false.
What koying said. Executing an automation’s Run command only executes its actions. That means it skips the triggers. By skipping the triggers, the trigger variable is never defined. An undefined trigger variable means none of the Trigger Conditions will work.
Your two Template Triggers will never trigger because their template is comparing a string to a number. In addition, the template uses an if - then that reports nothing.
I suggest you change your Template Triggers to this:
Your Template Triggers report Green when sensor.rubbish_collection_pink is greater than 8 and Pink when sensor.rubbish_collection_green is greater than 8. Is that intentional or a mistake?
Thanks Taras, I didn’t know how to convert the value to number for a like for like comparision, so I’ve added your suggestion code to the automation now. I’ve also switched the logic as you mentioned, which makes it more sense.
The revised version of what you posted still uses an if endif structure which won’t work the way you think it might. Use the template I suggested.
In your original version, the template tests if the sensor’s value is greater than 8. In your revised version it tests if it’s less than 8. That’s a significant change to the test. Which version of the test is correct?
Assuming that the new version of the test is the correct one, here’s what I suggest you use:
To test the automation, you can set the value of sensor.rubbish_collection_pink to a number lower than 8. You can do that using Developer Tools > States.
Go to Developer Tools > States
Find sensor.rubbish_collection_pink in the list and click it.
Scroll to the top of the page where all of the sensor’s properties are displayed in a form.
Take note of its current State value (perhaps make a copy of it). It should currently be above 8 in order for the test to work.
Change the value to 7 or anything less than 8.
Click the Set State button.
That should be sufficient to trigger the automation’s Template Trigger.
Optionally, use the same technique to set the sensor’s value back to its original value. Otherwise, simply wait for the sensor’s integration to update the sensor’s value.