And condition with a single child not working

I get

Invalid config for [automation]: Unexpected value for condition: ‘OrderedDict([(‘alias’, ‘temperature foo below 19 degrees’), (‘condition’, ‘and’), (‘conditions’, [OrderedDict([(‘below’, 19), (‘condition’, ‘numeric_state’), (‘entity_id’, ‘sensor.filtered_realistic_temperature_foo’)])])])’. Expected and, device, not, numeric_state, or, state, sun, template, time, trigger, zone, a valid template @ data[‘action’][1]. Got None. (See /var/lib/hass/configuration.yaml, line 1).

Given:

- action:
  - data:
      hvac_mode: heat
      temperature: 19
    service: climate.set_temperature
    target:
      entity_id: climate.0xb4e3f9fffebda199
  - condition:
      alias: temperature foo below 19 degrees
      condition: and
      conditions:
      - below: 19
        condition: numeric_state
        entity_id: sensor.filtered_realistic_temperature_foo
  - data:
      value: 465
    service: number.set_value
    target:
      entity_id: number.0xb4e3f9fffebda199_boost_timeset_countdown
  alias: alias1
  condition:
  - condition: time
    weekday:
    - fri
  id: myid
  trigger:
  - at: 09:30
    platform: time

Can’t I use a single “and” component or something?

I’m curious to know what you are using that sorted your automation’s YAML statements? It made action first, trigger last, and everything else somewhere in between. Like trying to read a novel sorted by its chapter titles.

Not according to the error message.

I agree the sort is not optimal (to say the least for home assistant). It’s just an uninformed sort based on hashing.

should be

  - alias: temperature foo below 19 degrees
    condition: and
    conditions:
    - below: 19
      condition: numeric_state
      entity_id: sensor.filtered_realistic_temperature_foo

This also doesn’t work. The intention is that the boost action does not execute if the condition is false. According to the documentation this seems to be supported.

  - condition:
      alias: temperature foo below 19 degrees
      below: 19
      condition: numeric_state
      entity_id: sensor.filtered_realistic_temperature_foo

The first example here is wrong too then:

You’re mixing the condition field up with actual conditions that go inside it. When putting conditions inside the action list, you do not include the main condition field.

No it’s not wrong, it’s showing you the condition inside the condition field.

You replied to me instead of petro.

BTW, I checked the contents of automations.yaml and all of the automations created by the Automation Editor are not sorted. So I still don’t understand why yours is. Are you using a recent version of Home Assistant?

Here’s the action sections condition documentation.

Notice the syntax.

Now notice the same condition inside the condition page that you linked that covers all conditions

See how they both share the same condition, one just has an alias attached to it.

That’s your condition. Not the field it goes into.

In that case, it goes against all conventions in programming language documentation.

I’d prefer to just see a formal operational semantics such that there is no confusion possible.

Thanks for the help, all. I got it to work without the extra condition:.

The yaml is created by tools outside of Home Assistant.

unfortunately, that leads to more confusion as then people don’t add the condition field in automation. It’s a double edged sword and it’s gotten to this point based on past experiences beginners had.

Whatever “tools” they might be, they needlessly sorted the YAML statements and failed to provide you with guidance for composing valid YAML (i.e. allowing for the malformed condition). I suggest you use the Automation Editor or, if you prefer a text editor, VS Code with the Config Helper plug-in.

I intentionally wrote it like this based on the documentation. I have programmed in 30+ languages. If I can’t write a condition the first time correctly, it’s a problem with Home Assistant.

The “script” syntax also uses this "script:" syntax. I have absolutely no idea whether it’s wrong to use it there too. I think it would help if there would be complete examples including the automation: toplevel element. A formal semantics would be better, however, but I believe the people involved in this project are not exactly PL experts, so I guess I can’t expect that.

YAML has unordered data format elements. If the designers of Home Assistant considered it important, they should not have used YAML.

I think you should familiarize yourself with integrations as that seems to be the disconnect here. An integration has a specific configuration, and that configuration changes based on the integration. Script is the script integration. The action section of an automation shares the same functionality as the sequence in a script.

It’s ordered because users wanted it that way. Remember, more than just you is using this.

EDIT: I should clarify, yaml doesn’t care. People on the forums like seeing it…

trigger:
  ...
condition:
  ...
action:
  ...

Can you show me examples in the documentation where the YAML statements are sorted alphabetically in automations?

The overwhelming majority of examples that I have found in the documentation and in this community forum are in a ‘cause and effect’ order (trigger/condition/action).

Your syntax errors are always Home Assistant’s fault?

At most I’d say the syntax errors you created (malformed condition) were allowed by whatever unnamed tools you used. Ultimately, it’s your responsibility to supply Home Assistant with a syntactically correct automation.

They considered trigger/condition/action ordering important enough to store it that way for automations created via the Automation Editor (even though it’s not required for the YAML interpreter, just for improved legibility).

1 Like

I rarely make mistakes while programming. I wrote it based on how I interpreted the documentation.

Also, let’s be fair. The condition syntax is completely awful and redundant compared to how it would be done in e.g. Lisp.

I have not claimed anything about the order of the properties in the documentation. It’s unfortunate that you talk about things I haven’t said.

The order is created by tooling and that tooling could potentially use a Home Assistant specific backend, but you are literally the only one that is concerned about the order.

The Automation Editor is something nobody is going to use for anything remotely complicated.