Areas no longer suck! Magic Areas will bring your Areas to life with area presence state tracking, aggregations and automations!

DISCLAIMER!!!
I do not check this post often, if you have questions or need help, hop onto our discord server at Magic Areas!

Tired of writing the same automations, over and over, for each of your rooms? Annoyed that some entities can’t be tied to Areas in the Area Registry ? Would like to have a single motion sensor that is grouped to all your other motion sensors in that area? What if all (most) of your sensor and binary_sensor entities had aggregates (grouping/average), PER AREA?

If you think all of the above features are freaking awesome, Magic Areas is here for you!

Some of the features are:

  • Uses multiple type of sensors for determining presence on an area.
    • media_player , binary_sensors ( motion , presence , occupancy and door ) are supported.
  • Loads areas from Area RegistryNo need of handling them elsewhere! .
  • Support inclusion of non-device-tied entities (non-discovery MQTT/Template sensors).
  • Support exclusion of entities.
  • Automatic turn climates and lights on! (All or user-defined).
    • Specify a disable_entity for when lights shouldn’t turn on (e.g. daytime, high luminance etc)
    • Specify a sleep_entity and sleep_lights to have only your accent lights turn on late in night
  • Automatic turn off lights, climate and media devices.
  • Creates a Health sensor (triggered by binary_sensors with problem , smoke , moisture , safety and gas device classes) for each area
  • Creates a Presence Hold switch to manually override area presence
  • Creates aggregation sensors for your binary_sensor :
    • Motion sensors
    • Door sensors
    • Window sensors
    • Leak sensors
  • Creates average sensors for all your sensor
  • Creates global (interior/exterior) aggregate and average sensors

Check out the full blog post here and the code in the GitHub repository.

You can add the repository url to HACS and get updates when they come out. Let me know your thoughts on the comments.

17 Likes

Question: I have Insteon Dimmer in bathroom and have Magic Areas turning the light on/off via motion sensor. No problem there except it turns on at 100% brightness and then Adaptive Lighting dims it to xx brightness. How can I get Magic Areas to turn it on at the AL brightness or alternatively at say 10% and let AL ramp it up as necessary from there?

I figured out how…
Using light_profiles.csv:

relax,0.5119,0.4147,144
concentrate,0.5119,0.4147,219
energize,0.368,0.3686,203
reading,0.4448,0.4066,240
light.ensuite_bathroom.default,0.5119,0.4147,10

P.s.: I love you writing style in your blog post!

2 Likes

This should definitively in the future be an integrated part of Home Assistant. It is a must have. Excellent job, Jan! :slight_smile:

Testing it out now and I’m quite happy so far. Initially I would have wished that my many wall switches that I use for various table lamps, wall lamps, ambient lights etc. was autodected as well. I have defined the switches as lights (https://www.home-assistant.io/integrations/light.switch/)

I know they are entities and not devices, but those spesifically are just a “copy” of a real device. Maybe you are able to add them automatically in a newer version?

Keep up the great work!

1 Like

The component just calls light.turn_on. Good solution!

Hi Frank, thanks for the kind words.

Gotta be honest on this one, I’ve been using the template light for this like a primate! Thanks for letting me know about light.switch. I’ll be changing mines to that and testing. I’ll get back to you once I have some answers.

Changed to the light.switch platform, they’re still working but you’ll need to use the include_entities directive to include them since they’re not tied to a device. Home Assistant just added the ability to add entities to areas and I’m working on an update to reflect that which will effectively render include_entities obsolete (but I’ll keep there just in case).

That would be awesome. If more of your Magic can be dynamic, the better and easier it becomes.

I also have a Nanoleaf light panel that I added as a custom light (Nanoleaf - Home Assistant), but that entity is not possible to add into an area. Haven’t figured out a solution for that yet as it shows up as a read-only entity because it doesn’t have a unique id. I’m new to HA so maybe that can easily be solved.

But I can still add it to include_entities to the right area to make it work. So it will probably always be a need for that option I guess.

I changed my light -platform: switch entities to light: - platform: template for my switched lights so I could add unique_id’s to permit adding them to areas since light -platform: switch does not seem to allow that option last I checked…

  - platform: template
    lights:
      pole_lamp:
        friendly_name: "Pole Lamp"
        unique_id: zwave-pole-lamp
        icon_template: >-
         hass:floor-lamp
        level_template: >-
          {% if is_state('switch.appliance_module_zl7201us_switch','on') %}255{% else %}0{% endif %}
        value_template: >-
          {{ is_state('switch.appliance_module_zl7201us_switch','on') }}
        turn_on:
          service: switch.turn_on
          entity_id: switch.appliance_module_zl7201us_switch
        turn_off:
          service: switch.turn_off
          entity_id: switch.appliance_module_zl7201us_switch
        set_level:
          service_template: >-
            {% if brightness > 0 %}switch.turn_on{% else %}switch.turn_off{% endif %}
          data:
            entity_id: switch.appliance_module_zl7201us_switch

You no longer need to do that. It works fine assigning “switched light” entities to areas.

However, I can’t do it with my Nanoleaf led panel so I will take a closer look at your template to be able to fix it for that one. Thanks for the code!

My Sensative Strips (door sensors) doesn’t seem to show up in the areas they are assigned. As far as I can see, binary sensors should be supported, right Jan?

I would have expected that this z-wave device showed up:

binary_sensor.door_storage_access_control_door_window_open

If not detected, can I add it manually somehow?

That’s true, forgot about the device_id issue!

Yeap, that’s a good trick with the template ones.

I have a Nanoleaf panel, works fine with the include_entities. It’s one of my sleep_lights for one of my rooms.

door and window device class are not included by default as presence sensors, you can add them by overriding the presence_sensor_device_class config option for the area (check MagicAreas doc for more info)

Thank you, Jan! Could you by any chance give us some more real life examples of codes you are using yourself so it is easier to get ideas and see the correct syntax for different options?

In my dining room I have 3 other small storage rooms with door sensors and a zigbee ceiling lightbulb. They work fine. However I would like the dining room to turn active if one of the 3 doors is opened as you have to be in the dining room to open these doors, but I get the following warnings after restarting HA:

Error retrieving device_class for entity 'binary_sensor.dor_matboden_access_control_door_window_open': str_err
Error retrieving device_class for entity 'binary_sensor.dor_vaskerommet_access_control_door_window_open': str_err
Error retrieving device_class for entity 'binary_sensor.dor_pax_access_control_door_window_open': str_err
Error retrieving device_class for entity 'climate.termostat_lemuria': str_err

The last one regarding the generic thermostat is actually working fine even though that one doesn’t have an area (because of a missing unique id). But the 3 binary sensors doesn’t show up. They do have their area defined to the 3 small rooms - which isn’t the dining area.

Is it possible to have a sensor belonging to several areas?

My magic_areas config for these rooms:

  spisestua:
    clear_timeout: 900
    presence_sensor_device_class: ['motion','occupancy','presence','door']
    include_entities:
      - binary_sensor.dor_matboden_access_control_door_window_open
      - binary_sensor.dor_vaskerommet_access_control_door_window_open
      - binary_sensor.dor_pax_access_control_door_window_open
      - light.drikke
      - light.buffe
      - light.te
      - light.kannestol
  matboden:
    presence_sensor_device_class: ['motion','occupancy','presence','door']
  vaskerommet:
    presence_sensor_device_class: ['motion','occupancy','presence','door']
  pax:
    presence_sensor_device_class: ['motion','occupancy','presence','door']

These are either missing the device_class or is being applied after MagicAreas has loaded. Known issue that I’ve been working on

It’s definitely possible. Just include_entities for the other areas you want

I’ll send some of my examples in a little bit

On top of my head

  • I use a template sensor to make a presence sensor of my smart outlets (if consumption goes over Xwatts) to trigger presence on the living room when the TV is on and for the home office (when the monitors are on).
  • Modified bathroom scales for presence in the bed (bedroom) https://synapselabs.io/posts/bed-sensor-with-esphome-on-homeassistant/
  • Contact sensor on my fridge door for presence in the kitchen
  • Tilt sensor on the garage door
  • Binary template sensor with the bathroom humidity threshold for presence in the bathroom during shower

I also use a binary template sensor for power consumption on my aquarium lights, to disable turning on the main ceiling light when the fish tank is already with the lights off (avoid scaring the poor fish).

I’ll try to remember some more and post here, but these are the most important ones.

The device_class is in place as you can see in the magic_area config, so it must be a bug then. Any thoughts on when you will fix it?

Thanks for the examples. Do you have any code to show how you use the sleep_state variable? I would like the areas to stop turning on the lights after 23:00 and not before 05:00. And some areas at different times than that. How do you accompish that?

I have three of these messages but mine are warnings. They are all ZHA devices. Everything is working fine so I just presumed it to be a case of the cart before the horse (loading order).

2021-01-18 15:50:20 WARNING (MainThread) [custom_components.magic_areas] Error retrieving device_class for entity 'binary_sensor.lumi_sensor_motion_living_room': str_err
2021-01-18 15:50:20 WARNING (MainThread) [custom_components.magic_areas] Error retrieving device_class for entity 'binary_sensor.lumi_sensor_motion_front_porch': str_err
2021-01-18 15:50:20 WARNING (MainThread) [custom_components.magic_areas] Error retrieving device_class for entity 'binary_sensor.office_motion': str_err

I use IOT Link on my PC to post info via MQTT to home assistant discovery topic which creates 35 different sensors with info about my PC. Then use the sensor created from homeassistant/sensor/iotlink/brunt-win10_systeminfo_idletime to template an occupancy sensor:

binary_sensor:
# My PC is Active
      my_pc_is_active:
        friendly_name: "My PC is Active"
        device_class: "occupancy"
        value_template: "{{ states('sensor.brunt_win10_system_idle_time')|float < 180 }}"
  office:
    icon: 'mdi:desktop-classic'
    automatic_lights:
      entities: 
       - light.office_lights
    include_entities:
      - binary_sensor.office_motion
      - binary_sensor.my_pc_is_active
      - light.office_lights

I also post back to IOT Link when Office motion is detected to wake my screen automatically for me rather than me violently pounding the keyboard &/or shaking the mouse. My screen is set to turn off after 5 minutes.

alias: Office - Motion
description: ''
trigger:
  - platform: state
    entity_id: binary_sensor.office_motion
    to: 'on'
    from: 'off'
condition: []
action:
  - service: mqtt.publish
    data:
      topic: iotlink/brunt/brunt-win10/commands/displays/on
      payload: ''
mode: single
1 Like