Hi, I’m very new to HA and its been going well so far but I’ve hit a snag. I’m trying to automate, if me and my wife leave the house, to turn off all lights and media players. I have grouped the people, lights and media players. and this is the code I have come up with but un surprisingly, something is wrong and my very limited coding knowledge cant help.
alias: Turn off lights and music when nobody is home
mode: single
trigger:
- platform: zone
entity_id: pdevice_tracker.WIFE_s_phone
zone: zone.home
event: not_home
condition:
- condition: zone
entity_id: device_tracker.MY_phone
zone: zone.home
event: not_home
action:
- data:
entity_id: group.all_lights
service: light.turn_off
entity_id: group.all_music
service: media_player.turn_off
alias: Turn off lights and music when nobody is home
mode: single
trigger:
- platform: state
entity_id: device_tracker.WIFE_s_phone
to: 'not_home'
- platform: state
entity_id: device_tracker.MY_phone
to: 'not_home'
condition:
- condition: state
entity_id: device_tracker.WIFE_s_phone
state: 'not_home'
- condition: state
entity_id: device_tracker.MY_phone
state: 'not_home'
action:
- service: homeassistant.turn_off
entity_id: group.all_music
- service: homeassistant.turn_off
entity_id: group.all_lights
This will trigger if either of you leave home, then check to see that both of you are away. If so, do the actions.
When turning off groups you have to use the homeassistant.turn_off service.
There is a special light group that you can use the light.turn_off service with as it actually creates a new light (that controlls all the group members), not a group.
This has other advantages in that it looks like a light in the Lovelace frontend.
i use the solution from you for this example, for my “sleep-mode”, but it dont work:
if i switch the input_boolean.sleep_mode_toggle from “off” to “on”, turn the entities off.
automations/sleep_mode.yaml
- id: sleep_mode_turn_off
alias: "Sleep Mode - Turn off"
mode: single
trigger:
- platform: state
entity_id: input_boolean.sleep_mode_toggle
to: "on"
condition:
- condition: state
entity_id: input_boolean.sleep_mode_toggle
state: "on"
action:
- service: homeassistant.turn_off
entity_id: group.all_turn_off_entities
packages/turn_off/group_turn_off.yaml
group:
# All Entities to switch turn off
media_player_turn_off_entities:
name: All Turn Off Entities
entities:
- media_player.ax_hd60_office
- media_player.samsung_au8079_55_tv
mh, what is the right way?
i found the problem… “all_turn_off_entities” => “media_player_turn_off_entities”
Good stuff here. I didn’t want to start my own thread but I’m in a similar boat. New to HA and trying to start doing some automations.
I’m approaching this a little more granularly as I work from home so I need some things turned off while others can be left on.
So, for instance my kids. Each has their own bedroom, each has a smart light and a Google Nest mini device. All of them are fond of leaving for school etc, and leaving their lights on with music playing on their speakers.
I’m trying do automate that when they leave our home zone (using device tracking with the HA companion app) that it checks to see if their light is on and/or if their music is playing and if either are, to turn them off.
Here’s what I have and this sort of half worked. It turned the light off but not the media.