Automation Blueprint: Run automation using manual event trigger

I need some help please understanding what I am doing wrong here. I want a manual event (event_type: said_task_finished) to trigger running an automation which in turn runs a script provided it meets a date range condition.

Logical steps:

  • Manual event triggers automation to run
  • additional condition is met (switch.tank_fill = off)
  • automation decides which script is run based on a pre-defined date range

I have managed to get it working fine in an automation but I need to create a few of these and thought it would be easier to do/manage in a blueprint

My code:

blueprint:
  name: "Nutrient Feed Phase"
  description: ''
  domain: automation
  input:
    event_type:
      name: "Feed Trigger"
      description: Select notification to trigger feed cycle
      selector:
        trigger:

    veg_phase_1:
      name: "Vegetative Phase 1 - Nutrient Type"
      description: "Select nutrient feed script" 
      selector:
        entity:
          filter:
            - domain: script
    
    condition_veg_phase_1:
      name: "Vegetative Phase 1 Condition"
      description: "Add conditions if needed"
      selector:
        condition:
    
    veg_phase_2:
      name: "Vegetative Phase 2 - Nutrient Type"
      description: "Select nutrient feed script" 
      selector:
        entity:
          filter:
            - domain: script
            
    condition_veg_phase_2:
      name: "Vegetative Phase 2 Condition"
      description: "Add conditions if needed"
      default: []
      selector:
        condition:

triggers:
  - trigger: event
    event_type: ''
    event_data:
      entity_id: !input event_type
conditions:
  - condition: state
    entity_id: switch.esphome_web_f54944_tank_fill
    state: 'off'
actions:
  - choose:
    - conditions:
      - condition: template
        value_template: "{{ condition_veg_phase_1 }}"
      sequence:
      - action: !input veg_phase_1
    - conditions:
      - condition: template
        value_template: "{{ condition_veg_phase_2 }}"
      sequence:
      - action: !input veg_phase_2
mode: single

Condition template (for date range)

condition: template
value_template: >
  {% set begin = states('sensor.vegetative_phase_1') | as_datetime | as_local %}
  {% set end = states('sensor.vegetative_phase_2') | as_datetime | as_local %}
  {% set d = [now().month, now().day] %} {{ [begin.month, begin.day] >= d or d <
  [end.month, end.day] }}

There’s a few things that are wrong here, but it just boils down to “Using the wrong selectors in the wrong fields”.

A trigger selector returns a full trigger. You can’t put that into the entity_id field of an event trigger’s data. Well you can, but the trigger won’t do anything. You should be using a text selector and the input should be placed in the event_type field, or use the entire input as the trigger to fully replace everything in your trigger section.

A condition selector returns a full selector as well. You are attempting to use a variable that has the same name as your selector output. You aren’t actually using the input anywhere. So those conditions will always fail because there’s no variable with that name. You need to use the full condition, or use a template selector (and pull the template into a variable or directly on the value_template field).

1 Like

Just had to change my response as I found I was using an outdated script! And also realised I should not include “event_type” in my text selector. Thank you so much for correcting my mistakes! It now works.

Though I couldn’t get the event trigger to work as “!input event_type”. I still have a lot of learning to do.

This is what I think you were suggesting:

blueprint:
  name: "Nutrient Feed Phase"
  description: ''
  domain: automation
  input:
    event_type:
      name: "Feed Trigger"
      description: "Select notification to trigger feed cycle"
      default: "fill_tank_complete"
      selector:
        text:

    veg_phase_1:
      name: "Vegetative Phase 1 - Nutrient Type"
      description: "Select nutrient feed script" 
      selector:
        entity:
          filter:
            - domain: script

    veg_phase_2:
      name: "Vegetative Phase 2 - Nutrient Type"
      description: "Select nutrient feed script" 
      selector:
        entity:
          filter:
            - domain: script

triggers:
  - trigger: event
    event_type: '{{ event_type }}'
conditions:
  - condition: state
    entity_id: switch.esphome_web_f54944_tank_fill
    state: 'off'
actions:
  - choose:
    - conditions:
      - condition: template
        value_template: >
          {% set begin = states('sensor.vegetative_phase_1') | as_datetime | as_local %}
          {% set end = states('sensor.vegetative_phase_2') | as_datetime | as_local %} 
          {% set d = [now().month, now().day] %} 
          {{ d >= [begin.month, begin.day] and d < [end.month, end.day] }}
      sequence:
      - action: !input veg_phase_1
    - conditions:
      - condition: template
        value_template: >
          {% set begin = states('sensor.vegetative_phase_2') | as_datetime | as_local %}
          {% set end = states('sensor.flowering_phase_1') | as_datetime | as_local %} 
          {% set d = [now().month, now().day] %} 
          {{ d >= [begin.month, begin.day] and d < [end.month, end.day] }}
      sequence:
      - action: !input veg_phase_2
mode: single