Window Sensor Alarm

Setup Information:

Raspberry Pi 3
Home Assistant All In One Installer
Aeotec Z-Stick Gen5
Aeotec Siren Gen5, Z-Wave Plus, 105dB siren with strobe alerts, Plug-in, Backup battery
Aeotec by Aeon Labs ZW120 Door / Window Sensor, Small, White

Hi All,
I am trying to put together a simple automation that involves a window/door sensor that when the sensor is removed from its position (tampered with) or the window opens, a siren device sounds for 10 seconds. I’m having some difficulties with my basic knowledge of writing these automations.

For the first part I wrote the below but it is having problems:

- alias: "Left Window Alarm"
  trigger:
    platform: numeric_state
    entity_id: sensor.aeotec_zw120_door_window_sensor_gen5_burglar_5_10
    to: '254'
    from: '0'
  action:
    - service: switch.turn_on
      entity_id: switch.aeotec_zw080_siren_gen5_switch 

Where did I go wrong?

Thanks in advance for any help!

it’s probably in the above: this would only work if you move from value=0 to value=254 in a single step, no other values in between.
What should the sensor.aeotec_zw120_door_window_sensor_gen5_burglar_5_10 normally return?
Personally I don’t like the numeric_state platform, but that’s just a preference, so I’d code it this way:

- alias: "Left Window Alarm"
  trigger:
    platform: numeric_state
    entity_id: sensor.aeotec_zw120_door_window_sensor_gen5_burglar_5_10
    to: '254'
    from: '0'
  condition:
    - condition: template
      value_template: '{{ states.sensor.aeotec_zw120_door_window_sensor_gen5_burglar_5_10.state >= xxx }}'
  action:
    - service: switch.turn_on
      entity_id: switch.aeotec_zw080_siren_gen5_switch

Where xxx is the value you want to check to be true to make the automation work…

Really appreciate the help.

The values for the burglar portion of the sensor are:

254 = sensor removed
3 = sensor misconfigured
0 = normal state

Did I correct what I written? Wasn’t sure if I should remove the to & from values with your based on your value_template suggestion.

- alias: "Left Window Alarm"
  trigger:
    platform: numeric_state
    entity_id: sensor.aeotec_zw120_door_window_sensor_gen5_burglar_5_10
    to: '254'
    from: '0'
  condition:
  - condition: template
    value_template: '{{ states.sensor.aeotec_zw120_door_window_sensor_gen5_burglar_5_10.state >= 0 }}'
  action:
    - service: switch.turn_on
      entity_id: switch.aeotec_zw080_siren_gen5_switch

How about something along these lines?

- alias: "Left Window Alarm"
    trigger:
      - platform: state
        entity_id: sensor.aeotec_zw120_door_window_sensor_gen5_burglar_5_10
        to: '254'
    
    action:
      - service: switch.turn_on
        entity_id: switch.aeotec_zw080_siren_gen5_switch

I have a similar automation to tell when a door is open. Seems to work here.

This feedback is a huge help.

Since there are two windows in the bedroom both with a sensor on each window, is there a way to write the automation where I can include both in the same YAML file instead of creating a YAML file for the right window and one for the left window?

The only different in the entity_id is one has _2 on the end to identify each separately.

- alias: "Window Sensor Tampered"
  trigger:
    - platform: state
      entity_id: sensor.aeotec_zw120_door_window_sensor_gen5_burglar
      to: '254'
  action:
    - service: switch.turn_on
      entity_id: switch.aeotec_zw080_siren_gen5_switch
    - delay: '00:00:05'
    - service: switch.turn_off
      entity_id: switch.aeotec_zw080_siren_gen5_switch
  trigger:
    - platform: state
      entity_id: sensor.aeotec_zw120_door_window_sensor_gen5_burglar_2
      to: '254'
  action:
    - service: switch.turn_on
      entity_id: switch.aeotec_zw080_siren_gen5_switch
    - delay: '00:00:05'
    - service: switch.turn_off
      entity_id: switch.aeotec_zw080_siren_gen5_switch

Thanks again for all the help!

Try something like this:

- alias: "Window Sensor Tampered"
  trigger:
    - platform: state
      entity_id: sensor.aeotec_zw120_door_window_sensor_gen5_burglar
      to: '254'
    - platform: state
      entity_id: sensor.aeotec_zw120_door_window_sensor_gen5_burglar_2
      to: '254'
  action:
    - service: switch.turn_on
      entity_id: switch.aeotec_zw080_siren_gen5_switch
    - delay: '00:00:05'
    - service: switch.turn_off
      entity_id: switch.aeotec_zw080_siren_gen5_switch

Multiple triggers have an implied “or”. So this says if either sensor goes to 254 then sound the siren.

Hope this helps.