Help with simple automation ID field

I have zwave working, can turn on and lights.

I am trying to set up some simple automation to turn a light off at night, and on in the morning. Using the automation editor, I ended up with this:

pi@raspberrypi:/home/homeassistant/.homeassistant $ cat automations.yaml

  • action:
    • data:
      entity_id: switch.living_room_table_lamp_switch
      service: switch.turn_off
      alias: Living Room Floor Lamp Off PM
      condition: []
      id: ‘1505695368764’
      trigger:
    • at: ‘22:00’
      platform: time

I tried to set up another in automation tool, but it will not save. There is no error message at top when I hit that icon. I am up for editing the automations.yaml manually, but my question is about the ID field above… Where does that come from? If I was adding another automation in the yaml file, would it need a different ID?

alias: your name here
  trigger: your trigger here
  condition: if applicable
  action

so

alias: Living Room Floor Lamp Off PM
  trigger:
    platform: time
    at: '22:00:00'
  condition:
    condition: state
    entity_id: ????
    state: ????
  action:
    service: switch.turn_off
    data:
      entity_id: switch.living_room_table_lamp_switch

I can’t see your condition in your post. It seems your automation is a bit wacky

Not to be dense, but what would the condition be? I don’t have a condition, just turn off at that time.

from

I see

Time condition

The time condition can test if it is after a specified time, before a specified time or if it is a certain day of the week

condition:
condition: time

At least one of the following is required.

after: ‘15:00:00’
before: ‘02:00:00’
weekday:
- mon
- wed
- fri

Valid values for weekday are mon, tue, wed, thu, fri, sat, sun. Time condition windows can span across the midnight threshold. In the example above, the condition window is from 3pm to 2am.

so I would have:

condition:
condition: time
weekday:
Mon
Tue
Wed
Thu
Fri

Sorry for the funky formatting, other than blockquote, what should I be using to maintain spaces.

And what is the purpose of ID the automation edit stuck in there?

The automation editor requires a unique id for each automation. No rhyme or reason to them.

Conditions are only required if you want something to be checked before the action fires.

The automation editor spits out automations in an odd sequence and format but they do work.

It would really make sense if the automation editor is creating the automation in the same format as the docs. I look at the top post and see something I’m not used to seeing and assume it’s incorrect.

1 Like

Oh I totally agree, I can’t read them without really looking close. Not sure why they dont follow the format in the docs.

The new automation editor is confusing! I’m used to the old automation.yaml which let me edit in Notepad++ pretty well. Now if I have set up a new automation in the editor and want to add another automation to the .yaml it doesn’t work. Is it even possible to edit the yaml file?

I was also wondering why the new automation starts with ’ action’ while the old starts with ‘alias’.

The order of the items doesn’t matter, you can have your action at the top or the trigger at the top. Apparently HA reads it all the same.

You should be able to add a automation manually. Are you giving it a unique ID?

Yes, I tried to add an automation manually with an unique ID but it didn’t fire. Does it matter how the ID look like? e.g. 12345 or 54321?

As long as its unique (not repeated in another automation) it shouldn’t matter.

Can you post up your automation? Maybe you have a slight misstep in the yaml which can cause issues.

- id: 1
  alias: Notify when Doorbell rings
  hide_entity: true
  trigger:
  - platform: state
    entity_id: binary_sensor.door_window_sensor_158d000
    to: 'on'
  action:
    - service: notify.Bravia
      data:
        message: Doorbell ring
    - service: notify.facebook
      data:
        message: Doorbell ring
        target:
          - +mobilenumber_redacted

- id: 2
  alias: Notify when Front door is open
  hide_entity: true
  trigger:
  - platform: state
    entity_id: binary_sensor.door_window_sensor_158d0001
    to: 'on'
  action:
    - service: notify.Bravia
      data:
        message: 'Front door open'
    - service: notify.facebook
      data:
        message: 'Front door open'
        target:
          - +mobilenumber_redacted

Any suggestions?

When I see automation examples containing id’s, they are always in single quotes.
Don’t know whether they are really needed ore not.
The whole thing is totally confusing in my opinion.

In my Hassio installation the Editor generates 13-digit id’s like this in single quotes;

  • id: ‘1523635427469’

Some examples on github are selfwritten text ids without any quotes:

-id: a_alarm_triggered

Many config examples on github do not contain any id’s when separated in different files in a directory
The “alias” is sometimes within single quotes, double quotes or no quotes at all.
alias: “3D Printer Finish Off”

  • alias: Doorbell - Turn On Front Porch when Rung
    alias: ‘Alarm Clock’

Unfortunately in the documentation to automations in Home assistant says noting about the id or usage of quotes.

But what they say::
“You have to set an initial state in your automations in order for Home Assistant to always enable them upon restart.”

automation:
- alias: Automation Name
  initial_state: True
  trigger:

On another page they recommend setting
initial_state: ‘off’
Seems that an automation entry can have the states true, false, “on” or “off”. ?!

Looking into examples on github, most of them do not set “initial_state”
but seem to work without this setting.

1 Like

id is a text field, quotes don’t matter and are optional (and the length doesn’t matter). If you omit initial_state, it defaults to what ever it had when it shut down. ‘on’/True are treated the same in many fields, same as ‘off’/False.

It would be lovely if the automation docs could be fleshed out a bit. It doesn’t even cover the fields available or required like many of the others, and it seems automations is pretty important to folks. I’m here because the help itself was pretty unhelpful. I’d offer to update it, but I’d have to understand it first. I’d also humbly suggest that a ‘last updated date’ be included on the pages so it would be easier to determine what needs updating when. But perhaps you guys are using githup repo tools for that, don’t know.

Automation is all up to date and covered pretty well. What attributes are you referring to? Perhaps you’re just looking in the wrong spot.

I guess. maybe if you already understood how they work. But for the first-timer, there’s the section on “Exploring the internal state” which feels out of place and never really explains how any of that is to be used (nor links to other pages that might). As for attributes, at the bottom, alias is used, but there is not the usual entry for such in a list as on other pages. It made me wonder what other attributes there were. Same with initial_state, but at least I can infer it’s use and possible values from the text. Granted, ‘alias’ is pretty easy to guess, if one has looked at any other pages. Consistency is the issue for me, mostly.

The Triggers and Conditions pages provide good detail and plenty of examples, although the Actions page pales in comparison (IMHO). There are just so many possibilities with Actions, and only two examples. What about syntax for calling scripts, or using templates, etc., references to more details. I found myself at a loss as to what was even possible.

I’m not being critical, only passing along my struggles as a fairly technical person and retired career SW Engineer, but someone new to HA, YAML, Jinja, etc., trying to use this incredible platform. The more I know the more I can hopefully contribute one day. :grinning: And I’m pretty much at this every day now.

actions don’t have documentation. Go to dev tools services tab to see all available services on your system. It will also list out all fields that are required or optional for the service data.

Also, all documentable services are covered in the scripts section. Because script services and automation actions are identical.

1 Like

Also, use the sidebar to navigate:

image

Initial state is covered in the main automation page, get there by clicking the automation title in the sidebar.

In the automation Actions section, there’s a link to all the built in actions mentioned in my previous post.

This page goes more into the actions (services). All other services that aren’t included here are documented in the developer tools -> services tab.

1 Like

Thanks petro, I had been through all of that multiple times, but read the “action part follows the script syntax” as describing the format “if you were using a script”. But I now put together that a Script is just a series of actions, most if not all of which are listed in the Script Synatx page. Sorry to be so dense.