Coder Social home page Coder Social logo

c-st / auto_areas Goto Github PK

View Code? Open in Web Editor NEW
24.0 2.0 5.0 436 KB

๐Ÿค– A custom component for Home Assistant which automates your areas.

License: MIT License

Python 98.12% Shell 1.88%
home-assistant home-assistant-custom custom-component home-automation

auto_areas's Introduction

๐Ÿค– Auto Areas

A custom component for Home Assistant which automates your areas.

An area in Home Assistant can represent a room or any other part of your home. Relevant entities and devices can be assigned to these areas; making it possible to create certain kind of automations automatically.

Example setup of areas and entities:

- Living room (Area)
  - Motion sensor
  - Motion sensor 2
  - Illuminance sensor
  - Light
  - Light 2
  - Light 3
- Bedroom (Area)
  - Motion sensor
  - Illuminance sensor
  - Light
- Office (Area)
  - Motion sensor
  - Light
- Kitchen (Area)
  - Motion sensor
  - Light

Desired behaviour:

  • if there is one or more motion sensors assigned to a room, all of them are used to determine if the room is currently occupied
  • the lights in this room should be turned on if presence is detected
  • additionally the lights should only be turned on if it's sufficiently dark in the area
  • once no presence is detected anymore, the lights should turn off again

To achieve this, without this component, it would be necessary to set up automations for all sensors and lights for each of the areas.


For information on how to install this component see Installation.

Features

See how ๐Ÿค– Auto Areas can take over some of this work:

Aggregated presence detection

Tracks the state of multiple sensor entities (for example motion sensors) to detect area presence. It aggregates presence based on these rules:

  • An area is considered "occupied" if there is at least one sensor in state on (for example motion is detected)
  • Only if all sensors are off the area presence is cleared and the area is considered empty

Currently binary_sensor entities with device class: motion, occupancy, presence are supported.

The presence state is published to a single binary_sensor which will be named according to the area: binary_sensor.area_presence_{area_name}.

Presence lock

If only relying on motion sensors, presence could be cleared if there is only little or no movement. Presence lock can be used to treat an area as "occupied" regardless of sensor state.

A new switch with ID switch.area_presence_lock_{area_name} is created for each area. If the switch is on, lights will not be turned off.

Aggregated illuminance

Tracks all illuminance measuring sensors in an area. The last known illuminance of all sensors is used. This illuminance is published in a sensor with the ID sensor.area_illuminance_{area_name}.

Control lights automatically

Lights are automatically turned on and off based on presence in an area.

By default all light entities of an area are managed. A list of entities to be ignored can be defined in the configuration options.

Illuminance

To not turn on lights during daytime an illuminance threshold can be configured. Only if an illuminance below this threshold is measured, the lights are turned on. Illuminance is constantly monitored: if an area is constantly occupied, lights would turn on once it's sufficiently dark in the area.

Sleep mode

For areas marked as "sleeping area", automatic light control can be temporarily turned off. Lights are never turned on even if presence is detected.

A switch with ID switch.area_sleep_mode_{area_name} is created for each sleeping area. If the switch is turned on, automatic light control will be disabled and lights will stay off.

For information on how to mark an area as "sleeping area" refer to the configuration section.

Installation

Auto Areas is a custom_component for Home Assistant.

  1. The recommended installation method is using HACS: search for "Auto Areas", install it and restart Home Assistant. Alternatively download a release and copy the folder custom_components/auto_areas to the custom_components folder of your Home Assistant installation.
  2. For each area that you want to control with Auto Areas, go to "Settings"/"Devices & Services"/"Add integration" and search for "Auto Areas". You can then create an instance for each area you want to manage.

Configuration

Navigate to "Settings"/"Devices & Services"/"Auto Areas" and select the area for which you want to change the options for. Select "Configure" and change the behaviour with the following options:

Area option Description Default value
Set as sleeping area Mark area as sleeping area. A switch for controlling sleep mode is created. See more false (disabled)
Excluded light entities Entities to exclude from automatic light control. These lights are never turned on or off. [] (none)
Illuminance threshold Only if area illuminance is lower than this threshold, lights are turned on. 0

Development

Using DevContainer is recommended (see config in .devcontainer).

auto_areas's People

Contributors

c-st avatar dependabot[bot] avatar jlverhagen avatar misa1515 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

auto_areas's Issues

Reset presence lock automatically

The motivation behind presence lock is to keep the light from going out if there is not much movement in an area. However, if forgotten It will keep the lights on indefinitely.

Discover how it could be reset automatically:

  • based on time (after x minutes/hours)
  • x hours after last presence was detected
  • on the next day (sunrise)

Additionally it should be disabled if:

  • sleep mode is turned on
  • lights are turned off manually (?)

Scenes auto discovery (naming convention)

If scenes are found which are named according to a given pattern, they will automatically be used - no configuration necessary.

Suggestion by @rsnodgrass

        # Auto discovery of scenes ... decided EXPLICIT scene setting is better for V1
        #        self.presence_scene_entity_id = f"scene.{self.area_name}_presence"
        #        self.goodbye_scene_entity_id = f"scene.{self.area_name}_goodbye"
        #        for entity in all_entities:
        #            if not entity.domain in SCENE_DOMAIN:
        #                continue
        #            if 'Presence' in entity.name:
        #                self.presence_scene_entity_id = ''

Utilize scene.turn_on instead of turning on ALL lights when presence detected

Currently auto_areas assumes that ALL lights assigned to a room should be turned on (full) upon entry to the room.

Ideally, a scene could be assigned for room entry which allows setting which lights to turn on, at what dimmable level, as well as other devices in a room that might be turned on (e.g. a fan, or climate setting). For leaving a room, a second scene would be needed to set the "away" settings for a room.

Lock or Sleep Mode Switch do not stay on

System Health details

System Information

version | core-2023.6.3
installation_type | Home Assistant OS
dev | false
hassio | true
docker | true
user | root
virtualenv | false
python_version | 3.11.4
os_name | Linux
os_version | 6.1.21-v8
arch | aarch64

Home Assistant Supervisor

host_os | Home Assistant OS 10.3
update_channel | stable
supervisor_version | supervisor-2023.06.2
agent_version | 1.5.1
docker_version | 23.0.6

Checklist

  • I have enabled debug logging for my installation.
  • I have filled out the issue template to the best of my ability.
  • This issue only contains 1 issue (if you have multiple issues, open one issue for each issue).
  • This issue is not a duplicate issue of currently previous issues..

Describe the issue

The app itself works well, but there are problems with the switches.
Sometimes I have the problem that, for example, the sleep mode can be activated initially. Later (sporadically) it jumps back to disabled and can no longer be switched on.

I just noticed it when I deleted another integration.
When I restart Homeassistant, this error is briefly resolved.

The whole thing also affects every created room and not just individual ones.

Reproduction steps

  1. Configure Room and take the switch on
  2. Delete some integration or change config

Debug logs

2023-06-26 15:01:46.498 WARNING (MainThread) [homeassistant.helpers.service] Unable to find referenced entities light.kuche or it is/they are currently not available
2023-06-26 15:01:46.501 WARNING (MainThread) [homeassistant.helpers.service] Unable to find referenced entities light.kuche or it is/they are currently not available
2023-06-26 15:01:46.505 WARNING (MainThread) [homeassistant.helpers.service] Unable to find referenced entities light.kuche or it is/they are currently not available
2023-06-26 15:01:46.507 WARNING (MainThread) [homeassistant.helpers.service] Unable to find referenced entities light.kuche or it is/they are currently not available
2023-06-26 15:01:46.510 WARNING (MainThread) [homeassistant.helpers.service] Unable to find referenced entities light.kuche or it is/they are currently not available
2023-06-26 15:01:46.512 WARNING (MainThread) [homeassistant.helpers.service] Unable to find referenced entities light.kuche or it is/they are currently not available
2023-06-26 15:01:46.514 WARNING (MainThread) [homeassistant.helpers.service] Unable to find referenced entities light.kuche or it is/they are currently not available
2023-06-26 15:01:46.517 WARNING (MainThread) [homeassistant.helpers.service] Unable to find referenced entities light.kuche or it is/they are currently not available
2023-06-26 15:01:46.521 WARNING (MainThread) [homeassistant.helpers.service] Unable to find referenced entities light.kuche or it is/they are currently not available
2023-06-26 15:01:46.525 WARNING (MainThread) [homeassistant.helpers.service] Unable to find referenced entities light.kuche or it is/they are currently not available
2023-06-26 15:01:46.528 WARNING (MainThread) [homeassistant.helpers.service] Unable to find referenced entities light.kuche or it is/they are currently not available
2023-06-26 15:01:46.530 WARNING (MainThread) [homeassistant.helpers.service] Unable to find referenced entities light.kuche or it is/they are currently not available
2023-06-26 15:01:46.533 WARNING (MainThread) [homeassistant.helpers.service] Unable to find referenced entities light.kuche or it is/they are currently not available
2023-06-26 15:01:46.535 WARNING (MainThread) [homeassistant.helpers.service] Unable to find referenced entities light.kuche or it is/they are currently not available

Diagnostics dump

No response

Aggregate sensor values

Measurement values for

  • temperature
  • humidity
  • illuminance
  • pressure

from multiple devices are aggregated per area (median) and exposed as additional sensors (for example sensor.area_temperature_bedroom).

Also the presence of all areas could be aggregated in a single binary_sensor.any_area_occupied that determines if ANY of the areas occupancy switches are on (device_class: presence) (cc @rsnodgrass)

more device_classes

Join forces with magic_areas?

Checklist

  • I have filled out the template to the best of my ability.
  • This only contains 1 feature request (if you have multiple feature requests, open one feature request for each feature request).
  • This issue is not a duplicate feature request of previous feature requests.

Is your feature request related to a problem? Please describe.

Hey, this looks great but also closely resembles magic_areas integration. Maybe you can combine forces?

https://github.com/jseidl/hass-magic_areas

Describe the solution you'd like

Have 1 integration that is better than choosing between 2

Describe alternatives you've considered

See above

Additional context

None needed

Only turn on lights if illuminance is below a certain threshold

  • aggregate illuminance in additional sensor
  • make threshold configurable (brightness below n lux)
  • evaluate sensor before turning on light
  • during presence, if brightness goes below threshold, turn on light
  • only turn on lights once (not repeatedly with every illuminance change)
  • stop turning on lights after they have been manually controlled

Define how to handle:

  • it goes dark while there is presence but lights are not on. For example: sun is setting in a consistently occupied room or blinds are closed during the day. illuminance threshold is also evaluated during presence
  • outdated illuminance sensor values? Battery-based devices don't broadcast their state very often. Take time of last update into account? always the latest state of all entities is considered
  • if light is turned off during presence it should not be turned on automatically based on illuminance

Automatic lighting only at night?

Is your feature request related to a problem? Please describe.
I do not need automatic lighting in all areas.
"Downstairs", "Garage" & "Bathroom" would be the only areas needing 24x7 artificial lighting.

Describe the solution you'd like
Additional entitiies utilized to control automatic lighting.
Eg.

  1. binary_sensor, device class light.
  2. sensor, device class illuminance. This entity would require a threshold though to be specified which could get tricky so, a user created binary_sensor template with device_class light would be the easiest and the integration need only check if that sensor is off.

Describe alternatives you've considered
Create automations to control the area_presence_lock entity, which is kludgy!

Additional context
None.

Aggregate sensor values

Measurement values for

  • temperature (avg)
  • humidity (max)
  • illuminance (min)

from multiple devices are aggregated per area and exposed as additional sensors (for example sensor.area_temperature_bedroom).

more device_classes

Cover control

A new cover entity for all covers in an area is created. This can be used to quickly

  • close
  • open
  • set to a given position

all shades in an area at the same time.

Considerations:

  • happy path: all covers have the same position and are always controlled at the same time. This way a position for the entity can be determined.
  • think about: how to handle different position among all covers in an area (don't publish a position?)

Add general override

This system is very cool but until the user sets it up completely, there should be a general on/off switch that turns Auto Areas completely on and off so it doesn't interfere with existing automations.

Integration is using deprecated `DEVICE_CLASS_*` constants

Version of the custom_component

Any

Configuration

n/a

Describe the bug

This custom integration uses deprecated DEVICE_CLASS_* constants in its codebase.

The DEVICE_CLASS_* constants have been deprecated and replaced in Home Assistant Core 2021.12 (over a year ago). I would highly suggest updating/migrating this integration to the new enums.

For example, for the device classes supported by the sensor platform, there is now a SensorDeviceClass enum. So if a sensor previously used the DEVICE_CLASS_ENERGY constant, it should now use SensorDeviceClass.ENERGY. Other platforms (like binary_sensor, and number) provide similar enumerations for their supported device classes.

The migration thus only consists of replacing constants with an enumeration member and is, therefore, very low impact and should be fairly straightforward.

If I can help resolve any questions regarding this change or migration, feel free to ask or respond to this issue. I'm happy to help!

Kindest regards,

../Frenck

Debug log


n/a

Have the option to use switches for lights.

Checklist

  • I have filled out the template to the best of my ability.
  • This only contains 1 feature request (if you have multiple feature requests, open one feature request for each feature request).
  • This issue is not a duplicate feature request of previous feature requests.

Is your feature request related to a problem? Please describe.

I would like to include switches as well as lights, as we have zonoff mini switches in our bathrooms that control fans and lights and so I can't control just the light without the switch also being on.

Describe the solution you'd like

For an Area to have the option to include switches as well that are triggered along with the lights.

Describe alternatives you've considered

Automations, but this would just make life easier as they can be a pain.

Additional context

None

Add switch for presence lock to each area

Sometimes an area is occupied but the motion sensors are not receiving enough movement. For example this could be happening if someone is reading. In order to avoid clearing presence an additional switch could be added.
If enabled, this switch locks presence and avoids that the lights turn off.

All of my areas are "managed" even with no motion/occupancy/presence or light entities in them

Version of the custom_component

v1.0.3

Configuration

auto_areas:
  bedroom:
    is_sleeping_area: true

Describe the bug

"It checks each of your areas for relevant devices and starts managing them automatically. Additionally, it creates a few sensors and switches which allow you to adjust its behaviour as needed." - As it stands now, it manages all of my areas, even if there are no motion, occupancy or presence sensors in the area.

image

image

Debug log

N/A

Can not configure

System Health details

System Information

version core-2023.5.3
installation_type Home Assistant OS
dev false
hassio true
docker true
user root
virtualenv false
python_version 3.10.11
os_name Linux
os_version 6.1.25
arch aarch64
timezone Europe/Amsterdam
config_dir /config
Home Assistant Community Store
GitHub API ok
GitHub Content ok
GitHub Web ok
GitHub API Calls Remaining 5000
Installed Version 1.32.1
Stage running
Available Repositories 1294
Downloaded Repositories 57
HACS Data ok
AccuWeather
can_reach_server ok
remaining_requests 26
Home Assistant Cloud
logged_in true
subscription_expiration August 1, 2023 at 2:00 AM
relayer_connected true
relayer_region eu-central-1
remote_enabled true
remote_connected true
alexa_enabled false
google_enabled true
remote_server eu-central-1-10.ui.nabu.casa
certificate_status ready
can_reach_cert_server ok
can_reach_cloud_auth ok
can_reach_cloud ok
Home Assistant Supervisor
host_os Home Assistant OS 10.1
update_channel stable
supervisor_version supervisor-2023.04.1
agent_version 1.5.1
docker_version 23.0.3
disk_total 117.3 GB
disk_used 38.0 GB
healthy true
supported true
board odroid-n2
supervisor_api ok
version_api ok
installed_addons Home Assistant Google Drive Backup (0.107.2), AppDaemon (0.13.0), File editor (5.6.0), Glances (0.19.2), Mosquitto broker (6.2.1), Samba share (10.0.1), Terminal & SSH (9.7.0), Log Viewer (0.15.1), ESPHome (2023.5.3), Studio Code Server (5.6.0), Rhasspy Assistant (2.5.11), Dutch TTS voice (rdh) (1.0.3), FTP (4.7.0), InfluxDB (4.7.0), Grafana (8.3.0), Music Assistant BETA (2.0.0b30), Node-RED (14.2.0)
Dashboards
dashboards 1
resources 30
views 16
mode yaml
Recorder
oldest_recorder_run May 13, 2023 at 2:22 PM
current_recorder_run May 23, 2023 at 3:58 PM
estimated_db_size 1624.13 MiB
database_engine sqlite
database_version 3.40.1
Sonoff
version 3.5.1 (122751c)
cloud_online 1 / 2
local_online 1 / 1
[home-assistant_2023-05-23T14-05-41.282Z.log](https://github.com/c-st/auto_areas/files/11544962/home-assistant_2023-05-23T14-05-41.282Z.log)
Xiaomi MIoT
logged_in true
can_reach_micloud_server ok
accounts_count 1
account_devices_count 4
added_devices 1

Checklist

  • I have enabled debug logging for my installation.
  • I have filled out the issue template to the best of my ability.
  • This issue only contains 1 issue (if you have multiple issues, open one issue for each issue).
  • This issue is not a duplicate issue of currently previous issues..

Describe the issue

When I try to configure an area I get the following error:
Config flow could not be loaded: 500 Internal Server Error Server got itself in trouble

Reproduction steps

  1. try to configure an area

...

Debug logs

see attachment

Diagnostics dump

NA

Do not use deprecated HA API

Describe the bug

Auto Areas uses deprecated functionality from HA:

2023-01-10 21:58:25.604 WARNING (MainThread) [homeassistant.helpers.frame] Detected integration that uses deprecated `async_get_registry` to access area registry, use async_get instead. Please report issue to the custom integration author for auto_areas using this method at custom_components/auto_areas/binary_sensor.py, line 27: area_registry: AreaRegistry = await hass.helpers.area_registry.async_get_registry()
2023-01-10 21:58:25.611 WARNING (MainThread) [homeassistant.helpers.frame] Detected integration that uses deprecated `async_get_registry` to access entity registry, use async_get instead. Please report issue to the custom integration author for auto_areas using this method at custom_components/auto_areas/binary_sensor.py, line 29: await hass.helpers.entity_registry.async_get_registry()
2023-01-10 21:58:25.619 WARNING (MainThread) [homeassistant.helpers.frame] Detected integration that uses deprecated `async_get_registry` to access device registry, use async_get instead. Please report issue to the custom integration author for auto_areas using this method at custom_components/auto_areas/binary_sensor.py, line 32: await hass.helpers.device_registry.async_get_registry()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.