Help with an automation that calls a script

I have a heating boiler that has the following three states:

  • Off–0 W
  • Water Pump Only Running- 80W
  • Burner and Water pump running - above 100W

I would like to have one automation with six triggers (for crossing between the three states in each direction). Then, this automation would execute a script that receives as a variable which trigger and direction combo caused the triggering and then posts a note to a Google sheet to log the time and a trigger note.

I know how to do this with six separate automations, but I think that might be confusing in the future and problematic to maintain.

I have researched it and believe it can be done but am running in circles, so I need a bit of guidance on the approach… or maybe just an example of a script receiving trigger status passed from an automation.

Thanks in advance.

It would help us provide you with an answer specific to your situation if you share at least one of those automations and the target script. Questions Guidlines #9 & 11

One general option would be to attach variables to each trigger

triggers:
  - trigger: state
    entity_id: ?
    to: ?
    from: ?
    variables:
      type: A
      direction: decrease
  - trigger: state
    entity_id: ?
    to: ?
    from: ?
    variables:
      type: B
      direction: decrease
conditions: []
actions:
  - action: script.example
    data:
      type: "{{ type }}"
      direction: "{{ direction }}"

If your trigger already contains the data you want to pass, you can do that directly using the trigger variable. For a state trigger it would be this, leveraging Drew’s example:

triggers:
  - trigger: state
    entity_id: ?
    to: ?
    from: ?
  - trigger: state
    entity_id: ?
    to: ?
    from: ?
conditions: []
actions:
  - action: script.example
    data:
      from: "{{ trigger.from_state.state }}"
      to: "{{ trigger.to_state.state }}"

Also note that you can call the script using the blocking or non-blocking format, depending on whether you want your automation to wait for the completion of the script before the automation continues to the next step. The non-blocking format would be

actions:
  - action: script.turn_on
    target:
      entity_id: script.example
    data:
      variables:
        from: "{{ trigger.from_state.state }}"
        to: "{{ trigger.to_state.state }}"

Thanks Didgeridrew. I don’t actually have a script yet. That is why I needed some conceptual help which you and mekhaneck provided. Many thanks. I have started to implement your suggestions and will post some code when I have it.

Thanks Didgeridrew and mekhaneck. You got me on the right path. Here is my solution. Comments welcomed and thanks so much!!

alias: TestReadStatus
description: Reads input number and post data to Google sheet
triggers:
  - trigger: numeric_state
    entity_id:
      - input_number.testnumber
    below: 2
    variables:
      type: Boiler Off
  - trigger: numeric_state
    entity_id:
      - input_number.testnumber
    above: 80
    variables:
      type: Burner Running
  - trigger: numeric_state
    entity_id:
      - input_number.testnumber
    below: 81
    above: 1
    variables:
      type: Boiler On Burner Off
conditions: []
actions:
  - action: google_sheets.append_sheet
    metadata: {}
    data:
      config_entry: xxxxxxxxxxxxxxxxxxxxx
      worksheet: Test
      data:
        Type: "{{type}}"
mode: single