Toggle💡lights based on your 🖥️ Apple Mac activity

Hello Home Assistant Community! :rocket:

I wanted to share a blueprint I’ve developed which allows you to automate the control of your lights based on the activity status of your Apple Mac. With the increasing work-from-home culture and the essence of an automated home office space, I felt this would be a valuable addition to anyone using HA and wants a seamless lighting control based on their Mac’s activity.

Blueprint Description:

The blueprint monitors specific attributes (like Screen Off, Locked, Screensaver, Sleeping) from a binary_sensor entity of your Mac. When the attribute indicates inactivity, the chosen lights are turned off, and vice versa.

blueprint:
  name: Toggle lights using your Mac activity
  description: 'This automation will turn on/off lights when your Mac is active or inactive, watching for the attribute of the entity'
  author: '@jodacame'
  domain: automation
  input:
    device:
      name: Entity
      description: 'Select a entity (Please make sure that the entity is a binary_sensor of activity, check entity name is like to: binary_sensor.[NAME]_active)'
      selector:
        entity:
          domain: binary_sensor
          integration: mobile_app
    attribute_option:
      name: Attribute Option
      description: Select the attribute to monitor
      selector:
        select:
          options:
            - Screen Off
            - Locked
            - Screensaver
            - Sleeping
    light:
      name: Light(s)
      description: The light(s) to control
      selector:
        target:
          entity:
            domain: light
trigger:
  - platform: state
    entity_id: !input device

action:
  - service: system_log.write
    data:
      message: "Triggered entity is: {{ trigger.entity_id }}"
      level: info

  - choose:
      - conditions:
          - condition: template
            value_template: "{{ is_state_attr(trigger.entity_id, !input attribute_option, true) }}"
        sequence:
          - service: light.turn_off
            target: !input light
      - conditions:
          - condition: template
            value_template: "{{ is_state_attr(trigger.entity_id, !input attribute_option, false) }}"
        sequence:
          - service: light.turn_on
            target: !input light
mode: single
max_exceeded: silent

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

Requirements:

  1. binary_sensor from Mobile App integration: You should have the Home Assistant mobile app set up on your Mac, and it should expose a binary_sensor indicating activity. Most commonly, this will be named something similar to binary_sensor.[NAME]_active.
  2. Light Entity: Any light entity that you wish to control based on the Mac’s activity.
  3. Tested: Macbook Pro and Mac Mini

Implementation Steps:

  1. Navigate to the blueprints section in Home Assistant and import the blueprint using the provided GitHub Gist URL.
  2. Create a new automation using the imported blueprint.
  3. Select the appropriate binary_sensor corresponding to your Mac’s activity.
  4. Choose the attribute you’d like to monitor (Screen Off, Locked, Screensaver, Sleeping).
  5. Select the light entity/entities you wish to control.
  6. Save the automation and you’re all set!

I hope you find this blueprint useful. Feedback, improvements, and suggestions are always welcome. Let’s keep building and innovating together! :star2:

Works Great, any way to make the lights go out a few minutes after I lock the Mac?