2018-06-14 02:41:31 +00:00
|
|
|
automation:
|
2018-06-14 20:38:20 +00:00
|
|
|
- alias: Turn off lights when unoccupied
|
2018-06-14 02:41:31 +00:00
|
|
|
action:
|
|
|
|
- service: light.turn_off
|
|
|
|
data:
|
|
|
|
entity_id: group.all_lights
|
|
|
|
trigger:
|
|
|
|
- platform: state
|
|
|
|
entity_id: binary_sensor.occupied
|
|
|
|
to: 'off'
|
|
|
|
- alias: Set occupied
|
|
|
|
action:
|
|
|
|
- service: input_boolean.turn_on
|
|
|
|
data:
|
|
|
|
entity_id: input_boolean.occupied
|
|
|
|
trigger:
|
|
|
|
- platform: state
|
|
|
|
entity_id: binary_sensor.activity
|
|
|
|
to: 'on'
|
|
|
|
condition:
|
|
|
|
- condition: state
|
|
|
|
entity_id: group.phones
|
|
|
|
state: 'not_home'
|
|
|
|
- alias: Unset occupied
|
|
|
|
action:
|
|
|
|
- service: input_boolean.turn_off
|
|
|
|
data:
|
|
|
|
entity_id: input_boolean.occupied
|
|
|
|
trigger:
|
|
|
|
- platform: state
|
|
|
|
entity_id: binary_sensor.activity
|
|
|
|
to: 'off'
|
|
|
|
for:
|
|
|
|
minutes: 10
|
|
|
|
- platform: state
|
|
|
|
entity_id: group.phones
|
|
|
|
to: 'not_home'
|
|
|
|
for:
|
|
|
|
minutes: 10
|
|
|
|
condition:
|
|
|
|
- condition: state
|
|
|
|
entity_id: group.phones
|
|
|
|
state: 'not_home'
|
|
|
|
- condition: state
|
|
|
|
entity_id: binary_sensor.activity
|
|
|
|
state: 'off'
|
2018-06-14 21:45:00 +00:00
|
|
|
- alias: Welcome home
|
|
|
|
action:
|
|
|
|
- delay: '00:00:05'
|
|
|
|
- service: script.sonos_tts
|
|
|
|
data_template:
|
|
|
|
message: >-
|
2018-06-29 19:15:14 +00:00
|
|
|
{% set occupants
|
|
|
|
= states.sensor.occupants.state.split(', ')
|
|
|
|
| select
|
|
|
|
| reject('equalto', 'Somebody')
|
|
|
|
| join(', ')
|
|
|
|
%}
|
|
|
|
Welcome home
|
|
|
|
{{ occupants }}!
|
2018-06-14 21:45:00 +00:00
|
|
|
trigger:
|
|
|
|
- entity_id: binary_sensor.occupied
|
|
|
|
platform: state
|
2018-06-29 19:15:14 +00:00
|
|
|
to: 'on'
|
|
|
|
- alias: Notify me when someone arrives at home
|
|
|
|
action:
|
|
|
|
- service: notify.correl
|
|
|
|
data_template:
|
|
|
|
title: Occupancy
|
|
|
|
message: >-
|
|
|
|
{% set occupants = states.sensor.occupants.state.split(', ')
|
|
|
|
%}
|
|
|
|
{% if occupants | length == 0 %}
|
|
|
|
Nobody is home
|
|
|
|
{% elif occupants | length == 1 %}
|
|
|
|
{{ occupants[0] }} is home
|
|
|
|
{% else %}
|
|
|
|
{{ occupants[:-2].join(', ') }}
|
|
|
|
{{ occupants[-2].join(' and ') }}
|
|
|
|
are home
|
|
|
|
{% endif %}
|
|
|
|
trigger:
|
|
|
|
- platform: state
|
|
|
|
entity_id: sensor.occupants
|
|
|
|
condition:
|
|
|
|
- condition: template
|
|
|
|
value_template: >-
|
|
|
|
{% set from = trigger.from_state.state.split(', ') | select %}
|
|
|
|
{% set to = trigger.to_state.state.split(', ') | select %}
|
|
|
|
{{ from|reject('equalto', 'Correl') | sort
|
|
|
|
!= to|reject('equalto', 'Correl') | sort
|
|
|
|
}}
|
2018-06-30 00:44:02 +00:00
|
|
|
- alias: Turn the lights on
|
|
|
|
action:
|
|
|
|
- service: scene.turn_on
|
|
|
|
data:
|
|
|
|
entity_id: scene.normal_brightness
|
|
|
|
trigger:
|
|
|
|
- entity_id: binary_sensor.occupied
|
|
|
|
platform: state
|
|
|
|
to: 'on'
|
|
|
|
condition:
|
|
|
|
- condition: state
|
|
|
|
entity_id: group.all_lights
|
|
|
|
state: 'off'
|
|
|
|
- condition: or
|
|
|
|
conditions:
|
|
|
|
- condition: sun
|
|
|
|
after: sunset
|
|
|
|
- condition: sun
|
|
|
|
before: sunrise
|
|
|
|
- condition: numeric_state
|
|
|
|
entity_id: sensor.living_room_camera_light_level
|
|
|
|
below: 20
|
2018-06-14 02:41:31 +00:00
|
|
|
|
|
|
|
input_boolean:
|
|
|
|
occupied:
|
|
|
|
name: House is occupied
|
|
|
|
icon: mdi:home
|
|
|
|
|
|
|
|
binary_sensor:
|
|
|
|
- platform: template
|
|
|
|
sensors:
|
|
|
|
occupied:
|
|
|
|
friendly_name: Somebody is home
|
|
|
|
device_class: occupancy
|
|
|
|
value_template: >-
|
|
|
|
{{ is_state('group.phones', 'home')
|
|
|
|
or is_state('input_boolean.occupied', 'on')
|
|
|
|
}}
|
|
|
|
activity:
|
|
|
|
friendly_name: House in use
|
|
|
|
device_class: occupancy
|
|
|
|
value_template: >-
|
|
|
|
{{ is_state('group.all_lights', 'on')
|
|
|
|
or is_state('media_player.den', 'playing')
|
|
|
|
}}
|
2018-06-29 19:15:14 +00:00
|
|
|
sensor:
|
|
|
|
- platform: template
|
|
|
|
sensors:
|
|
|
|
occupants:
|
|
|
|
friendly_name: List of occupants
|
|
|
|
value_template: >-
|
|
|
|
{% if is_state('binary_sensor.occupied', 'on') %}
|
|
|
|
{{ states
|
|
|
|
| selectattr("entity_id", "in",
|
|
|
|
states.group.phones.attributes.entity_id)
|
|
|
|
| selectattr('state', 'eq', 'home')
|
|
|
|
| map(attribute='attributes.friendly_name')
|
|
|
|
| join(', ')
|
|
|
|
| default('Somebody', true)
|
|
|
|
}}
|
|
|
|
{% endif %}
|
2018-06-14 20:38:20 +00:00
|
|
|
group:
|
|
|
|
Occupancy:
|
|
|
|
view: yes
|
|
|
|
icon: mdi:account-group
|
|
|
|
entities:
|
|
|
|
- binary_sensor.occupied
|
|
|
|
- binary_sensor.activity
|
|
|
|
- group.phones
|
|
|
|
- group.occupancy_automations
|
|
|
|
- group.occupancy_overrides
|
|
|
|
occupancy_automations:
|
|
|
|
name: Automations
|
|
|
|
entities:
|
|
|
|
- automation.turn_off_lights_when_unoccupied
|
|
|
|
- automation.set_occupied
|
|
|
|
- automation.unset_occupied
|
2018-06-14 21:45:00 +00:00
|
|
|
- automation.welcome_home
|
2018-06-14 20:38:20 +00:00
|
|
|
occupancy_overrides:
|
|
|
|
name: Overrides
|
|
|
|
entities:
|
|
|
|
- input_boolean.occupied
|