How to create more dynamic automations?

Sorry for the vague title but I didn’t quite know how else to describe my problem.

So what I want to do:

When door X is opened for more than 5 minutes AND the AC is set to cooling AND the difference between indoor and outdoor temp is lower than X °C: Send a notification and TTS about this. And if this happens again after 10 minutes, turn off the AC.

Do the same for when AC is in HEATING mode and the difference is above 5°C.

Now I can perfectly do this for one door, I created a template sensor that calcualtes the difference between inside and outside temperature.
But I have more than one door so I would like to make it dynamic. And also doing this for heat and cool would double alll such automations, same with the 5min action (notify) and 10min action (turn off AC) it would be: number_of_doors * 2 (5/10min) * 2 (heating/cooling). Which I could do but maintaining seems like a hassle.

I know I could probably make a template that just checks if any door is open and then react but I do want to notify via notification and tts which door is the culprit. For windows this is much less important and I am ok just having one general “you left a window open” notification.

Is this possible? I attached a screenshot of my single-door, cooling-scenario, 5 minute alert automation:

Hi,

Try to work with multiple triggers and add a trigger ID to each of them.
Delete the conditions (and if) and add them to a choose action (then do) incl. other actions.

There are a number of ways to accomplish this.

I would probably start with a Template that combines:

  1. Is any door open?
  2. Is temp delta past the threshold for the current HVAC action?

That could be used either directly as a Template trigger or as a binary sensor. Since you are going to need two identical triggers except for the duration, having a binary sensor might be the easier choice long-term.

Naming the door or doors that are open in the message is a pretty easy template, so don’t get hung up on that part.

A custom template would create a macro that you can call with data, so write it once, call it over and over again with the entities in question.
Here’s an example of one of mine… GitHub - SirGoodenough/Availability-Template: Custom Template for checking the availiability of an entity. · GitHub

You may be able to set up a blueprint template for that. This method is not fully fleshed out yet, WIP, but some template types are possible. Again set up the code once, create templates by adding inputs to the code to change things as needed per template. You can get examples of these by pasting this URL into a browser (It’s a search of this site)

Topics tagged template-entity

Thank you guys, I will try to make sense of each approach and play around with that!

I was looking at your sceenshot again. Tip: Use entity status triggers, not device.

trigger: state
entity_id:
  - binary_sensor.door_1
  - binary_sensor.door_2
  - binary_sensor.door_3
to: "on"
id: doors_open

I vaguely recall reading about using templating/cookie cutter type abilities in a HomeAssistant blog recently, but not sure if it has been implemented yet. Setup a master style scenario and then pass parameters for the variations. You do it once, get it right, and then the others will work the same. No global search and replace and accidental omissions to worry about.

I generally find that when I am stringing long sets of conditions together it’s worth taking a break and considering what I am actually trying to do.

I understand that you don’t want to heat or cool whilst the door is left open - makes sense not wanting to heat/cool the rest of the planet.

By why do you care about the difference in inside/outside temperature?

I don’t currently have sensors on all my doors and windows, but if i was in the same position I would just pause ** the AC whenever a door/window was opened.

** - Pause just means remember what it was set to and turn it off - if all the doors/windows are closed I would reset the AC back to its previous setting.

Great question!

Lets say we have a heat wave in spring (which we just had) and the AC is basically on all the time, say I set it to 23°C cooling. In spring however, the nights are still kinda cold so the AC is not needed at 10°C (and will not turn on). So when I open the doors in the morning for some air flow (aka “lüften”) when it is now still pleasent 15°C, I don’t want the AC to turn off because I don’t want to deal with turning it on later myself. And I don’t want to get into automatically turning off and later on again when doors close, that is too intransparent for me and family.

The temperature basically tells me how much energy I would waste if I open the door and the temperature equilizes. And the thermostat context tells me if this is a favorable condition for me or not:

  • If I have set the thermostat to cooling and the inside is cooler than the outside, I want to turn it off because now the heat would creep in faster
  • If I have set the thermostat to cooling and the inside is warmer than the outside, I do not want to turn off the AC because the air from outside helps me cool down and in most cases this scenario means the set point is higher than the outside/inside temp so the AC isn’t running anyways (but still turned on for when it does get hotter). Think about my spring example where in the morning when inside is 20°C, outside is 18°C and set temp is 23°C.

And the same goes for heating.

I should probably include the set temperature in my calculations but need to think through this.

Hope this makes sense.

I also follow the same practice of opening windows both to:

  • Exchange the air.
  • Save on heating and cooling when the outside temperature is favorable.

There is a range of temperatures I find comfortable for the sake of this discussion lets say I want the temperature to stay in the range: 15°C - 25°C (pick your own range). If the temperature is below 15°C I want to heat and if the temperature is above 25°C I want to cool.

With respect to the automations I see this as two different problems:

  1. Being notified when it makes sense to open (or close) windows.
  2. Turning Heating or Cooling on/off.

Notification

I understand why you need both temperatures - simply put if the temperature outside is either in the “comfortable range” or it’s the “right way” to fix your inside temperature you want to be notified to open the windows.

When both the outside and inside temperatures are too hot you want to be told to shut the windows - the same if both are too cold.

Climate Control

The point I am struggling to understand, is why you need more complex logic for controlling the Heat/AC, specifically:

  • If the room is too hot and the windows are closed - turn on the AC.
  • If the room is too cold and the windows are closed - turn on the Heating.
  • If the temperature is okay - turn off the AC/Heating.
  • If the door/windows is open turn off the AC/Heating **.

** - I understand you may want a timer so that the door being open briefly (whilst someone is going through it) doesn’t change the AC/Heating.

One thing that may help, is in my setup is I have two generic thermostats (one sets the bottom (heating) temp and the other sets the top (cooling) temp so I can just turn both on whenever either heating or cooling is needed and turn them both off when a window is open or I leave the house.

Another Consideration

There is a different scenario (than the one you named) where I think it may be useful to useful to consider inside and outside temperature in that you can make the AC more “aggressive” when it is really hot outside since your AC will likely struggle to hold temperature when the difference between inside and outside temperatures is large.

You may also want to factor in humidity as well for the same reason - on humid days I find it necessary to reduce the temperature further to feel comfortable **.

** - I actually have this automated in that I use a combination of actual temp and dew point when controlling my AC (on humid days the dew point increases hence the AC is on for longer).

Because of my mother-in-law…
Who randomly opens doors or windows and then forgets about it.

I also don’t want to automatically turn on the AC. It is expensive and certain other conditions (mostly humidity) also factor in how comfortable a temperature feels.

Even with these additional constraints I would still tackle notification and climate control as separate problems, however I won’t belabor that point, instead I will answer your question:

You can just add all the contact sensors to a group then use something like this:

triggers:
  - entity_id: binary_sensor.doors
    to: "on"
    trigger: state
actions:
  - action: system_log.write
    data:
      message: >
        {% set entities = state_attr('binary_sensor.doors', 'entity_id') %}
        Triggered by:  {{ entities | select('is_state', 'on') | list }}

You might need to enhance that, if you want something more friendly than the entity ids. But the idea is that you are using the group both to trigger the automation and to provide a list of entities to loop through to find the offending door.

Sorry, HA only works with smart stuff. Mother in law v0.7.2 is not supported due to being a legacy dumb device :rofl:

I realize (hope) you are joking.

Even through HA requires some technical skill and/or time to get it setup, frankly if your automations are intrusive or can’t be used by those that are not technically savvy - frankly you are doing it wrong.

For example walking into a room and having the lights turn on doesn’t require any technical skill from the end user.

I suspect a lot of us have older family members that we do “family tech support” for, I don’t really see HA as much different - figure out ways to make the automation simple (or transparent) to them.

PS the joke would have been funnier with version: v1.9.48