Help setting up automation involving HVAC, security system and outdoor temperature sensors

hello!

I’m trying to set up an automation but I’m not sure what is the best way to approach this so im reaching out.

Here’s what I would like to do:

If a window and/or door is kept open for more than 10 minutes and if the outdoor temperature is less than +13oC or more than 24oC, I want the HVAC (whether in cooling or heating mode i.e. winter or summer) to turn off and send a warning that this is the case

Here’s what I have:

  • a security system with door and window contacts reporting to HA (through an integration) via sensors
  • a thermostat reporting to HA through an integration
  • a local (in my backyard) weather station reporting directly to HA

Thanks to the community help (especially @ Didgeridrew), I have a similar type automation here based on distance from home, it changes the temperature as we leave and/or approach the home.

Now its a bit different, so I have some questions:

  1. Should I group my door and window contacts into one (there’s about 20 of them reporting), and thus it could make the condition easier (like all true or all false if one or more sensors (door or window) is opened)?

  2. As for the thermostat, its integrated via American Standard/Trane and the entities it reports are system status (fan running, waiting, cooling, heating, idle), and mode (heat, cool, off, heat/cool, off) etc. There are other entities reporting, I don’t know if “current system status” is required, but suspect that “mode” would be needed for this automation, for example, whether its in heat or cool, if the condition is met, change the mode to “OFF” and send a message.

  3. How do I incorporate a time of 10 minutes before the condition does anything? For example, opening a window or door briefly (less than 10 minutes), should not turn off the HVAC.

  4. EDIT: another condition could be, if the outdoor temperature is at an extreme, for example, having a window open when the outdoor temperature is less than +13oC or more than +24oC, this automation should trigger (i.e. turn OFF the HVAC), but if a window/door is open between those outdoor temperatures for more than 10 minutes, perhaps just a warning message should be sent. The reason I say this is because well sometimes my wife likes to keep the windows open but she would never keep them open for hours if the outdoor temperatures are below +13oC and above +24oC. Perhaps a condition of this sort, should also be included. I have several outdoor temperature sensors reporting to HA that can be used for this condition (from my local weather station, for example).

Any ides as to how to set this up? I can paste some yaml once I have some direction as to how to set this up…did I miss anything?

thanks

1 & 3. Yes, groups are great. The window/door sensors (or group) turning ‘on’ should be your trigger (or one of your triggers). State, Numeric State, and Device triggers types allow you to add a for: variable to handle the question of how long it must be open before the automation triggers.

2. For what you have described, this will be a condition.

4 & 3. You can use two Numeric State triggers to track the temperature and trigger when it passes your set points (this is also a good place to use the for: variable so don’t get an excessive number of notifications if the temperature is hovering around your set point). When you use multiple triggers for an automation like this, you can use matching conditions in the Condition section or in your a Choose action so you know all your requirements are met when the actions are executed.

Example Trigger w/ 'global' Conditions

This is part of an automation to have Alexa make and announcement. It triggers on either a window being opened or the HVAC mode changing to anything but ‘off’.

trigger:
  - platform: state
    id: HVAC
    entity_id: climate.centralite_thermostat
    from: 'off'
    to:
      - heat
      - cool
      - heat_cool
  - platform: state
    id: Window
    entity_id: group.all_window_sensors
    to: 'on'
condition:
  - condition: state
    entity_id: binary_sensor.house_occupied
    state: 'on'
  - condition: state
    entity_id: climate.centralite_thermostat
    state:
      - heat
      - cool
      - heat_cool
  - condition: state
    entity_id: group.all_window_sensors
    state: 'on'

FYI:
Climate control is a great place to implement scripts. The logic can get as complicated as you want to make it and there are often groups of actions that you will want to use mulitple times.

Once you have your automation set up, if you are interested in taking it a step further, this is also a good place to use Actionable Notifications. Instead of just turning the HVAC off, notify the person and give them options like “Ignore”, “Turn Off HVAC” and/or “Turn On Fan Only”.

Thanks and awesome!

Im going to try and set this up and post my yaml here.

With regards to Actionable Notifcation, this is really cool. What if no answer is received? i.e. if we don’t have our phones on us? I presume it can be set to default to a certain action after a short time?

Yes, you can include a timeout so that your automation executes a specific action if no one responds to the notification within a certain amount of time.

Here’s my first attempt at this.

First I created a group in my configration.yaml for all my door and window contacts:

binary_sensor:
   # Door and Window Contact Sensor
  - platform: group
    name: Door and Window Contacts
    unique_id: door_window_contacts
    device_class: opening
    entities:
        - binary_sensor.back_door
        - binary_sensor.basement_bedroom_windowl
        - binary_sensor.basement_bedroom_windowr
        - binary_sensor.basement_fam_room_winl
        - binary_sensor.basement_fam_room_winr
        - binary_sensor.front_door
        - binary_sensor.garage_door
        - binary_sensor.kitchen_window
        - binary_sensor.l_s_bedroomn_window
        - binary_sensor.living_room_window
        - binary_sensor.master_bedroom_window
        - binary_sensor.v_s_bedroom_window

I tested the above by opening a window for about a minute, and state correctly went from off to on, and then on to off when I closed the window.

Then I created the automation based on the above being a trigger:

alias: Shut Off HVAC when Window or Door Is Left Open
description: ''
trigger:
  - platform: state
    entity_id: binary_sensor.door_and_window_contacts
    to: 'on'
    for:
      hours: 0
      minutes: 10
      seconds: 0
condition: []
action:
  - choose:
      - conditions:
          - condition: numeric_state
            entity_id: sensor.outdoor_temperature
            above: '24'
          - condition: state
            entity_id: climate.house_thermostat_nativezone
            attribute: hvac_mode
            state: cool
        sequence:
          - service: climate.set_hvac_mode
            data:
              hvac_mode: 'off'
            target:
              entity_id: climate.house_thermostat_nativezone
          - service: notify.mobile_app_sony_xperia_zx1
            data:
              message: HVAC Turned off because a window or door is opened.
              title: HVAC Turned off
          - service: notify.mobile_app_iphone
            data:
              message: HVAC Turned off because a window or door is opened.
              title: HVAC Turned off
          - service: tts.cloud_say
            data:
              entity_id: media_player.kitchen_display
              message: HVAC Turned off because a window or door is opened.
      - conditions:
          - condition: numeric_state
            entity_id: sensor.outdoor_temperature
            below: '13'
          - condition: state
            entity_id: climate.house_thermostat_nativezone
            attribute: hvac_mode
            state: heat
        sequence:
          - service: climate.set_hvac_mode
            data:
              hvac_mode: 'off'
            target:
              entity_id: climate.house_thermostat_nativezone
          - service: notify.mobile_app_sony_xperia_zx1
            data:
              message: HVAC Turned off because a window or door is opened.
              title: HVAC Turned off
          - service: notify.mobile_app_iphone
            data:
              message: HVAC Turned off because a window or door is opened.
              title: HVAC Turned off
          - service: tts.cloud_say
            data:
              entity_id: media_player.kitchen_display
              message: HVAC Turned off because a window or door is opened.
    default: []
mode: single

I also added some phone and TTS notifications.

You mentioned a great point about:

“…using two Numeric State triggers to track the temperature and trigger when it passes your set points (this is also a good place to use the for: variable so don’t get an excessive number of notifications if the temperature is hovering around your set point).”

I’m not sure I did that correctly above?

That should work, but you have a lot of unecessary repetition. With a little restructuring you can cut that down and handle the case where the temperature passes your set points when a window is already open.

alias: Shut Off HVAC when Window or Door Is Left Open
description: ''
trigger:
  - platform: state
    entity_id: binary_sensor.door_and_window_contacts
    to: 'on'
    for:
      hours: 0
      minutes: 10
      seconds: 0
  - platform: numeric_state
    entity_id: sensor.outdoor_temperature
    above: '24'
    for:
      hours: 0
      minutes: 10
      seconds: 0
  - platform: numeric_state
    entity_id: sensor.outdoor_temperature
    below: '13'
    for:
      hours: 0
      minutes: 10
      seconds: 0
condition:
  - condition: state
    entity_id: binary_sensor.door_and_window_contacts
    state: 'on'
  - condition: or
    - conditions:
      - condition: numeric_state
        entity_id: sensor.outdoor_temperature
        above: '24'
      - condition: numeric_state
        entity_id: sensor.outdoor_temperature
        below: '13'
  - condition: state
    entity_id: climate.house_thermostat_nativezone
    state:
      - cool
      - heat
action:
  - service: climate.set_hvac_mode
    data:
      hvac_mode: 'off'
    target:
      entity_id: climate.house_thermostat_nativezone
  - service: notify.mobile_app_sony_xperia_zx1
    data:
      message: HVAC Turned off because a window or door is opened.
      title: HVAC Turned off
  - service: notify.mobile_app_iphone
    data:
      message: HVAC Turned off because a window or door is opened.
      title: HVAC Turned off
  - service: tts.cloud_say
    data:
      entity_id: media_player.kitchen_display
      message: HVAC Turned off because a window or door is opened.
mode: single
1 Like

thanks @Didgeridrew this new version makes much more sense in terms of flow! nice!

I’ve noticed with automation now, that Im often using the text editor version as opposed to the visual editor, somtimes I see this:

condition:
condition: []
condition: null

do the above mean the same thing?

Also, I was reading the documentation with regards to a Actionable Notifications. To implement this into the above script, for now i’ll just consider my Android phone as there seems to be clear differences with iPhone.

How do implement a timeout for this and how do I implement a dismiss the action? For example, I don’t need it to take me to lovelace, justthe ability cancel or proceed with the HVAC shutdown, but with a timeout to shutdown if no responce is received within say, 30 seconds?

this is jsut an example with fillter below

service: notify.mobile_app_sony_xperia_zx1
data:
  message: "HVAC Will Turn off due to window or door being opened!"
  data:
    actions:
      - action: "ALARM" # The key you are sending for the event
        title: "Sound Alarm" # The button title
      - action: "URI" # Must be set to URI if you plan to use a URI
        title: "Open Url"
        uri: "https://google.com" # URL to open when action is selected, can also be a lovelace view/dashboard

Mostly… The caveat is that you must use the first one if you actually have conditions nested underneath it. You shouldn’t overtly declare it as null in that case. There have been a few additions/changes to how to you can/must declare a null value over the past couple of years. If I remember correctly, declaring them with [] was mandated first to fix something that was causing issues, then later the devs added back the ability to leave it blank or use null… I think as an effort to make it easier for new users.

I use a Wait for Trigger Action with a timeout. I’ve set this up as a script so that the original automation only needs a minimal change.

HVAC Actionable Notification Script
alias: "Notify Android Actionable HVAC/Window"
description: "Sends an actionable notification to ZX1 about HVAC"
sequence:
  - alias: Set up variables for the actions
    variables:
      action_killall: '{{ "SHUTDOWN_" ~ context.id }}'
      action_ignore: '{{ "IGNORE_" ~ context.id }}'
      action_fan: '{{ "FAN_" ~ context.id }}'
  - alias: Ask What to do about the HVAC
    service: notify.mobile_app_sony_xperia_zx1
    data:
      message: The HVAC is running with a window or door open.
      data:
        channel: HVAC
        tag: window
        actions:
          - action: '{{ action_killall }}'
            title: Turn Off
          - action: '{{ action_ignore }}'
            title: Ignore
          - action: '{{ action_fan }}'
            title: Fan Only
  - alias: Wait for a response
    timeout: '00:01:00'
    wait_for_trigger:
      - platform: event
        event_type: mobile_app_notification_action
        event_data:
          action: '{{ action_killall }}'
      - platform: event
        event_type: mobile_app_notification_action
        event_data:
          action: '{{ action_ignore }}'
      - platform: event
        event_type: mobile_app_notification_action
        event_data:
          action: '{{ action_fan }}'
  - alias: Perform the action on button press or timeout
    choose:
      - conditions:
          - condition: template
            value_template: >-
              {{ wait.trigger.event.data.action == action_killall or
              wait.trigger == "none" }}
        sequence:
          - service: climate.set_hvac_mode
            data:
              hvac_mode: 'off'
            target:
              entity_id: climate.house_thermostat_nativezone
          - delay: 2
          - service: climate.set_fan_mode
            data:
              fan_mode: 'Auto'
            target:
              entity_id: climate.house_thermostat_nativezone
          - service: notify.mobile_app_sony_xperia_zx1
            data:
              message: clear_notification
              data:
                channel: HVAC
                tag: window
      - conditions:
          - condition: template
            value_template: '{{ wait.trigger.event.data.action == action_ignore }}'
        sequence:
          - delay: 5
          - service: notify.mobile_app_sony_xperia_zx1
            data:
              message: clear_notification
              data:
                channel: HVAC
                tag: window
      - conditions:
          - condition: template
            value_template: '{{ wait.trigger.event.data.action == action_fan }}'
        sequence:
          - service: climate.set_hvac_mode
            data:
              hvac_mode: 'off'
            target:
              entity_id: climate.house_thermostat_nativezone
          - delay: 2
          - service: climate.set_fan_mode
            data:
              fan_mode: 'on'
            target:
              entity_id: climate.house_thermostat_nativezone
          - delay: 5
          - service: notify.mobile_app_sony_xperia_zx1
            data:
              message: clear_notification
              data:
                channel: HVAC
                tag: window
mode: single

Modified Automation
alias: Shut Off HVAC when Window or Door Is Left Open
description: ''
trigger:
  - platform: state
    entity_id: binary_sensor.door_and_window_contacts
    to: 'on'
    for:
      hours: 0
      minutes: 10
      seconds: 0
  - platform: numeric_state
    entity_id: sensor.outdoor_temperature
    above: '24'
    for:
      hours: 0
      minutes: 10
      seconds: 0
  - platform: numeric_state
    entity_id: sensor.outdoor_temperature
    below: '13'
    for:
      hours: 0
      minutes: 10
      seconds: 0
condition:
  - condition: state
    entity_id: binary_sensor.door_and_window_contacts
    state: 'on'
  - condition: or
    conditions:
      - condition: numeric_state
        entity_id: sensor.outdoor_temperature
        above: '24'
      - condition: numeric_state
        entity_id: sensor.outdoor_temperature
        below: '13'
  - condition: state
    entity_id: climate.house_thermostat_nativezone
    state:
      - cool
      - heat
action:
  - service: script.notify_android_actionable_hvac_window
  - service: notify.mobile_app_iphone
    data:
      message: HVAC Turned off because a window or door is opened.
      title: HVAC Turned off
  - service: tts.cloud_say
    data:
      entity_id: media_player.kitchen_display
      message: HVAC Turned off because a window or door is opened.
mode: single

EDIT: Corrected OR Condition formatting and removed Comment

1 Like

well then! this is really elegant, the automation calls the script which deals with the actionable notifcation. I’m going to try this out by modifying the outdoor temperature thresholds.

By the way, when I try to implement the automation and script, the editor is complaining about:

this in the automation:
“Message malformed: required key not provided @ data[‘action’]”"

and this in the script:
“Message malformed: required key not provided @ data[‘sequence’]”

I tried to look for bad indentation, or perhaps the copy-paste didn’t go well, or is there some title field missing?

I don’t see anywhere that’s missing an action: or sequence:… double check indents, and punctuation symbols; namely colons and quotation marks. Sometimes when using copy/paste on this forum you will get “fancy quotes” instead of normal quotes.

Thanks again, @Didgeridrew

I manged to figure out what was wrong with the automation, it was an indentation on line 30. I changed this:

- condition: or
    - conditions:
      - condition: numeric_state
        entity_id: sensor.outdoor_temperature

to this, deleted hyphen and move “conditions” back

- condition: or
  conditions:
    - condition: numeric_state
      entity_id: sensor.outdoor_temperature

It accepted this without any errors. Does this change what we’re trying to do?

As for the script,

UPDATE: found this issue, there was an extra bracket on the comment line, but I just deleted this part of line 54

{# Your thermostat might use ‘auto’ or ‘off’ instead #}

Ran the script only, and it works! I get the notification with actions on my phone.

Good catch! That’s my fault, apparently I don’t use OR conditions enough and used the formatting from Choose (which I use all the time)…

1 Like

just tried running the entire process. The Automation seems to run fun after 10 minutes, however, I think the automation does not know where the script it, as individually, they run well. and I get these errors in the log files after 10 minutes of having a window open:

Shut Off HVAC when Window or Door Is Left Open: Error executing script. Service not found for call_service at pos 1: Unable to find service script.notify_android_actionable_hvac_window

Error while executing automation automation.shut_off_hvac_when_window_or_door_is_left_open: Unable to find service script.notify_android_actionable_hvac_window

Does the alias of the script need to be “notify_android_actionable_hvac_window” or is there some sort of script ID that I have to rename?

EDIT: Ok managed to get the script to link to the automation (just placed notify_android_actionable_hvac_window: on the first line!)

did the test again. Here’s what happened.

I wanted to test the event where the window is open for 10 minutes, and we don’t have access to our phones. In this scenario, it would turn off the HVAC.

After 10 minutes past, the notifcation came on the google speakers, and we got the notification on the phones. My android phone has the options presented me, but I didn’t press any of the options so I waited…after about 8 minutre more, I noticed nothing happend. The notification and 3 options was still on my phone and my HVAC was still on. I checked the logs again and found this:

these two errors are at rougly the 10 minute after opening the window

Logger: homeassistant.helpers.script
Source: helpers/script.py:649
First occurred: 2:54:11 PM (3 occurrences)
Last logged: 2:54:11 PM

Error in 'choose[0]' evaluation: In 'template' condition: UndefinedError: 'None' has no attribute 'event
Logger: homeassistant.helpers.template
Source: helpers/template.py:1834
First occurred: 2:54:11 PM (3 occurrences)
Last logged: 2:54:11 PM

Template variable error: 'None' has no attribute 'event' when rendering '{{ wait.trigger.event.data.action == action_killall or wait.trigger == "none" }}'
Template variable error: 'None' has no attribute 'event' when rendering '{{ wait.trigger.event.data.action == action_ignore }}'
Template variable error: 'None' has no attribute 'event' when rendering '{{ wait.trigger.event.data.action == action_fan }}'

its complaing about none having no attribute event, and related to the timeout (i.e. me not doing anything).

Had I pressed an option on the actionable notification, it works. It just seems to hang on the time-out scenario.

Yep, it’s the wait.trigger == 'none', the docs says the proper value is none, the automation debug says it’s returning null… no variation of either of those seems to work at this time. So, instead we can move those actions to a default:

alias: "Notify Android Actionable HVAC/Window"
description: "Sends an actionable notification to ZX1 about HVAC"
sequence:
  - alias: Set up variables for the actions
    variables:
      action_killall: '{{ "SHUTDOWN_" ~ context.id }}'
      action_ignore: '{{ "IGNORE_" ~ context.id }}'
      action_fan: '{{ "FAN_" ~ context.id }}'
  - alias: Ask What to do about the HVAC
    service: notify.mobile_app_sony_xperia_zx1
    data:
      message: The HVAC is running with a window or door open.
      data:
        channel: HVAC
        tag: window
        actions:
          - action: '{{ action_killall }}'
            title: Turn Off
          - action: '{{ action_ignore }}'
            title: Ignore
          - action: '{{ action_fan }}'
            title: Fan Only
  - alias: Wait for a response
    timeout: '00:01:00'
    wait_for_trigger:
      - platform: event
        event_type: mobile_app_notification_action
        event_data:
          action: '{{ action_killall }}'
      - platform: event
        event_type: mobile_app_notification_action
        event_data:
          action: '{{ action_ignore }}'
      - platform: event
        event_type: mobile_app_notification_action
        event_data:
          action: '{{ action_fan }}'
  - alias: Perform the action on button press or timeout
    choose:
      - conditions:
          - condition: template
            value_template: '{{ wait.trigger.event.data.action == action_ignore }}'
        sequence:
          - delay: 5
          - service: notify.mobile_app_sony_xperia_zx1
            data:
              message: clear_notification
              data:
                channel: HVAC
                tag: window
      - conditions:
          - condition: template
            value_template: '{{ wait.trigger.event.data.action == action_fan }}'
        sequence:
          - service: climate.set_hvac_mode
            data:
              hvac_mode: 'off'
            target:
              entity_id: climate.house_thermostat_nativezone
          - delay: 2
          - service: climate.set_fan_mode
            data:
              fan_mode: 'on'
            target:
              entity_id: climate.house_thermostat_nativezone
          - delay: 5
          - service: notify.mobile_app_sony_xperia_zx1
            data:
              message: clear_notification
              data:
                channel: HVAC
                tag: window
    default:
       - service: climate.set_hvac_mode
         data:
           hvac_mode: 'off'
         target:
           entity_id: climate.house_thermostat_nativezone
       - delay: 2
       - service: climate.set_fan_mode
         data:
           fan_mode: 'Auto'
         target:
           entity_id: climate.house_thermostat_nativezone
       - service: notify.mobile_app_sony_xperia_zx1
         data:
           message: clear_notification
           data:
             channel: HVAC
             tag: window
mode: single

thanks again!

Using the new script, it works exactly was we discussed! THANK YOU!
If I ignore the actions messages, after 1 minute, my HVAC turns off. Pretty Sweet.

The errors logs still show the none error, I wonder if just some legacy/cache issue (I didn’t restart my HA but did reset the scripts and automations).

Logger: homeassistant.helpers.template
Source: helpers/template.py:1834
First occurred: 6:18:56 PM (2 occurrences)
Last logged: 6:18:56 PM

Template variable error: 'None' has no attribute 'event' when rendering '{{ wait.trigger.event.data.action == action_ignore }}'
Template variable error: 'None' has no attribute 'event' when rendering '{{ wait.trigger.event.data.action == action_fan }}'
Logger: homeassistant.helpers.script
Source: helpers/script.py:649
First occurred: 6:18:56 PM (2 occurrences)
Last logged: 6:18:56 PM

Error in 'choose[0]' evaluation: In 'template' condition: UndefinedError: 'None' has no attribute 'event'

There was another error log shown, but more related to my thermostat and intergration,

Logger: homeassistant.core
Source: components/nexia/climate.py:211
First occurred: 6:00:35 PM (2 occurrences)
Last logged: 6:19:19 PM

Error executing service: <ServiceCall climate.set_fan_mode (c:58baefee020d30cb2db571325ca23ae3): fan_mode=Auto, entity_id=['climate.house_thermostat_nativezone']>
Error executing service: <ServiceCall climate.set_fan_mode (c:7c7b8be6e9d7a8717ddadaa7ae71e332): fan_mode=Auto, entity_id=['climate.house_thermostat_nativezone']>

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 449, in _make_request
    six.raise_from(e, None)
  File "<string>", line 3, in raise_from
  File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 444, in _make_request
    httplib_response = conn.getresponse()
  File "/usr/local/lib/python3.9/http/client.py", line 1377, in getresponse
    response.begin()
  File "/usr/local/lib/python3.9/http/client.py", line 320, in begin
    version, status, reason = self._read_status()
  File "/usr/local/lib/python3.9/http/client.py", line 281, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
  File "/usr/local/lib/python3.9/socket.py", line 704, in readinto
    return self._sock.recv_into(b)
  File "/usr/local/lib/python3.9/ssl.py", line 1241, in recv_into
    return self.read(nbytes, buffer)
  File "/usr/local/lib/python3.9/ssl.py", line 1099, in read
    return self._sslobj.read(len, buffer)
socket.timeout: The read operation timed out

During handling of the above exception, another exception occurred, but I suspect this is more related to the itnregration instead.

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/requests/adapters.py", line 440, in send
    resp = conn.urlopen(
  File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 785, in urlopen
    retries = retries.increment(
  File "/usr/local/lib/python3.9/site-packages/urllib3/util/retry.py", line 550, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "/usr/local/lib/python3.9/site-packages/urllib3/packages/six.py", line 770, in reraise
    raise value
  File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(
  File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 451, in _make_request
    self._raise_timeout(err=e, url=url, timeout_value=read_timeout)
  File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 340, in _raise_timeout
    raise ReadTimeoutError(
urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='www.mynexia.com', port=443): Read timed out. (read timeout=20)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/core.py", line 1654, in catch_exceptions
    await coro_or_task
  File "/usr/src/homeassistant/homeassistant/core.py", line 1673, in _execute_service
    await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)(
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 204, in handle_service
    await self.hass.helpers.service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 668, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 949, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 705, in _handle_entity_call
    await result
  File "/usr/src/homeassistant/homeassistant/components/climate/__init__.py", line 462, in async_set_fan_mode
    await self.hass.async_add_executor_job(self.set_fan_mode, fan_mode)
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/nexia/climate.py", line 211, in set_fan_mode
    self._thermostat.set_fan_mode(fan_mode)
  File "/usr/local/lib/python3.9/site-packages/nexia/thermostat.py", line 377, in set_fan_mode
    self._post_and_update_thermostat_json("fan_mode", {"value": fan_mode})
  File "/usr/local/lib/python3.9/site-packages/nexia/thermostat.py", line 665, in _post_and_update_thermostat_json
    response = self._nexia_home.post_url(url, payload)
  File "/usr/local/lib/python3.9/site-packages/nexia/home.py", line 159, in post_url
    response = self.session.post(
  File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 577, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 529, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 645, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/requests/adapters.py", line 532, in send
    raise ReadTimeout(e, request=request)
requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='www.mynexia.com', port=443): Read timed out. (read timeout=20)

I was able to determine why the last erros above, i.e. this error below occurs:

Error executing service: <ServiceCall climate.set_fan_mode (c:58baefee020d30cb2db571325ca23ae3): fan_mode=Auto, entity_id=['climate.house_thermostat_nativezone']>

I’m able to reproduce the error by playing with fan mode settings in the developer tools. If the thermostat is already in the state that it calls, it throws that error. Since my thermostat is going to be always in fan mode auto, I commented out that part of the script for the timeout section:

default:
       - service: climate.set_hvac_mode
         data:
           hvac_mode: 'off'
         target:
           entity_id: climate.house_thermostat_nativezone
       - delay: 2
       #- service: climate.set_fan_mode
       #  data:
       #   fan_mode: 'Auto'
       #  target:
       #   entity_id: climate.house_thermostat_nativezone
       - service: notify.mobile_app_sony_xperia_zx1
         data:
           message: clear_notification
           data:
             channel: HVAC
             tag: window

Since my HVAC fan mode is always in AUTO, it will always show up under normal use. Actually, this type of error will happen in any state, if the script calls for a state that thermostat is already in, it will give that error.

I still get those “none” attribute errors though, I supect its related to the orignal issues that you referenced in the document above.

regardless, it works, just throws these errors below.

Logger: homeassistant.helpers.template
Source: helpers/template.py:1834
First occurred: 12:43:18 PM (6 occurrences)
Last logged: 2:35:57 PM

Template variable error: 'None' has no attribute 'event' when rendering '{{ wait.trigger.event.data.action == action_ignore }}'
Template variable error: 'None' has no attribute 'event' when rendering '{{ wait.trigger.event.data.action == action_fan }}'

Congratualtions on debugging the fan mode issue.

I’m pretty sure the None errors are an artifact of it trying to render the templates before wait.trigger event has been defined. I had planned on seeing if my daily automation that the example was based on threw the same errors this morning, but I forgot to let it keep running to trigger the timeout.

thanks, @Didgeridrew It’d be curious to know what you find when you allow the timeout to occure, perhaps a bug in the code we can both push forward to the developers.