Automation without trigger?

I have a bedtime script that is executed when I click a button on the lovelace panel.

alias: bedtime
sequence:
  - service: homeassistant.turn_off
    target:
      area_id:
        - patio
        - family_room
        - office
        - foyer
      entity_id:
        - switch.stanley_lamp
        - switch.pulley_lamp
mode: single

I am building an automation that will use various Conditions to alert me if a door is open or unlocked.

alias: Door-Checker
description: ''
mode: single
trigger:
  - platform: device
    device_id: ''
    domain: ''
    entity_id: ''
condition:
  - condition: or
    conditions:
      - condition: state
        entity_id: binary_sensor.konnected_1c57f2_side_door
        state: 'on'
      - condition: state
        entity_id: binary_sensor.konnected_1c57f2_basement_rear
        state: 'on'
      - condition: state
        entity_id: binary_sensor.konnected_1c57f2_kitchen_door
        state: 'on'
      - condition: state
        entity_id: binary_sensor.konnected_1c57f2_front_door
        state: 'on'
action:
  - service: tts.google_translate_say
    data:
      entity_id: media_player.master_bedroom_display
      message: A door is Still Open

This doesn’t work since there is no trigger.

What I would like is to have my Bedtime Script call the Door-Checker automation.

How do I add the Door-Checker automation to the existing Bedtime script executed by the Lovelace Button? Or… can I add the Door-Checker conditions to the Bedtime script?

Thank you.

An automation without a trigger is not an automation.

If your application has no need for a trigger, create a script. Scripts can contain conditions and service calls, delays, choose, repeat, etc. In other words, everything an automation can contain, minus the trigger.

1 Like

Like @123 says, what you are doing when you create a trigger-less automation is basically a script that won’t run on its own but rather need to be forced to run using automation.trigger, so you might as well make a script. Otherwise you will have to add a service call to automation.trigger to run it.

For my wake-up and sleep modes I use a fairly long script that runs through the laundry list of lights to turn off, lights to turn on and a myriad of other things. While possible inside the automation UI it would be messy (to me at least).

asleep:
  alias: Asleep
  icon: mdi:home
  sequence:
    # --------------------------------------
    # TURN OFF MOTION AUTOMATION SO THE OFF
    # DELAY IS CANCELLED IF TRIGGERED
    # --------------------------------------
    - service: automation.turn_off
      data:
        entity_id: automation.trigger_bedroom_motion_when_awake

    # --------------------------------------
    # TURN ON BEDROOM
    # --------------------------------------
    - service: homeassistant.turn_on
      data:
        entity_id: group.bedroom_core

      ...

    # --------------------------------------
    # SET STATUS
    # --------------------------------------
    - service: input_select.select_option
      data:
        entity_id: input_select.sleep_mode
        option: "Sleeping"

  mode: single

Why don’t you put those condition as triggers? You don’t even need the “or” condition, whenever one of the binary_sensor state is “on” it’s gonna do the action

1 Like

Try this:

alias: Door-Checker
description: ''
mode: single
trigger:
  - platform: state
    entity_id:
      - binary_sensor.konnected_1c57f2_side_door
      - binary_sensor.konnected_1c57f2_basement_rear
      - binary_sensor.konnected_1c57f2_kitchen_door
      - binary_sensor.konnected_1c57f2_front_door
    to: 'on'
action:
  - service: tts.google_translate_say
    data:
      entity_id: media_player.master_bedroom_display
      message: >
        {% set open_doors =
          [ states.binary_sensor.konnected_1c57f2_side_door,
            states.binary_sensor.konnected_1c57f2_basement_rear,
            states.binary_sensor.konnected_1c57f2_kitchen_door,
            states.binary_sensor.konnected_1c57f2_front_door ] 
          | selectattr('state', 'eq', 'on')
          | map(attribute='name') | list %}
        {% set qty = open_doors | count %}
        {% set plural = 's' if qty > 1 else '' %}
        {% set verb = 'are' if qty > 1 else 'is' %}
        The following door{{ plural }} {{ verb }} open: {{ open_doors | join(', ') }}.

and you can look at what was Trigger

trigger.to_state
- id: 'notify stephan phone Door Change'
  alias: "notify Stephan phone Door Change"
  initial_state: true
  trigger:
  - entity_id: 
    - binary_sensor.garage_side_door
    - binary_sensor.garage_door
    - binary_sensor.front_door
    - binary_sensor.cupboard_door
    - binary_sensor.linen_door
    - binary_sensor.washing_door
    - binary_sensor.dryer_door
    platform: state
  action:
  - data_template:
      title: "Home Assistant"
      message: "{{ trigger.to_state.attributes.friendly_name }} was {% if trigger.to_state.state == 'on' %} Open {% else %} Closed {% endif %}"
    service: notify.stephan_phone

Even that won’t work since that service only works with an automation (hence the name) and you can’t create an automation without a trigger (you will get errors that says that the trigger is missing) so there is no automation to use that service against.

I’m not looking for a door chime, the requirement isn’t to alert when a door is open.

The requirement is an automation that runs only once, when I lick a button on a Lovelace panel, that tells me if any doors are open at that point in time, and only then.

I already have a button, and I already have a script. I think my take-away from this thread is just to move this door alerting logic into that script somehow, so I just have one giant bedtime script.

It works for me.

With no triggers at all. Then run it in Developer and it does precisely what’s in the actions (wife’s name hidden to protect the innocent :stuck_out_tongue_winking_eye: )

That would be a script, not an automation.

report_open_doors:
  alias: Report Open Doors
  sequence:
  - service: tts.google_translate_say
    data:
      entity_id: media_player.master_bedroom_display
      message: >
        {% set open_doors =
          [ states.binary_sensor.konnected_1c57f2_side_door,
            states.binary_sensor.konnected_1c57f2_basement_rear,
            states.binary_sensor.konnected_1c57f2_kitchen_door,
            states.binary_sensor.konnected_1c57f2_front_door ] 
          | selectattr('state', 'eq', 'on')
          | map(attribute='name') | list %}
        {% set qty = open_doors | count %}
        {% if qty == 0 %}
          All doors are closed.
        {% else %}
          {% set plural = 's' if qty > 1 else '' %}
          {% set verb = 'are' if qty > 1 else 'is' %}
          The following door{{ plural }} {{ verb }} open: {{ open_doors | join(', ') }}.
        {% endif %}

Simply use the button’s tap_action to call the script.


EDIT

You said you already have a ‘bedtime script’ so just append the service call, shown in the example above, to your existing script.

1 Like

If you want to use an automation “without” a trigger, you can use an input_boolean as helper.

Setup an input_boolean.bed_mode, and use that as trigger in the automation (trigger state input_boolean to on). Whenever you switch that button on, your bed mode starts.

I’m using this for different modes, one of them is bed mode. I let this bed mode end together with the alarm clock time from my mobile phone. This can be useful if you have for example a coffee machine, that needs to be started before you wake up.

I’m not sure why.

I just tried it as a test.

I configured this automation in my automation_test.yaml file (I split mine up with !include and never use the editors):

  - alias: test repeat till count
    # trigger:
      # - platform: state
        # entity_id: switch.boot_dryer
        # to: 'on'
    action:
      - repeat:
          count: 4
          sequence:
            - delay: 2
            - service: light.toggle
              data_template:
                entity_id: light.comp_corner_lamp_1df9

The config validator check returns “valid” but I also get an error in the logs along with a persistent notification pop-up in the sidebar:

Invalid config for [automation]: required key not provided @ data['trigger']. Got None. (See ?, line ?).

And the automation doesn’t show up in my states page.

What is an “action-group”. Is that just the alias of the automation you gave it?

And how did you add the actions for the automation? I don’t see those listed.

EDIT:

I just tried it with the automation editor and it does actually work the way you say yours does.

BUT…

I can’t imagine that is the intended behavior. It’s likely a (happy in your case) bug in the system.

So I wouldn’t necessarily be recommending that to other users since it’s definitely not consistent between yaml and UI. That will cause way more confusion among users.

It’s best just to keep the “action only automation” as a script and then call that script properly within the lovelace UI or via an automation.

EDIT2:

How in the heck does a person delete an automation created via the UI editor?

I can’t find anywhere to remove it.

That doesn’t sound very hygienic to me… :mask:

:laughing:

2 Likes

I’m very slowly coming around to the power of templating. Thanks for that pointer.

1 Like

It’s in beta right now, the final release will also have scratch-and-sniff. :joy:

1 Like