Notify when temperature dropped by 2°C and window is open

Hi,

I searched a lot but didn’t find the correct answer.

I want to notify my family when a window is open and the temperature in that specific room dropped by 2 degrees within 1 hour.

How can I realise that. Something with history stats?

In my opinion I need to do the following.

Store the actual room temperature in a sensor when the window changes it state to open.

Trigger an automation when the actual room temperature is 2 degrees below the saved temperature and the window is open.

Can somebody please help how to do that? I also would like to do that for all rooms. Maybe there is a way to simplyfy that instead of creating 8 different automations.

Thx for your help.

this should tell you the max temp in the last hour.

- platform: statistics
  name: "room name max temp"
  entity_id: sensor.room_temp
  state_characteristic: value_max
  max_age:
    hours: 1
  sampling_size: 12
  precision: 1

You could trigger your automation if this sensor (sensor.room_name_max_temp) > sensor.room_name by 2.0 with the condition that the window is open.

thx for that

How do I configure in the automation that the difference should be by 2?

with a template. Something like:

  trigger:
    - platform: template
      value_template: "{{ states('room_temp_max_temp')|int(0) > states('room_temp')|int(0) +2 }}"
1 Like

Unfortunately it didn’t work. Last time when I tried it I manually changed the max temp.

But now I checked the difference between the temperature and max temp and its always nearly the same. any idea?

I think I need to store the actual temperature when the window is opened and as soon as the real temperature gets 2°C below that stored point I need to send an alarm.

Any idea how that could work?

Heres a picture of the max temp and actual temp and the reason why it didn’t work.

grafik

grafik

hoe many times does the temps sensor update per hour?
The problem may be that this is not frequent enough?

OK, let’s try your original idea.

What’s the temp sensor’s entity_id and have you set up an input_number for the saved temp? No worries if not, I’ll try and write your automation for you later today…

1 Like

wanna give this a try?

You’ll need to rename the following:

binary_sensor.room_window_contact (window sensor)
sensor.room_temp (room temp sensor)
input_number.room_temp (saved room temp when window opened)

- alias: "Notify if Bedroom temp drops by 2 degrees (window open)"
  id: bedroom_temp_drop
  description: ""
  mode: single
  trigger:
    - platform: state
      entity_id:
        - binary_sensor.room_window_contact
      to: "on"
      id: window_opened
    - platform: numeric_state
      entity_id:
        - sensor.room_temp
      id: temp_change
  action:
    - choose:
        - conditions:
            - condition: trigger
              id: window_opened
          sequence:
            - service: input_number.set_value
              target:
                entity_id: input_number.room_temp
              data:
                value: "{{ states('sensor.room_window_contact')|round(1) }}"
        - conditions:
            - condition: trigger
              id: temp_change
            - condition: state
              entity_id: binary_sensor.room_window_contact
              state: "on"
          sequence:
            - service: send_alert
            - service: notify.notify
              data:
                title: "HA status:"
                message: "Bedroom has dropped from {{ states('input_number.room_temp') }} to {{ states('sensor.room_temp') }}"

I got it working now. Thx for your help.

Here is the final code.

alias: Notify if Bedroom temp drops by 2 degrees (window open)
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.fensterkontakt_arbeitszimmer_offnet
    to: "on"
    id: window_opened
  - platform: template
    value_template: >-
      {{ states('input_number.schlafzimmer_temperatur_gespeichert')|int(0) >
      states('sensor.luftfeuchte_arbeitzimmer_temperatur')|int(0) +2 }}
    id: temp_change
action:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - window_opened
        sequence:
          - service: input_number.set_value
            data:
              value: >-
                {{ states('sensor.luftfeuchte_arbeitzimmer_temperatur')|round(1)
                }}
            target:
              entity_id: input_number.schlafzimmer_temperatur_gespeichert
      - conditions:
          - condition: trigger
            id:
              - temp_change
          - condition: state
            entity_id: binary_sensor.fensterkontakt_arbeitszimmer_offnet
            state: "on"
        sequence:
          - service: notify.alexa_media_echo_arbeitszimmer
            data:
              data:
                type: announce
              message: >-
                Achtung, das Schlafzimmerfenster ist noch offen! Das
                Schlafzimmer kühlt gerade aus! Bitte Fenster schließen.
mode: single

1 Like