How do I troubleshoot an Automation not firing?

Check what they’re changes states from and to versus your trigger. If the trigger is looking for “from off to on” but your entity is going from unavailable to on, it won’t trigger.

If you’re stuck, post the YAML for your automation and a history chart for the entity.

As per my second and third statements, check that your entities are changing to the states your automation is looking for. (as Troon mentioned too).

Post your YAML and we can have a look at what might be the issue.

Thanks all

As I’m digging further, it seems that the problem may be more to do with my scripts rather than the automation. Just before I start posting the YAML, a question about how scripts should work (apologies if this is digressing from the topic header):

  • I was trying to generalise/‘templatise’ the service calls in configuration.yaml for the aircon. ie. I pass the data/parameters specific to the aircon and/or command as a variable to the script. The script then executes according to the variables.
  • The scripts outside of the automation at least appears to work fine.
  • I then noticed that in System/Logs I have warnings: “Running script requires passing in a context”
  • If I restart HA, the aircon would switch on automatically as triggered by the scripts - not the automations, even though there’s no active/conscious command to run the script.

What does the above indicate/mean?

Apart from the scripts question above, looks like the problem could be with the automation itself? This the YAML for the automation that doesn’t trigger itself when I close the door. But if I manually switch on the aircon (via HA), the temperature trigger does work. I have no idea what’s happening here.

(For context, this automation did work properly before but it seems that the change to using scripts above affected the automation’s triggering)

- id: '1684253061907'
  alias: 'Bedroom: AIr Con On'
  description: 'Triggers:

    - Wet Bulb Temperature > target Max Wet Bulb Temperature'
  trigger:
  - platform: numeric_state
    entity_id: sensor.bedroom_wetbulb_temperature
    above: input_number.bedroom_aircon_targettw_max
  condition:
  - condition: and
    conditions:
    - condition: state
      entity_id: input_boolean.bedroom_aircon_climate_control_switch
      state: 'on'
    - condition: state
      entity_id: sensor.bedroom_door_position
      state: close
  action:
  - service: input_boolean.turn_on
    data: {}
    target:
      entity_id: input_boolean.bedroom_aircon_power
  mode: single

Why would it trigger when you close the door? It only has one trigger — that trigger fires at the point when the temperature exceeds the helper setting.

The instant that happens, it checks that the door is closed before running the action, but it’s not sitting there waiting for you to close the door.

Add a trigger for the door and a condition for the temperature, then it’ll trigger off either event but only continue if both are true.

You don’t need the condition: and — conditions are AND by default.

Thanks, I should have been more explicit that there’s another automation that switches the aircon off when a) the door is in the state of ‘left open’ or b) temperate is below the target min temperature

alias: "Bedroom: AIr Con Off"
description: >-
  Triggers:

  - Wet Bulb Temperature < target Min Wet Bulb Temperature; or

  - Door Sensor stated changed to Left Open*


  =============


  * timeOutNotClose state = Left Open state

  time setting for state to change from 'open' to 'timeOutNotClose' is set in
  SwitchBot app

  (could try to set such time setting to zero in SwitchBot app and set the time
  such state is held for in HA to transfer control to HA, but can't change time
  setting to zero - minimum time is 1 minute)
trigger:
  - platform: numeric_state
    entity_id: sensor.bedroom_wetbulb_temperature
    below: input_number.bedroom_aircon_targettw_min
  - platform: state
    entity_id:
      - sensor.bedroom_door_position
    to: timeOutNotClose
condition: []
action:
  - service: input_boolean.turn_off
    data: {}
    target:
      entity_id: input_boolean.bedroom_aircon_power
mode: single

The original intention is that I wanted the aircon to switch on:

  • If (Trigger) temperature > input_number.max_temperature
  • on the condition that:
    a) climate_control_switch is on; and
    b) door is closed

This way when:
a) the temperature is below input_number.min_temperature, the air con switches off; or
b) the door is left open, the air con switches off

In one scenario when the temperature rises back above input_number.max_temperature, the air con should switch on again automatically. But this doesn’t seem to happen because the trigger is door being close?

At the same time if I add another trigger for the temperature > input_number.max_temperature, it doesn’t check if door is closed? (which I understand the Triggers are triggered if any one Trigger is triggered)

I think another way to put it is, I want the aircon automation to trigger as follows:

  1. Switch on aircon if door is close, subject to temperature > temperature_max; or
  2. Switch on aircon if temperature > temperature_max, subject to door is close

Does this necessarily require 2 automations?

You must be careful with your words. You have no trigger on the door being closed. You have a condition that it must be closed for the action to run — and that is an instant evaluation at the moment that the temperature exceeds the threshold. If you shut it later, the aircon won’t switch on because you don’t have a trigger on the door closing.

Here’s what you want — I’m guessing at how your door sensor operates in terms of its state.

  trigger:
    - platform: numeric_state
      entity_id: sensor.bedroom_wetbulb_temperature
      above: input_number.bedroom_aircon_targettw_max
    - platform: state
      entity_id: sensor.bedroom_door_position
      to: close
  condition:
    - condition: numeric_state
      entity_id: sensor.bedroom_wetbulb_temperature
      above: input_number.bedroom_aircon_targettw_max
    - condition: state
      entity_id: input_boolean.bedroom_aircon_climate_control_switch
      state: 'on'
    - condition: state
      entity_id: sensor.bedroom_door_position
      state: close

I see, many thanks. That works as I had intended and has really helped me understand the HA Automation structure.

On a separate but somewhat related topic (apologies if this should be under a separate header), every time I restart HA, all aircons turn on undeliberately.

Logbook gives:
“set_hvac_mode started triggered by service script.set_hvac_mode”

The script is:

sequence:
  - service: rest_command.switchbot_irdevice_command
    data_template:
      deviceId: "{{ aircon_deviceId }}"
      command: |
        {% if aircon_hvac_mode == "auto" %}
          one touch
        {% else %}
          power off
        {% endif %}
      parameter: default
      commandType: customize
alias: set_hvac_mode
mode: queued
max: 10

aircon_hvac_mode is (should be) determined by user input in the template below:

climate:
  - platform: climate_template
    name: Bedroom
    unique_id: Bedroom

    hvac_mode_template: >
      {% if states('input_boolean.bedroom_aircon_power') == "on" %}
        auto
      {% else %}
        off
      {% endif %}

    set_hvac_mode:
      - service: script.set_hvac_mode
        data:
          aircon_deviceId: !secret bedroom_aircon_deviceId
          aircon_hvac_mode: "{{ hvac_mode }}"

Appreciate any pointers to help me troubleshoot why the script is calling set_hvac_mode automatically without any user input

You must have an automation somewhere calling the script: set_hvac_mode upon HA startup, or when some entity becomes available upon HA startup. Is that input_boolean ON at startup?

no re a script, automation and input_boolean, or at least none that’s apparent to me.

would there happen to be some function in HA that let’s me trace what exactly is happening during HA startup?

Your logs / history logbook should show you

finally found it, partly due to having scripts set on ‘queue’ rather than ‘single’ during troubleshooting and partly due to misreading of some code

thanks again all for your help

Thanks so much for this checklist. I have a situation where checking the config doesn’t return any error, yet reloading automations or all YAML or even restarting HA doesn’t load the automation at all - no trace of it in home-assistant.log or in the automations or the states pages. I deleted all the other automations from automations.yaml and this one still doesn’t load.

Any idea, please, what else to check? Thanks a lot!

LE: I managed to find a solution - the very last paragraph on this page: Splitting up the configuration - Home Assistant

1 Like