Automation condition - to message when to close windows when one is open - and it's warmer outside - is_state and value_template condition

I wrote the automation below to tells when to close the windows to keep the house cool. Basic premise is to open windows when it’s cooler out and close them when the opposite is true. This automation scripted “worked” until I tried to add the condition that a window is open. The binary sensor is the open sensor on our patio slider. It’s state is ‘on’ when the door is open. Any idea what I’m doing wrong?

  - condition: template
    value_template: "{{is_state('binary_sensor.living_room', 'on')}}"

If I can get this working I will add a check on any of the windows being open with an or check.

- id: 'XXXXXXXXX899'
  alias: Close windows
  description: ''
  trigger:
  - entity_id: binary_sensor.cool_inside
    from: 'off'
    platform: state
    to: 'on'
  condition:
  - after: sunrise
    condition: sun
  - condition: template
    value_template: "{{is_state('binary_sensor.living_room', 'on')}}"
  action:
  - data:
      message: Time to close the windows to keep the house cool.
    service: notify.notify
  - data:
      message: Time to close the windows to keep the house cool.
    service: persistent_notification.create
  mode: single

It could be something as simple as that hyphon in the wrong place. You could try this:-

- id: 'XXXXXXXXX899'
  alias: Close windows
  description: ''
  trigger:
  - entity_id: binary_sensor.cool_inside
    from: 'off'
    platform: state
    to: 'on'
  condition:
  - condition: sun
    after: sunrise
  - condition: template
    value_template: "{{is_state('binary_sensor.living_room', 'on')}}"
  action:
  - data:
      message: Time to close the windows to keep the house cool.
    service: notify.notify
  - data:
      message: Time to close the windows to keep the house cool.
    service: persistent_notification.create
  mode: single

By the time you’ve tried that, one of the veterans will probably come back with a sensible answer :smile: :+1:

1 Like

Order shouldn’t matter there, so I don’t think that will help. I don’t see anything obviously wrong with the conditions, so I can only explain what I think that automation will do:

  • If binary_sensor.cool_inside turns on (presumably indicating that it’s cooler inside?)
  • AND it’s after sunrise and before midnight
  • AND a window is open
  • Notify you

If that’s what you want, it looks like it should work. If not, perhaps you could point out the difference in intent.

Also, make sure that the template gives the expected result in :hammer:->Templates.

Thanks both. I can confirm the order in the sunrise condition did not make it work.@rccoleman that is exactly what I want to have happen. I checked the individual conditions and the all toggle appropriately when independent fact the notification happens if I just remove the window on (open) condition. From what I can tell the binary sensor is either “on” or “off”. That said in history it shows “open” or “closed”.

What does the state say in Dev->States?

Off - when it’s closed.

I’m at a loss. Here’s a test that I just wrote and works fine:

- alias: test
  initial_state: true
  trigger:
    - platform: state
      entity_id: binary_sensor.aarlo_motion_back_door
      from: 'off'
      to: 'on'
  condition:
    - condition: sun
      after: sunrise
    - condition: template
      value_template: "{{ is_state('binary_sensor.syn_nas_security_status', 'on') }}"
  action:
    service: persistent_notification.create
    data:
      message: foobar

Did you run a config check and reload your automations? Is the automation enabled?

How did you test it? Did you wait for the binary sensor to change to ‘on’ and left the window open?

Yes.

Good news - I think I found my problem. On Sunday, I decided to open the automation file directly in a text editor vs the automation UI. To my surprise there were a couple “\n” end of line characters, I didn’t expect. I think they were added by the automation UI. I removed them on a whim - and it worked today.

image

I’ll do some more testing. Thanks a ton for the help.

I’ve seen that kind of change in examples on Discord from the UI and I don’t know why it does that. It had to be something like that.

Glad you got it working.