Allow templates for enabling automation triggers, conditions and actions #1066
|
Currently an automation trigger can be disabled by setting automation:
trigger:
- enabled: false
platform: ...Allowed values are booleans, numbers and strings ("on", "off", "true", "false", etc.) https://github.com/home-assistant/core/blob/5aabb2a920ab3810e6fcdec4de4e8698b22a960f/homeassistant/helpers/config_validation.py#L1651 For Blueprints, it would be nice to be able to disable a specific items based on an input (or its default value if nothing is set by the user). blueprint:
name: Dependent disable
domain: automation
input:
required_input:
name: Required
optional_input:
name: Optional
default: false
binary_input:
name: Use action
selector:
boolean:
trigger_variables:
_optional_input: !input optional_input
trigger:
- platform: mqtt
topic: !input required_input
- platform: mqtt
topic: !input optional_input
enabled: "{{ not _optional_input == False }}"
# or maybe even simpler without trigger_variable
enabled: !input optional_input
action:
- service: system_log.write
enabled: !binary_input
data:
level: info
message: "{{ trigger }}"To achieve this, the vol.Optional(CONF_ENABLED): vol.Any(boolean, template),and evaluate these in and according methods for condition and action. While, for conditions and actions, we could support full templates, PR for implementations: |
Replies: 2 comments 4 replies
|
You would need to take into account more that an MQTT trigger though. By using the actual input as the flag, this would be hard as there are so many options. MQTT triggers happen, but there are state and target and all the things. Also most inputs are NOT triggers. As far as is this useful, yes, it has come up as a question a few times. People end up putting a dummy helper in there or something lame. I usually try to code around it when I can by asking for a more general trigger and templating in the conditions things that might not be there. Not everyone has trained themselves to think a few steps ahead. |
|
This is a nice addition, let's do it! |
This is a nice addition, let's do it!