Hello Home Assistant Community!
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
Requirements:
-
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 tobinary_sensor.[NAME]_active
. - Light Entity: Any light entity that you wish to control based on the Mac’s activity.
- Tested: Macbook Pro and Mac Mini
Implementation Steps:
- Navigate to the blueprints section in Home Assistant and import the blueprint using the provided GitHub Gist URL.
- Create a new automation using the imported blueprint.
- Select the appropriate
binary_sensor
corresponding to your Mac’s activity. - Choose the attribute you’d like to monitor (Screen Off, Locked, Screensaver, Sleeping).
- Select the light entity/entities you wish to control.
- 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!