Simple automation not triggering

Hi community.
sorry if it’s not the right forum for that kind of question.

I just tried to set up my first very simple automation using the visual editor. Just triggering the AC when insinde temperature above 21 C. The problem is, it is not triggering. If I test it manually, the AC starts so I think the action is correct but the trigger is not evaluated. Copied as YAML:

alias: Test
description: ''
trigger:
  - type: temperature
    platform: device
    device_id: a3f6afd9854bdd8df4ce64b78db64c8c
    entity_id: sensor.daikin_schlafz_inside_temperature
    domain: sensor
    above: 21
condition: []
action:
  - device_id: a3f6afd9854bdd8df4ce64b78db64c8c
    domain: climate
    entity_id: climate.daikin_schlafz
    type: set_hvac_mode
    hvac_mode: cool
mode: single

Can you see whats wrong?

Thank you!

The temperature has to cross from below 21 to above 21 to trigger. If it is already above 21 it wont trigger.

1 Like

Hi Tom,
omg that sounds pretty obvious :see_no_evil:
I will validate this.
Thank you very much!
BR

Here’s an update to work around this:

alias: Test
description: ''
trigger:
  - platform: numeric_state
    entity_id: sensor.daikin_schlafz_inside_temperature
    above: 21
  - platform: homeassistant
    event: start
  - platform: event
    event_type: automation_reloaded
condition:
  - condition: numeric_state
    entity_id: sensor.daikin_schlafz_inside_temperature
    above: 21
action:
  - device_id: a3f6afd9854bdd8df4ce64b78db64c8c
    domain: climate
    entity_id: climate.daikin_schlafz
    type: set_hvac_mode
    hvac_mode: cool
mode: single

This triggers when the temperature crosses the threshold or when the system or automation is restarted, and the condition ensures that the AC isn’t turned on when triggered by a restart when it’s cold.

I’ve also changed your initial trigger from a device to an entity trigger, as it’s easier when manually editing, although this is just personal preference.

1 Like

As an optional refinement, I would add a second condition that checks if the thermostat’s current state is not cool. That will prevent needlessly setting the thermostat to cool when it’s already in that mode (which can happen if the temperature continues to increase above the threshold value or on startup/reload).

  - "{{ states('climate.daikin_schlafz') != 'cool' }}"

EDIT

Correction. Removed first of two conditions because it was mistakenly copied here from another automation that didn’t employ triggers for startup/reload.

1 Like

What will your first condition do if the trigger is a restart?

1 Like

It’ll fail. :slight_smile:

I was composing an automation similar to yours when you posted your more complete version that handles startup/reloads. I blindly copy-pasted the conditions I already had without considering that the first one will now be subjected to startup/reload. I’ll remove it from my previous post.

1 Like

Thank you very much! This is really a great community! I just found HA by coincidence a week ago.

I know combined the answers from Troon an Taras and have:

alias: Test
description: ''
trigger:
  - platform: numeric_state
    entity_id: sensor.daikin_schlafz_inside_temperature
    above: '21'
  - platform: homeassistant
    event: start
  - platform: event
    event_type: automation_reloaded
condition:
  - condition: template
    value_template: '{{ states(''climate.daikin_schlafz'') != ''cool'' }}'
  - condition: numeric_state
    entity_id: sensor.daikin_schlafz_inside_temperature
    above: '21'
action:
  - device_id: a3f6afd9854bdd8df4ce64b78db64c8c
    domain: climate
    entity_id: climate.daikin_schlafz
    type: set_hvac_mode
    hvac_mode: cool
mode: single

That seems to work really good :slight_smile:

If I’d like to add another condition having it fire (or cool be correct :slight_smile: ) only between a certain time, would this be correct?

alias: Test
description: ''
trigger:
  - platform: numeric_state
    entity_id: sensor.daikin_schlafz_inside_temperature
    above: '21'
  - platform: homeassistant
    event: start
  - platform: event
    event_type: automation_reloaded
condition:
  - condition: template
    value_template: '{{ states(''climate.daikin_schlafz'') != ''cool'' }}'
  - condition: time
    after: '17:00:00'
    before: '06:00:00'
  - condition: numeric_state
    entity_id: sensor.daikin_schlafz_inside_temperature
    above: '21'
action:
  - device_id: a3f6afd9854bdd8df4ce64b78db64c8c
    domain: climate
    entity_id: climate.daikin_schlafz
    type: set_hvac_mode
    hvac_mode: cool
mode: single

so it will only trigger between 17:01 and 5:59 in the morning, right?

Thanky you!!

1 Like

Almost.

Add a time trigger in case it is already above 21° when it turns 5pm.

trigger:
  - platform: numeric_state
    entity_id: sensor.daikin_schlafz_inside_temperature
    above: '21'
  - platform: homeassistant
    event: start
  - platform: event
    event_type: automation_reloaded
  - platform: time
    at: '17:00:01'

This always fires at (a second after) 5pm but you already have a condition to make sure the temperature is above 21° before running the actions.

2 Likes

Hi Tom,
just for understanding purposes… The way I did using a condition it won’t trigger if at 5pm the temperature is already above 21 degrees, right?

Having it as part of the trigger solves this issue. This would also trigger not only exactly 17:00:01 but also after 5 pm? How could I then also limit the rule to not trigger after e.g. 10 pm? Time-trigger seems to offer only “at” rules not before-after like the conditions do.

Correct. Conditions are only evaluated after the trigger occurs.

The way it is at the moment if it is already 21° at 5pm the time trigger starts your automation. And the conditions are then checked to make sure it is above 21°.

If it is below 21° but goes above 21° at any time the numeric_state trigger starts your automation, then the conditions are evaluated to see if it is between 5pm and 6am. If you want it to not occur after 10 pm change your time condition,

  - condition: time
    after: '17:00:00'
    before: '22:00:00'
1 Like

Thank you very much, think now I got it. Did also some reading during the weekend about automation with HA.

It works really well now. For documentation purposes I’d like to share the actual / final yaml:

alias: Start Daikin cooling when hot evening
description: ''
trigger:
  - platform: numeric_state
    entity_id: sensor.daikin_schlafz_inside_temperature
    above: '21'
  - platform: homeassistant
    event: start
  - platform: event
    event_type: automation_reloaded
  - platform: time
    at: '16:00:01'
condition:
  - condition: time
    after: '16:00:00'
    before: '22:00:00'
  - condition: template
    value_template: '{{ states(''climate.daikin_schlafz'') != ''cool'' }}'
  - condition: numeric_state
    entity_id: sensor.daikin_schlafz_inside_temperature
    above: '21'
action:
  - device_id: a3f6afd9854bdd8df4ce64b78db64c8c
    domain: climate
    entity_id: climate.daikin_schlafz
    type: set_hvac_mode
    hvac_mode: cool
mode: single
1 Like

For future reference, if you use shorthand notation for Template Conditions, you can replace this:

  - condition: template
    value_template: '{{ states(''climate.daikin_schlafz'') != ''cool'' }}'

with this:

  - '{{ states(''climate.daikin_schlafz'') != ''cool'' }}'
1 Like

or even less quote-fusing

- >
  {{ states('climate.daikin_schlafz') != 'cool' }}
3 Likes