Send a message when the window is already open

Hello,
I get a message when the window is opened at a certain time (change off to on). But I don’t want that. I’d like a message when the window is already open at a certain time, so not when something changes.

alias: "Telegram: Fenster Bad EG"
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.fenster_bad_eg_2
    from: "off"
    to: "on"
condition:
  - condition: time
    before: "07:00:00"
    after: "19:00:00"
    weekday:
      - sun
      - mon
      - tue
      - wed
      - thu
      - fri
      - sat
action:
  - service: telegram_bot.send_message
    data:
      message: Fenster Badezimmer EG ist offen.
  - service: notify.karina_telegram
    data:
      message: Fenster Badezimmer EG ist offen.
mode: single

Can you help me please? Thanks.

at a certain time or for a certain time?

If the later:

trigger:
  - platform: state
    entity_id:
      - binary_sensor.fenster_bad_eg_2
    from: "off"
    to: "on"
    for:
      hours: 0
      minutes: 5
      seconds: 0

This would trigger, if binary_sensor.fenster_bad_eg_2 changed from off to on and stayed on for 5 minutes (“Fenster Badezimmer EG seit 5 Minuten geöffnet”).

Sure, just use a time trigger and then a condition that the window is open for the automation to run:

Something like this:

alias: Window is open at 1800 hours
description: ""
trigger:
  - platform: time
    at: "18:00:00"
condition:
  - condition: state
    entity_id: binary_sensor.fenster_bad_eg_2
    state: "on"
action:
  - service: telegram_bot.send_message
    data:
      message: Fenster Badezimmer EG ist offen.
  - service: notify.karina_telegram
    data:
      message: Fenster Badezimmer EG ist offen.

Thanks very much,

do I need two rules per window to be able to do this?
1: Message if window open after 6pm
2: Message if the window was closed after 6:00 p.m. an is opend between 6.00 p.m and 6.00 a.m.

I have the following two rules:
1:

alias: "Telegram: Fenster Büro Matthias Nord"
description: Nachricht, wenn Fenster nach 18.00 bereits offen war
trigger:
  - platform: time
    at: "18:00:00"
condition:
  - condition: state
    entity_id: binary_sensor.fenster_buro_matthias_nord_2
    state: "on"
action:
  - service: telegram_bot.send_message
    data:
      message: Fenster Büro Matthias ist offen.
  - service: notify.karina_telegram
    data:
      message: Fenster Badezimmer EG ist offen.
    enabled: false

2:

alias: "Telegram: Fenster Bad EG"
description: "Nachricht, wenn Fenster nach 19.00 geöffnet wird."
trigger:
  - platform: state
    entity_id:
      - binary_sensor.fenster_bad_eg_2
    from: "off"
    to: "on"
condition:
  - condition: time
    before: "07:00:00"
    after: "19:00:00"
    weekday:
      - sun
      - mon
      - tue
      - wed
      - thu
      - fri
      - sat
action:
  - service: notify.alexa_media_echo_wohnzimmer
    data:
      message: test
  - service: notify.karina_telegram
    data:
      message: Fenster Badezimmer EG ist offen.
    enabled: false
mode: single

Is there a more elegant way?

You could combine the two, the trigger ID and Choose options would be your best bet here.

Something like this maybe?:

description: ""
mode: single
trigger:
  - platform: time
    at: "18:00:00"
    id: fixed time
  - platform: state
    entity_id:
      - binary_sensor.fenster_bad_eg_2
    from: "off"
    to: "on"
    id: night time
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: fixed time
          - condition: state
            entity_id: binary_sensor.fenster_buro_matthias_nord_2
            state: "on"
        sequence:
          - service: telegram_bot.send_message
            data:
              message: Fenster Büro Matthias ist offen.
          - service: notify.karina_telegram
            data:
              message: Fenster Badezimmer EG ist offen.
      - conditions:
          - condition: trigger
            id: night time
          - condition: time
            after: "19:00:00"
            before: "07:00:00"
        sequence:
          - service: notify.karina_telegram
            data:
              message: Fenster Badezimmer EG ist offen.
1 Like