Creating an IF Statement or Multiple Automations aren't Working

Hello, I created multiple automations to set my thermostat based on the outside temperature. When I click on Execute for each automation, they are completing the actions requested. However, once the conditions are met, the automations are not executing.

I think I would be better off with an IF statement, but I can’t seem to figure that out either. I haven’t taken programming in over 10 years, so that leaves me with understanding what I’m needing but clueless on how to make this.

Would someone be able to either help me figure out why any of these multiple automations are not running when their conditions are met or help me create the correct IF statement.

 id: '1591843203331'
  alias: Air at 75
  description: Sets the air at 75 when it's 82 outside.
  trigger:
  - platform: template
    value_template: '{{(state_attr(''climate.home'',''current_temperature''))}}'
  condition:
  - condition: template
    value_template: '{{(state_attr(''climate.home'',''current_temperature''|int)==82|int)}}'
  - condition: and
    conditions:
    - condition: template
      value_template: '{{(state_attr(''climate.home'',''preset_modes'')!=''away'')}}'
    - condition: or
      conditions:
      - condition: template
        value_template: '{{(state_attr(''climate.home'',''preset_modes'')!=''sleep'')}}'
  action:
  - data:
      hvac_mode: heat_cool
      target_temp_high: 75
      target_temp_low: 69
    entity_id: climate.home
    service: climate.set_temperature
  - data:
      fan_mode: 'on'
    entity_id: climate.home
    service: climate.set_fan_mode
- id: '1592187904943'
  alias: Air at 76
  description: Sets the air at 76 when it's 83 outside.
  trigger:
  - platform: template
    value_template: '{{(state_attr(''climate.home'',''current_temperature''))}}'
  condition:
  - condition: template
    value_template: '{{(state_attr(''climate.home'',''current_temperature''|int)==83|int)}}'
  - condition: and
    conditions:
    - condition: template
      value_template: '{{(state_attr(''climate.home'',''preset_modes'')!=''away'')}}'
    - condition: or
      conditions:
      - condition: template
        value_template: '{{(state_attr(''climate.home'',''preset_modes'')!=''sleep'')}}'
  action:
  - data:
      hvac_mode: heat_cool
      target_temp_high: 76
      target_temp_low: 69
    entity_id: climate.home
    service: climate.set_temperature
- id: '1592190145589'
  alias: Air at 77
  description: Sets the air at 77 when it's 84 outside.
  trigger:
  - platform: template
    value_template: '{{(state_attr(''climate.home'',''current_temperature''))}}'
  condition:
  - condition: template
    value_template: '{{(state_attr(''climate.home'',''current_temperature''|int)==84|int)}}'
  - condition: and
    conditions:
    - condition: template
      value_template: '{{(state_attr(''climate.home'',''preset_modes'')!=''away'')}}'
    - condition: or
      conditions:
      - condition: template
        value_template: '{{(state_attr(''climate.home'',''preset_modes'')!=''sleep'')}}'
  action:
  - data:
      hvac_mode: heat_cool
      target_temp_high: 77
      target_temp_low: 69
    entity_id: climate.home
    service: climate.set_temperature
  - data:
      fan_mode: 'on'
    entity_id: climate.home
    service: climate.set_fan_mode
- id: '1592190826693'
  alias: Air at 78
  description: Sets the air at 78 when it's 85 outside.
  trigger:
  - platform: template
    value_template: '{{(state_attr(''climate.home'',''current_temperature''))}}'
  condition:
  - condition: template
    value_template: '{{(state_attr(''climate.home'',''current_temperature''|int)==85|int)}}'
  - condition: and
    conditions:
    - condition: template
      value_template: '{{(state_attr(''climate.home'',''preset_modes'')!=''away'')}}'
    - condition: or
      conditions:
      - condition: template
        value_template: '{{(state_attr(''climate.home'',''preset_modes'')!=''sleep'')}}'
  action:
  - data:
      hvac_mode: heat_cool
      target_temp_high: 78
      target_temp_low: 69
    entity_id: climate.home
    service: climate.set_temperature
  - data:
      fan_mode: 'on'
    entity_id: climate.home
    service: climate.set_fan_mode
- id: '1592191106126'
  alias: Air at 79
  description: Sets the air at 79 when it's 86 outside.
  trigger:
  - platform: template
    value_template: '{{(state_attr(''climate.home'',''current_temperature''))}}'
  condition:
  - condition: template
    value_template: '{{(state_attr(''climate.home'',''current_temperature''|int)==86|int)}}'
  - condition: and
    conditions:
    - condition: template
      value_template: '{{(state_attr(''climate.home'',''preset_modes'')!=''away'')}}'
    - condition: or
      conditions:
      - condition: template
        value_template: '{{(state_attr(''climate.home'',''preset_modes'')!=''sleep'')}}'
  action:
  - data:
      hvac_mode: heat_cool
      target_temp_high: 79
      target_temp_low: 69
    entity_id: climate.home
    service: climate.set_temperature
  - data:
      fan_mode: 'on'
    entity_id: climate.home
    service: climate.set_fan_mode
- id: '1592191936289'
  alias: Air at 80
  description: Sets the air at 80 when it's warmer than 86 outside.
  trigger:
  - platform: template
    value_template: '{{(state_attr(''climate.home'',''current_temperature''))}}'
  condition:
  - condition: template
    value_template: '{{(state_attr(''climate.home'',''current_temperature''|int)>86|int)}}'
  - condition: and
    conditions:
    - condition: template
      value_template: '{{(state_attr(''climate.home'',''preset_modes'')!=''away'')}}'
    - condition: or
      conditions:
      - condition: template
        value_template: '{{(state_attr(''climate.home'',''preset_modes'')!=''sleep'')}}'
  action:
  - data:
      hvac_mode: heat_cool
      target_temp_high: 80
      target_temp_low: 69
    entity_id: climate.home
    service: climate.set_temperature
  - data:
      fan_mode: 'on'
    entity_id: climate.home
    service: climate.set_fan_mode
- id: '1592192445564'
  alias: That Normal Air
  description: Resume's the Ecobee Programming
  trigger:
  - platform: template
    value_template: '{{(state_attr(''climate.home'',''current_temperature''))}}'
  condition:
  - condition: template
    value_template: '{{(state_attr(''climate.home'',''current_temperature''|int)<82|int)}}'
  - condition: and
    conditions:
    - condition: template
      value_template: '{{(state_attr(''climate.home'',''preset_modes'')!=''away'')}}'
    - condition: or
      conditions:
      - condition: template
        value_template: '{{(state_attr(''climate.home'',''preset_modes'')!=''sleep'')}}'
  action:
  - data: {}
    service: ecobee.resume_program

When you execute an automation that way, it skips the trigger and condition sections and simply runs the action.

If you go to Developer Tools > Services and use automation.trigger, there’s an option (skip_condition) to control if the condition is used or not.

Trigger the action of an automation.

Parameter Description Example
entity_id Name of the automation to trigger. automation.notify_home
skip_condition Whether or not the condition will be skipped (defaults to True). true
1 Like

I don’t think you have your conditions coded correctly.

Maybe if you describe in words what you want the conditions to be someone might be able to figure out how they need to be written.

As mentioned there are a few errors in your current attempt which are preventing the automations from running. Rather than go into those, I think a much simpler implementation can do what I think you want. Give this a try. Let me know if you have any questions.

But first. In your description you say the thermostat set point is set based on outside temperature. But I’m pretty sure the current_temperature attribute is the inside temperature. I use Nest not ecobee, so I guess I’m not 100% sure, but I’m at least 99.44% sure. :wink: So what attribute of climate.home, or other entity, indicates the outside temperature? In the examples below, I’ll use a made up entity (sensor.outside_temp); just replace accordingly.

Automation to change set point and turn on fan:

- description: Sets the air appropriately when it's 82 or more outside.
  trigger:
  # Trigger whenever outside temp changes.
  - platform: state
    entity_id: sensor.outside_temp
  condition:
  # Only run if outside temp is 82 or above and not in away or sleep mode.
  - condition: template
    value_template: >
      {{ trigger.to_state.state|float >= 82 and
         state_attr('climate.home', 'preset_mode') not in ['away', 'sleep'] }}
  action:
  # Set upper limit to current temp - 7 degrees.
  - service: climate.set_temperature
    entity_id: climate.home
    data_template:
      hvac_mode: heat_cool
      target_temp_high: "{{ trigger.to_state.state|float - 7 }}"
      target_temp_low: 69
  # Turn on fan.
  - service: climate.set_fan_mode
    entity_id: climate.home
    data:
      fan_mode: 'on'

Automation to resume programming:

- description: Resume the ecobee programming.
  trigger:
  # Trigger when outside temp falls below 82.
  - platform: numeric_state
    entity_id: sensor.outside_temp
    below: 82
  condition:
  # Only run if not in away or sleep mode.
  - condition: template
    value_template: >
      {{ state_attr('climate.home', 'preset_mode') not in ['away', 'sleep'] }}
  action:
  - service: ecobee.resume_program

@pnbruckner guessed what I was trying to do. I have a max target limit for my Ecobee, but As it gets a bit warmer outside, I’m wanting to raise the temp. It’s mostly just because I’m cheap and have enough fans if it gets up to 80 in my home. My goal is to have the air set 7 degrees lower than the outside temp.

Thank you for your reply.

You were right that I shouldn’t be using climate.home for the outside temp. I’m not sure why I did that. I should be using weather.home. However I can’t use the state and instead have to use the attribute of, temperature.

I don’t understand the “trigger.to_state.state” part of your solution. I can also confirm it isn’t working lol. In the developer logs, the automations couldn’t be loaded. This is what I tried, but I couldn’t get it to work either.

- id: '1592190826693'
  alias: Air at 78
  description: Sets the air at 78 when it's 85 outside.
  trigger:
  - platform: template
    value_template: '{{(state_attr(''weather.home'',''temperature''))}}'
  condition:
  - condition: template
    value_template: '{{(state_attr(''weather.home'',''temperature''|float)==85)}}'
  - condition: and
    conditions:
    - condition: template
      value_template: '{{(state_attr(''climate.home'',''preset_modes'')!=''away'')}}'
    - condition: or
      conditions:
      - condition: template
        value_template: '{{(state_attr(''climate.home'',''preset_modes'')!=''sleep'')}}'
  action:
  - data:
      hvac_mode: heat_cool
      target_temp_high: {{(state_attr(''weather.home'',''temperature'')|float)-7}}
      target_temp_low: 69
    entity_id: climate.home
    service: climate.set_temperature
  - data:
      fan_mode: 'on'
    entity_id: climate.home
    service: climate.set_fan_mode

I receive this error in my Developer Logs: “invalid key: “OrderedDict([(”(state_attr(’‘weather.home’’’‘temperature’’)|float-7)”, None)])" in “/config/automations.yaml”, line 161, column 0" Line 161 is the value for target_temp_high:

Ignore the current name and description of this.

Here are the state attributes of climate.home:

hvac_modes:
  - heat_cool
  - heat
  - cool
  - 'off'
min_temp: 45
max_temp: 95
fan_modes:
  - auto
  - 'on'
preset_modes:
  - Home
  - Away
  - Sleep
  - WFH PM
  - WFH AM
current_temperature: 74
temperature: null
target_temp_high: 74
target_temp_low: 69
current_humidity: 56
fan_mode: 'on'
hvac_action: fan
preset_mode: Home
aux_heat: 'off'
fan: 'on'
climate_mode: Home
equipment_running: fan
fan_min_on_time: 0
friendly_name: Home
supported_features: 91

Here are the state attributes of weather.home:

temperature: 85
humidity: 36
pressure: 1015
wind_bearing: 58
wind_speed: 7
visibility: 16
attribution: 'Ecobee weather provided by FI:KFWA at 2020-06-18 23:34:49 UTC'
forecast:
  - datetime: '2020-06-19T00:00:00'
    condition: sunny
    temperature: 88
    templow: 65
    wind_bearing: 36
    wind_speed: 2
  - datetime: '2020-06-20T00:00:00'
    condition: sunny
    temperature: 90
    templow: 68
    wind_bearing: 201
    wind_speed: 5
  - datetime: '2020-06-21T00:00:00'
    condition: partlycloudy
    temperature: 88
    templow: 71
    wind_bearing: 224
    wind_speed: 11
  - datetime: '2020-06-22T00:00:00'
    condition: rainy
    temperature: 88
    templow: 69
    wind_bearing: 212
    wind_speed: 9
friendly_name: Home

Just add an initial alias to pnbruckner’s example.

- alias: 'A name of your choosing goes here'
  description: Sets the air appropriately when it's 82 or more outside.
  trigger:
  - platform: state
    entity_id: sensor.outside_temp
  condition:
  # Only run if outside temp is 82 or above and not in away or sleep mode.
  - condition: template
    value_template: >
      {{ trigger.to_state.state|float >= 82 and
         state_attr('climate.home', 'preset_mode') not in ['away', 'sleep'] }}
  action:
  - service: climate.set_temperature
    entity_id: climate.home
    data_template:
      hvac_mode: heat_cool
      target_temp_high: "{{ trigger.to_state.state|float - 7 }}"
      target_temp_low: 69
  - service: climate.set_fan_mode
    entity_id: climate.home
    data:
      fan_mode: 'on'

The latest example you posted contains several syntax errors.

That is nothing like I suggested. You reintroduced many of your original errors.

Try this (where I substituted the temperature attribute of weather.home):

- description: Sets the air appropriately when it's 82 or more outside.
  trigger:
  # Trigger whenever outside temp changes.
  - platform: state
    entity_id: weather.home
  condition:
  # Only run if outside temp is 82 or above and not in away or sleep mode.
  - condition: template
    value_template: >
      {{ trigger.to_state.attributes.temperature >= 82 and
         state_attr('climate.home', 'preset_mode') not in ['away', 'sleep'] }}
  action:
  # Set upper limit to current temp - 7 degrees.
  - service: climate.set_temperature
    entity_id: climate.home
    data_template:
      hvac_mode: heat_cool
      target_temp_high: "{{ trigger.to_state.attributes.temperature - 7 }}"
      target_temp_low: 69
  # Turn on fan.
  - service: climate.set_fan_mode
    entity_id: climate.home
    data:
      fan_mode: 'on'

And:

- description: Resume the ecobee programming.
  trigger:
  # Trigger when outside temp falls below 82.
  - platform: numeric_state
    entity_id: weather.home
    value_template: "{{ state.attributes.temperature }}"
    below: 82
  condition:
  # Only run if not in away or sleep mode.
  - condition: template
    value_template: >
      {{ state_attr('climate.home', 'preset_mode') not in ['away', 'sleep'] }}
  action:
  - service: ecobee.resume_program
1 Like

So I can confirm this worked. I don’t understand quite how it works. I had build some other automations for my ceiling fan based on temperatures, and they are different. I’ll continue to keep trying to review this and other examples until I understand this more.

My first examples of this thread were built off of my other automations. They work, but now I’m not sure if they’re following best practices. When I was trying to modify your example for my system last night, I was confused and concerned because I was getting null values in the GUI and when using the code editor, it also seemed to be giving me values I didn’t think belonged.

Thank you very much for your help. I really appreciate your effort.

-Paul