Basic Temperature Automation Not Working

Having trouble with a basic temperature trigger. Have a fan that I want to turn on when the temperature gets above a certain point in my office and have the following automation yaml (I used the visual tool and this is the output):

alias: Office Fan
description: Activates fan in office when temperature gets too high.
trigger:
  - platform: numeric_state
    entity_id: sensor.office_temperature
    above: '70'
condition:
  - condition: device
    type: is_off
    device_id: 06815a34d2ce252a289bbbab50080b0b
    entity_id: switch.office_fan_on_off
    domain: switch
    for:
      hours: 0
      minutes: 5
      seconds: 0
      milliseconds: 0
action:
  - type: turn_on
    device_id: 06815a34d2ce252a289bbbab50080b0b
    entity_id: switch.office_fan_on_off
    domain: switch
mode: single

If I just run the action the fan turns on just fine. Then if I go into the developer tools and set the state of sensor.office_temperature to something ridiculous like 90, I get the following in my debug-level-logs:

2021-03-27 03:07:17 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=sensor.office_temperature, old_state=<state sensor.office_temperature=78.4; unit_of_measurement=Ā°F, friendly_name=Office Temperature, device_class=temperature @ 2021-03-27T03:00:15.287506-04:00>, new_state=<state sensor.office_temperature=90; unit_of_measurement=Ā°F, friendly_name=Office Temperature, device_class=temperature @ 2021-03-27T03:07:17.193697-04:00>>
2021-03-27 03:07:17 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection] [2861361880] Sending {"id": 90, "type": "event", "event": {"event_type": "state_changed", "data": {"entity_id": "sensor.office_temperature", "old_state": {"entity_id": "sensor.office_temperature", "state": "78.4", "attributes": {"unit_of_measurement": "\u00b0F", "friendly_name": "Office Temperature", "device_class": "temperature"}, "last_changed": "2021-03-27T07:00:15.287506+00:00", "last_updated": "2021-03-27T07:00:15.287506+00:00", "context": {"id": "52a408ea23e32df30760df8f8d4369f0", "parent_id": null, "user_id": null}}, "new_state": {"entity_id": "sensor.office_temperature", "state": "90", "attributes": {"unit_of_measurement": "\u00b0F", "friendly_name": "Office Temperature", "device_class": "temperature"}, "last_changed": "2021-03-27T07:07:17.193697+00:00", "last_updated": "2021-03-27T07:07:17.193697+00:00", "context": {"id": "8882b5e041a8143186d38e9a3d553b5a", "parent_id": null, "user_id": "8a32d8373d2e4546b3897391b84226b0"}}}, "origin": "LOCAL", "time_fired": "2021-03-27T07:07:17.193697+00:00", "context": {"id": "8882b5e041a8143186d38e9a3d553b5a", "parent_id": null, "user_id": "8a32d8373d2e4546b3897391b84226b0"}}}
2021-03-27 03:07:17 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection] [2922715792] Sending {"id": 30, "type": "event", "event": {"event_type": "state_changed", "data": {"entity_id": "sensor.office_temperature", "old_state": {"entity_id": "sensor.office_temperature", "state": "78.4", "attributes": {"unit_of_measurement": "\u00b0F", "friendly_name": "Office Temperature", "device_class": "temperature"}, "last_changed": "2021-03-27T07:00:15.287506+00:00", "last_updated": "2021-03-27T07:00:15.287506+00:00", "context": {"id": "52a408ea23e32df30760df8f8d4369f0", "parent_id": null, "user_id": null}}, "new_state": {"entity_id": "sensor.office_temperature", "state": "90", "attributes": {"unit_of_measurement": "\u00b0F", "friendly_name": "Office Temperature", "device_class": "temperature"}, "last_changed": "2021-03-27T07:07:17.193697+00:00", "last_updated": "2021-03-27T07:07:17.193697+00:00", "context": {"id": "8882b5e041a8143186d38e9a3d553b5a", "parent_id": null, "user_id": "8a32d8373d2e4546b3897391b84226b0"}}}, "origin": "LOCAL", "time_fired": "2021-03-27T07:07:17.193697+00:00", "context": {"id": "8882b5e041a8143186d38e9a3d553b5a", "parent_id": null, "user_id": "8a32d8373d2e4546b3897391b84226b0"}}}

But no errors and no mention of the automation, switch, anything.

Iā€™m at a loss. I tried messing around with using a template trigger along the lines of:

{{ (states("sensor.office_temperature") | float) < 70 }}

and still no-go. Any insight is appreciated; I have no clue what Iā€™m doing wrong. I even had this setup before just fine but I upgraded from a Pi 3 to a Pi 4 and did a reinstall of HA. Current version info:

core-2021.3.4
supervisor-2021.03.6

Thanks in advance for anyhelp!

Hi there, Please change the condition to this and try.

condition:
  - condition: state
    entity_id: switch.office_fan_on_off
    state: 'off'
    for: '00:05:00'

For the trigger to trigger, the office temperature needs to be under 70 and then go above 70.
From your logs, temperature was at 78.4 so already above 70 when you set it to 90.

Thatā€™s not going to trigger your automation. A numeric_state trigger only fires when the entity crosses the threshold: in this case, from below to above 70 freedom units. Your ā€œbeforeā€ temperature was already above the threshold.

EDIT: just beaten to it by @makai :unamused:

1 Like