Please check my first automation yaml

Hi there,

My first automation… So the idea is for the AC to turn on when:

Conditions:

  1. The room temperature is above 25.5C for 15sec
  2. This would only trigger between the hours of 08:00-22:55
  3. Device 1 & Device 2 are “home”
/trigger:
  - platform: numeric_state
    entity_id: sensor.AC_lr_temperature
    above: 25.5
    for:
      hours: 0
      minutes: 0
      seconds: 15
condition:
  - condition: and
    conditions:
      - condition: time
        after: "08:00:00"
        before: "22:55:00"
      - condition: device
        device_id: 1(id here)
        domain: device_tracker
        entity_id: yxyxyxyxyx (id here)
        type: is_home
      - condition: device
        device_id: 2 (id here)
        domain: device_tracker
        entity_id: xyxyxyxyxyx (id here)
        type: is_home
action:
  - device_id: AC ID
    domain: climate
    entity_id: AC entity ID
    type: set_hvac_mode
    hvac_mode: auto
mode: single

Does it look correct?

Thank you

I’m not sure where you are editing that, is it just a text editor and you are playing with concepts? Several things in your automation aren’t real (was this ChatGPT or something?). Also, using device ID’s is generally a bad idea for future maintenance unless there’s just no way to get the trigger you want from an entity state.

trigger:
  - platform: numeric_state
    entity_id: sensor.AC_lr_temperature
    above: 25.5
    for:
      hours: 0
      minutes: 0
      seconds: 15
condition:
  - condition: and
    conditions:
      - condition: time
        after: "08:00:00"
        before: "22:55:00"
      - condition: state
        entity_id: yxyxyxyxyx (id here)
        state: (state you want to constrain with)
      - condition: state
        entity_id: xyxyxyxyxyx (id here)
        state: (state you want to constrain with)
action:
  - service: climate.set_hvac_mode
    data:
      hvac_mode: auto
    target:
      entity_id: xyxyxyxyxyx (id here)
mode: single

There’s a / before trigger. Typo when creating the post?

Why do two devices need to be home at the same time? Is this one person or are you checking for two? It is better to test for the state of zone.home to be above 0 if you want “some one is home”. Tracking two devices for one person is tricky, especially if you do not always take both with you. It can be done, but we’d need to know more to get it right.

You don’t need the and condition block. And is the default for the conditions in the conditions list.

Also, what if you come home while it is already hot? Or it is already hot at 8:00? You need more triggers. Here’s a good read about it, be sure to read to the end:

Hi, thank you for your answer. As posted this was my first ever attempt. If you are referring to my entity_id: yxyxyxyxyx (id here), entity_id: xyxyxyxyxyx (id here) etc, yes, I wasn’t sure if I should post the Id’s here so I replaced them with xx, yy… etc

The code I posted should be usable for your needs. I have similar use cases myself where I want both my wife and I to be home to trigger something.

Id’s are not a security issue. But device triggers, conditions and actions are wise to avoid for many reasons. There’s more on that here:

Thank you, yes, that is exactly the case here… Hmm, the intent was to have one or the other or both be home :frowning:

Then I was right, and you should test zone.home to be above 0. It counts the number of people in the zone. You could also use an or with the trackers, but that is harder to maintain should you ever change device, or increase the number of persons in your household.

Great, thank you… I will read what you suggested.

Have you thought about what to do when the first person comes home and it is already hot? This automation will not set AC to auto the way it is now. The automation should be set up something like:

Triggers (one of these things happen):

  • temperature rises above 25.5
  • the first person arrives home
  • it is 8:00 in the morning

Conditions (these things should all be the case):

  • temperature is above 25.5
  • someone is home
  • it is between 8:00 and 22:55

Action:

  • Set AC to auto

lol… no I have not :slight_smile: The learning process has started…
Thank you

I gave more hints by editing the above post. This is one of the most crucial things to understand, once you do you’re half way there.

Thank you… my second attempt according to your hints… (I hope I understood them)

alias: Test AC
description: ""
trigger:
  - platform: numeric_state
    entity_id:
      - sensor.cielo_lr_temperature
    above: 25.5
  - platform: numeric_state
    entity_id:
      - zone.home
    above: 0
  - platform: time
    at: "08:00:00"
condition:
  - condition: numeric_state
    entity_id: sensor.cielo_lr_temperature
    above: 25.5
  - condition: numeric_state
    entity_id: zone.home
    above: 0
  - condition: time
    after: "08:00:00"
    before: "22:55:00"
action:
  - device_id: b4d5fbf2c08806212f5fefa46fba61b0
    domain: climate
    entity_id: 115fcdf43930ea395adc396086122b97
    type: set_hvac_mode
    hvac_mode: cool
mode: single

Perfect! You could have kept the for: if you wanted, but this will work just fine.

Yay… :-)… Thank you!

What do you mean by “You could have kept the for: if you wanted”?

1 Like

In your first example, you wanted the temperature above 25.5 “for” 15 seconds.

Aha… I was not exactly sure what that will do so I entered 15sec to try and see. Does that mean that the sensor temperature have to be above 25.5 for at least 15sec?

Right again. You’ll get there fast :slight_smile: In a trigger it is exactly that time, in a condition it is at least that time. Very useful for situations like: if there’s no motion for 2 mins, turn the light off.

Alright… thank you so much… lot’s for me to read