Need help for automation with dynamic actions

Hello, I’m more a beginner…

I like to create automations like this (which is only an example for the problem):

IF sunset
THEN

  1. action: set Bathroom shutter: 50%, bathroom light: 20%, in 5 minutes from now
  2. action: set livingroom shutter: 40%, livingroom light:30%, in 2 minutes from now
  3. action: set sleepingroom shutter:100%, livingroom light: 10%, in 15 minutes from now
  4. action: set kitchenroom shutter: 20%, kitchenroom light: 100%, now

My question:

How can I create an object which can be added as an action with has configurable values for room, shutter%, light% and timer values via GUI?

Must it be a template? a skript? a blueprint? a service?

I’m really lost and wouldt appreciate any help (example?) how to do that.

Thank you!

Guenter

Note: I named the actions in chronological order, not your action list order.

trigger:
  - id: action_1
    platform: sun
    event: sunset
  - id: action_2
    platform: sun
    event: sunset
    offset: "00:00:02"
  - id: action_3
    platform: sun
    event: sunset
    offset: "00:00:05"
  - id: action_4
    platform: sun
    event: sunset
    offset: "00:00:15"
action:
  - choose:
      - conditions:
          - condition: trigger
            id: "action_1"
        sequence:
          - service: cover.set_cover_position
            target:
              entity_id: cover.kitchenroom_shutter
            data:
              position: 20
          - service: light.turn_on
            target:
              entity_id: light.kitchenroom
            data:
              brightness_pct: 100
      - conditions:
          - condition: trigger
            id: "action_2"
        sequence:
          - service: cover.set_cover_position
            target:
              entity_id: cover.livingroom_shutter
            data:
              position: 40
          - service: light.turn_on
            target:
              entity_id: light.livingroom
            data:
              brightness_pct: 30
      - conditions:
          - condition: trigger
            id: "action_3"
        sequence:
          - service: cover.set_cover_position
            target:
              entity_id: cover.bathroom_shutter
            data:
              position: 50
          - service: light.turn_on
            target:
              entity_id: light.bathroom
            data:
              brightness_pct: 20
      - conditions:
          - condition: trigger
            id: "action_4"
        sequence:
          - service: cover.set_cover_position
            target:
              entity_id: cover.sleepingroom_shutter
            data:
              position: 100
          - service: light.turn_on
            target:
              entity_id: light.livingroom
            data:
              brightness_pct: 10

Hi Tom,

thank you for the fast reply!!

I understood your solution, but what I’m really looking for ist is a more generic way, where I can select an object in the GUI as an action, which let me select the different values for room, shutter and so on like this:

But I don’t know how to define something else. I can create a Blaupause (blueprint) with the needed fields, but I cannot call a blueprint as an action. So how to define an object, which can be defined and called multiple times in an automation with different parameters.

The background for that is to do similar things like Homematic does. And its an idea for migration to HA:

It must be as easy as possible, no YAML knowledge for creation of an automation, IF such kind of action type can be offered at automation creation time.

Couldt I explain that better now?

Best Guenni

You could define some input selects (room) and input numbers (light %, cover %). and use them in your automation.

So:

trigger:
  - platform: sun
    event: sunset
action:
  - service: cover.set_cover_position
    target:
      entity_id: "cover.{{ states('input_select.room')|sligify }}"
    data:
      position: "{{ states('input_number.cover_position') }}"
  - service: light.turn_on
    target:
      entity_id: "light.{{ states('input_select.room')|slugify }}"
    data:
      brightness_pct: "{{ states('input_number.light_prichtness_pct') }}"

What you are asking for is not simple and will require an understanding of YAML and jinja templates.

Yes, youre right concerning the knowledge for the builder of those kinds of templates.
For the User who builds automations from those kinds of templates it should be as easy as possible.

Your first example showed me that you where using

“service: cover.set_cover_position”

This service can be selected when defining actions and has an GUI for that.

And my question is, how to create such a service with my individual parameters (and of course with the needed knowledge), so that an easy enduser can select this service in an automation action?

Best
Guenni

I have no idea what you are asking. You can select the entity in the automation editor. How much simpler than that do you want?

OK, from my understanding I need to write my own service in the way “cover.set_cover_position” did it.

Do you know where to find the source code from that service?

Every integration has a link to its source in the documentation.

Thank you so much Tom!

I learned a lot. Just to make more clear what the goal is:

In old Homematic CCU you can define programs, which are similar to automations in HA. And I’m looking for a migration strategy.

The first part of a Homematic program is like the trigger and condition part of an automation and easy.

The second part is the action list when trigger fires.

And the action list consists of multiple entries, each having
a) select entity b) target value c) timer delay

And now I am looking for a service, which allows the calling of a service lets say “homematic.entity_action”. That call should run asynchronously from the next action.

Building a custom service looks like sophisticated, I have to go deeper into that.

But when that service is build, it could be used by every administrator, who can define a Homematic program today and in an further step it could be possible to write a migration tool, that migrates a Homematic program to a HA automation, producing the YAML-Code for that.

Best Guenni

It seems like you should be creating a Script Blueprint not an Automation Blueprint.

YES!!!

Thank you!