Zones and Automation

Project Overview

Turn on door alarm alerts to the phone when not at home, and turn off door alarm alerts when at home.

Receiving alerts outside of the home assistant's network requires some kind of remote access for your phone app. Nabu Casa is an easy and secure way, but there are other methods.

The Panel


This is from a dashboard.

"Door Alarm Notify Only" is an input boolean. When this is on, doors being opened will trigger an automation to message users whenever a door sensor turns on. When it is off, no messages are generated. This is called Door Alarm Notify Only, as opposed to when the security alarm is engaged. (Code was removed from this blogger post.)

"Smoke Alarm Notify Only" [clear] is not part of the automation. (When it is not clear, it uses an automation to send a notification.)

"Door Ajar Notify" is an input boolean. When on, if a door sensor is open for more than 15 seconds, it generates an alert. (This is always on, but if it is generating bad messages, there should be a way to turn off this automation on a cellphone.)

"Elmer Away Notify" is an input boolean. This is a condition check for the automations. This input boolean could be skipped, but it allows the disabling of automations through your phone app.

These input booleans were created through Settings>Devices & Services>Helpers>Create Helper>Toggle. (Toggle is found by scrolling down.)

There is an older process where input booleans are hard-coded in config/input_boolean.yaml, and turned on in config/configuration.yaml with the line "input_boolean: !include input_boolean.yaml". When they are hard-coded in configuration files, they cannot be edited in the easier process.

Zones

The only necessary zone for this project is a zone.home. This can be hard-coded, or created a fast way through Settings>Areas & Zones>Zones>Add Zone.

The Automations

Automations are made through Settings>Automations & Scenes>Automations. There were not any easy blueprints to use, but these are basic automations.

Door Notify Only

There are two triggers. In the future, there will be trigger ids that generate specific door opening messages. (Alternatively, create a separate automation for each door.)

alias: Door Notify Only
description: ''
trigger:
  - platform: state
    entity_id: binary_sensor.front_door_is_open
    to: 'on'
  - platform: state
    entity_id: binary_sensor.back_door_is_open
    to: 'on'
condition:
  - condition: state
    state: 'on'
    entity_id: input_boolean.door_alarm_notify_only
action:
  - service: notify.notify
    data:
      message: Door opened
      title: Notify Alarm only
mode: single

The input boolean "Door Alarm Notify Only" is checked as a condition,allowing finer control of notification automations. A user might want to receive door notifications when home occasionally. Turning this input boolean on or off from a dashboard is an easy process.

Everyone Leaves

There is one trigger - zone.home equaling 0 (below 1) for at least 10 seconds. Then it checks for "Elmer Away Notify" input boolean being on. It processes one action: turn on the input boolean "Door Alarm Notify Only". This chains into the previous automation.

alias: Everyone Leaves
description: ''
trigger:
  - platform: numeric_state
    entity_id: zone.home
    for:
      hours: 0
      minutes: 0
      seconds: 10
    below: '1'
condition:
  - condition: state
    entity_id: input_boolean.elmer_away_notify
    state: 'on'
action:
  - service: input_boolean.turn_on
    data: {}
    target:
      entity_id: input_boolean.door_alarm_notify_only
mode: single

This was the first time using Call Service, where the service was "Input boolean: Turn On". Using "Condition" and "State" does not work to assign a state for input booleans, at least at this time.

Someone Returns

This automation is much like Everyone Leaves, where it checks the zone.home count - if it is above 0, checks the Elmer Away Notify condition. It will then turn off door notifications.

alias: Someone Returns
description: ''
trigger:
  - platform: numeric_state
    entity_id: zone.home
    for:
      hours: 0
      minutes: 0
      seconds: 10
    above: '0'
condition:
  - condition: state
    entity_id: input_boolean.elmer_away_notify
    state: 'on'
action:
  - service: input_boolean.turn_off
    data: {}
    target:
      entity_id: input_boolean.door_alarm_notify_only
mode: single

Things Learned

As mentioned, the action of "Call Service > Input boolean: Turn On" was a first-time use. Why couldn't "Condition > State" work, by assigning a state to an entity?

The current version of Home Assistant (2022.7.7) has an oddity when working on automations in visual editor mode. After a part of an automation is disabled, it adds a line "enabled: false" to the yaml. Enable that part of the code, the yaml line changes to "enabled: true". (If there is no enabled line of code, it is by default true.) Visual editor is not an option until you remove the line in yaml.

Creating zones and helpers (toggle/input booleans) are easier, and reduces the need to edit configuration files.

Comments

Popular posts from this blog

Home Assistant Controlling Octoprint through MQTT - Chapter 1

Setting up MQTT on HA and Octoprint

Home Assistant Controlling Octoprint through MQTT - Chapter 2