Home Assistant - How to automatically turn off a socket when nobody's home

Home Assistant - How to automatically turn off a socket when nobody's home

Hi guys,

In this article we saw how to automatically set a switch state based on presence at home so that your defined switch will appear as follows on the Home Assistant user interface:

No alt text provided for this image

When someone is at home


No alt text provided for this image

When nobody's at home


Scenario

You need to automatically turn off a critical socket as soon as nobody is at home.

Home Assistant can automatically do this for us, let see how.

What you need in terms of hardware

  1. Aeotec Z-Stick Gen5+. It's a Z-Wave gateway to build up and manage your Z-Wave network.
  2. Aeotec nano switch.?It's a Z-Wave device that allows you to control any switch as well as socket from anywhere. For this specific use case, I've used the device with energy reading feature (ZW116). In case you need to control two different sockets at time, please refer to the Aeotec dual nano switch (ZW132 with energy reading, ZW140 without energy reading).

Software configuration

  1. Home Assistant. I'm currently running version?2022.9.2.
  2. Z-Wave JS integration?configured in Home Assistant. This integration allows you to control all the Z-Wave devices within your network via Home Assistant. As soon as the Aeotec nano/dual switch device has been added to your Z-Wave network, it exposes several entities including the switch.your_switch allowing you to turning OFF / ON the switch itself wirelessy.
  3. Mobile App integration?configured in Home Assistant. This integration allows Home Assistant mobile APP (Android / IOS) to integrate with your?Home Assistant?environment.
  4. Mobile APP?installed on each smartphone you want to track.
  5. Person integration?defined in order to know who currently is / is not at home.
  6. A group configured (e.g.?named family) composed of each person defined above in order to have a single entity. Such a group has to be defined within your groups.yaml?file as follows:

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

Home Assistant code (yaml) / steps

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

alias: Switch - Turn off your socket if nobody's home
description: Switch - Turn off your socket if nobody's home
trigger:
? - platform: state
? ? entity_id: group.family
? ? from: home
? ? to: not_home
? ? for: "00:00:30"
condition:
? - condition: state
? ? entity_id: switch.your_switch
? ? state: "on"
action:
? - type: turn_off
? ? device_id: xxxxxx
? ? entity_id: switch.your_switch
? ? domain: switch
mode: single        

Some specifics about the code above

  1. The trigger is based on the changing state of the group.familiy from home to not_home.
  2. I've just added 30 seconds of latency to avoid unwanted multiple changing states.
  3. The automation includes the condition to check the current state of the switch. In case it's already OFF, the automation will not be executed.

Thank you for reading. ?? I 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.

Your feedbacks will be very appreciated!

Meanwhile,?if you liked this article share it or?subscribe?to my newsletter?about?Home Assistant?to read all previous episodes and still up to date on latest news.

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

社区洞察

其他会员也浏览了