Dynamic temperature colors - should I close/open windows?

Scenario: In the summer, quite often we open doors & windows until it gets too warm outside. But when should I close them?
image

Note that this is not an automated solution. It’s about the ability to instantly see where you could close/open a window

This card shows exactly which rooms are cooler than the outside temperature.
In the above screenshot

  • the garage is cooler: close doors.
  • other windows/doors could remain open as it’s still cooler outside.

Requires:

Code:

type: custom:bar-card
entities:
  - entity: sensor.temp_garage
    name: Garage
  - entity: sensor.temp_office
    name: Office
  - entity: sensor.temp_outside
    name: Outside
  - entity: sensor.temp_living
    name: Living
  - entity: sensor.temp_cabin
    name: BH
title: Temperature comparison
direction: up
height: 200px
show_icon: false
positions:
  icon: 'off'
  title: inside
  value: inside
  name: inside
min: 0
max: 34
stack: horizontal
card_mod:
  style: |
    bar-card-row bar-card-card:nth-of-type(1) {
      --bar-card-color: 
        {% if states('sensor.temp_garage') | float < states('sensor.temp_outside') | float %}
        #03a9f4
        {% else %}
        red
        {% endif %}
    }
    bar-card-row bar-card-card:nth-of-type(2) {
      --bar-card-color: 
        {% if states('sensor.temp_office') | float < states('sensor.temp_outside') | float %}
        #03a9f4
        {% else %}
        red
        {% endif %}
    }
    bar-card-row bar-card-card:nth-of-type(3) {
        --bar-card-color: grey;
    bar-card-row bar-card-card:nth-of-type(4) {
      --bar-card-color: 
        {% if states('sensor.temp_living') | float < states('sensor.temp_outside') | float %}
        #03a9f4
        {% else %}
        red
        {% endif %}
    }
    bar-card-row bar-card-card:nth-of-type(5) {
      --bar-card-color: 
        {% if states('sensor.temp_cabin') | float < states('sensor.temp_outside') | float %}
        #03a9f4
        {% else %}
        red
        {% endif %}
    }
    bar-card-row {
        --primary-text-color: white;
        font-size: 16px;
    }
    bar-card-backgroundbar {
        border-radius: 10px;
    }

Little explanation:
You can set the individual bar color with the following card_mod style:

bar-card-row bar-card-card:nth-of-type(1)

Where “type(2)” is the 2nd bar etc.

Next steps

  • Automate notifications telling you when/which doors to close.
  • Visualize door/window status in or below these bars.
3 Likes

We also like to have the windows open as much possible … but I never got around to building a dashboard card. I did however put together a notification automation that has worked well for my needs. I get notifications to open or close the windows based on on comparing a mix of forecasts, current outside temp and humidity to set points as well as inside conditions.

Like many houses here in the US we have central, forced-air heating and cooling, so it usually makes the most sense to open/close all the windows at the same time (this might not be directly translatable to other heating/cooling methods).

Notification Automation

Since the front porch sensor tends to warm up a bit sooner (and cools down a bit later) than the readings of the local weather station, I compare that to my indoor average.

alias: Alexa - Notify - Outside Temperature - Windows Actions
description: >-
  Notifies when to open or close windows based on comparing outside temp and
  humidity to setpoints as well as inside conditions. 
trigger:
  - platform: numeric_state
    entity_id: sensor.front_porch_temperature
    above: sensor.average_non_basement_temp
    id: Hotter Outside
    for:
      hours: 0
      minutes: 5
      seconds: 0
      milliseconds: 0
  - platform: numeric_state
    entity_id: sensor.front_porch_temperature
    below: sensor.average_non_basement_temp
    id: Cooler Outside
    for:
      hours: 0
      minutes: 5
      seconds: 0
      milliseconds: 0
  - platform: state
    entity_id: binary_sensor.nicer_outside
    id: Nicer Outside
    to: 'on'
    for:
      hours: 0
      minutes: 5
      seconds: 0
condition:
  - condition: time
    after: '07:30:00'
  - condition: state
    entity_id: input_boolean.a_in_bed
    state: 'off'
  - condition: state
    entity_id: binary_sensor.house_occupied
    state: 'on'
action:
  - choose:
      - conditions:
          - condition: trigger
            id: Hotter Outside
          - condition: state
            entity_id: binary_sensor.all_window_sensors
            state: 'on'
          - condition: numeric_state
            entity_id: sensor.high_temp_forecast
            above: '23.5'
        sequence:
          - wait_for_trigger:
              - platform: numeric_state
                entity_id: sensor.front_porch_temperature
                above: '23.5'
                for:
                  hours: 0
                  minutes: 10
                  seconds: 0
                  milliseconds: 0
            timeout: '01:00:00'
          - condition: numeric_state
            entity_id: sensor.outside_temperature_derivative
            above: '0'
          - service: notify.alexa_media
            data:
              target: media_player.everywhere
              data:
                type: announce
              message: "Its warming up outside. Time to close the windows."
          - wait_for_trigger:
              - platform: state
                entity_id: binary_sensor.all_window_sensors
                from: 'on'
                to: 'off'
            timeout: '00:10:00'
          - choose:
              - conditions:
                  - condition: state
                    entity_id: binary_sensor.all_window_sensors
                    state: 'off'
                sequence:
                  - service: notify.alexa_media
                    data:
                      message: "Thank You. All the windows are now closed."
                      target: media_player.everywhere
                      data:
                        type: announce
            default:
              - condition: numeric_state
                entity_id: sensor.outside_temperature_derivative
                above: '0'
              - service: notify.alexa_media
                data:
                  message: "There are still windows open and its getting hotter outside."
                  target: media_player.everywhere
                  data:
                    type: announce
      - conditions:
          - condition: trigger
            id: Cooler Outside
          - condition: numeric_state
            entity_id: sensor.outside_temperature_derivative
            below: '0'
          - condition: state
            entity_id: binary_sensor.all_window_sensors
            state: 'off'
          - condition: numeric_state
            entity_id: sensor.front_porch_temperature
            above: '5'
            below: '18'
          - condition: numeric_state
            entity_id: sensor.low_temp_forecast
            above: '4.5'
        sequence:
          - service: notify.alexa_media
            data:
              target: media_player.everywhere
              data:
                type: announce
              message: "Its cooling down outside. Time to open the windows."
      - conditions:
          - condition: trigger
            id: Nicer Outside
          - condition: state
            entity_id: binary_sensor.all_window_sensors
            state: 'off'
          - condition: numeric_state
            entity_id: sensor.front_porch_temperature
            below: '23.5'
            above: '4.5'
          - condition: numeric_state
            entity_id: sensor.low_temp_forecast
            above: '4.5'
        sequence:
          - service: notify.alexa_media
            data:
              target: media_player.everywhere
              data:
                type: announce
              message: >-
                My sensors indicate that the combination of temperature and humidity may
                be nicer outside than inside. This may be a good time to open the windows.
    default: []
mode: single

The Nicer Outside sensor compares two template sensors that calculate the Discomfort Index. Alternatively, you could use a Heat Index or your preferred temp + humidity calculation.

template:
  - sensor:
      - name: "Outside Discomfort Index"
        unit_of_measurement: ""
        state_class: measurement
        state: >-
          {% set t = ((states('sensor.front_porch_temperature')|float(0)) %}
          {% set h = states('sensor.front_porch_humidity')|float(0) %}
          {{ (t - (0.55*(1  - (0.01*h) ) * (t - 14.5)))|round(2,0) }}
        attributes:
          comfortable: >-
            {{ this.state|int(0)  < 20 }}
template:
  - binary_sensor:
      - name: "Nicer Outside"
        state: >-
          {{ states('binary_sensor.inside_discomfort_index')|float(0)|round(1,0) - 1.5
          >= states('binary_sensor.outside_discomfort_index')|float(0)|round(1,0) }}
3 Likes

Please consider changing the category on this post/thread as it is seeking help and not sharing a working a solution in the initial post.

I too made notifications and dashboard widgets. Per window I have binary sensors:

  1. Window should be opened (windows in that room currently closed and no rain, hot and outside is 1 degree cooler or high CO2 or other pollutant levels inside)
  2. Window should be closed (window currently open, rain or outside hot and temp outside 1 degree higher than inside, pollutant levels in the room ok)

When more binary sensors go on, and I’m at home and awake, the advice is broadcasted on my nest hub in the living room. I’m contemplating also broadcasting the advice for the room itself in that particular room when not asleep).

The dashboard has icons showing wether the window is closed (grey, closed window icon) or open (blue open window icon). When the advice is telling the window should be openend/closed, the icon turns red saying this is not the desired state.

It is not the prettiest code, and a lot of it. But if anyone is interested I can make a separate post for it.

1 Like

I’m not seeking help. That happened in other thread(s).
This is a working solution.

You posed this question:

I only see a solution for a card, unless one needs to stare at a screen to determine the moment to do so, with an automation suggested as an afterthought:

To me it seems like Drew’s answer is the real answer to the question.

Sorry, I’m not trying to be an ass: I followed the original link since I really wanted to see how some people are doing this. I clearly misunderstood the intent here and just explaining where I came from. I’m moving on.