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 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.
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:
Switch on aircon if door is close, subject to temperature > temperature_max; or
Switch on aircon if temperature > temperature_max, subject to door is close
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:
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?
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!