Home Assistant - Stop streaming on Google Home speakers when not home

Home Assistant - Stop streaming on Google Home speakers when not home

Hi everyone,

Today I would like to introduce the following automation, which is very useful especially when you leave your home and are in a hurry.

Use case

You are getting ready to go out and you are streaming music on the google home you have at home.

It's late. You go out but you forget to stop the music.

Software configuration

  1. Home Assistant. I'm currently running version?2022.8.0
  2. Mobile App integration?configured in Home Assistant. This integration allows Home Assistant mobile apps (Android / IOS) to integrate with your Home Assistant environment.
  3. Within the configuration.yaml file set the coordinates (latitude/longitude) of your home location as well as the elevation in meters.
  4. Google Cast integration?configured in Home Assistant. This integration allows you to control your google devices for streaming (chromcast) as well as audio (nest audio) via Home Assistant.
  5. A familiy group like this one below has to be defined within the groups.yaml file in order to manage all the people at home as one entity:

family:
? entities:
? ? - person.A
? ? - person.B
	- person.C        

The state of the entity group.family will be:

  • home when at least one of the defined person is at home.
  • not_home when all the defined people are outside home.

Home Assistant code (yaml)

This is the piece of code -?Automation?- you have to write down:

alias: Position - Tunrn off google home
description: Turn off google home if familiy group is not_home
trigger:
? - platform: state
? ? entity_id: group.family
? ? from: home
? ? to: not_home
? ? for: "00:00:15"
condition: []
action:
? - service: media_player.turn_off
? ? data: {}
? ? target:
? ? ? device_id:
? ? ? ? - device_A
? ? ? ? - device_B
? ? ? ? - ....
? ? ? ? - device_N
mode: single
        

Some specifics about the code above

  1. The state home / not_home of the entity group.familiy is based on the position provided by each device_tracker.[nameofthesmartphone] entity.
  2. To avoid unuseful changes state, the trigger needs to be true for 15 seconds before executing the actions.

I do hope you have enjoyed this article. I'm available for any feedback so, feel free to contact me or share your thoughts in the comments section below!

Thank you for reading.

--------------------------------------------------------------------------------------------------------

Other recent articles about Home Assistant:

Home Assistant - Create a button to do something

Home Assistant - Know the distance between two people

Home Assistant - Get notified when ISS is above your home

Home Assistant - Getting the position?of ISS

Home Assistant - Getting the distance between people and zones

Home Assistant - Automation: Stop chromcast streaming if TV has turned OFF

Home Assistant - Sensor: Getting the operational state of a household appliance

Home Assistant - Automation: Power up your TV / DVD based on Chromcast

要查看或添加评论,请登录

Emiliano Guerzoni的更多文章

社区洞察

其他会员也浏览了