Home Assistant

Home Assistant Night Mode

Home Assistant

Introduction

In this blog post I will explain how I setup my Home Assistant Night Mode. My custom Home Assistant Night mode is used to easily turn of all lights and prevent motion sensors from turning on the lights when activity is triggered. More information about Home Assistant can be found on their website!

Input boolean for Home Assistant Night Mode

To be able to use this Night Mode configuration we need to create an Input Boolean that we later use in our automation. To create an Input Boolean go to Settings -> Devices and Services -> Helpers. Then create an new Input Boolean like the example below.

Input Boolean

Automations for Home Assistant Night Mode

The Input Boolean is used in two different automations. The first one is the Home Assistant trigger on my iPhone and Apple Watch to toggle the Night Mode and turn off all lights in all rooms.

alias: Actie - Nachtmodus
description: ""
trigger:
  - platform: event
    event_type: ios.action_fired
    event_data:
      actionName: Nachtmodus
condition: []
action:
  - choose:
      - conditions:
          - condition: state
            entity_id: input_boolean.nachtmodus
            state: "off"
        sequence:
          - service: light.turn_off
            data: {}
            target:
              area_id:
                - hal_voordeur
                - huis
                - keuken
                - schuur
                - slaapkamer_tim
                - washok
                - woonkamer
          - service: input_boolean.turn_on
            data: {}
            target:
              entity_id: input_boolean.nachtmodus
      - conditions:
          - condition: state
            entity_id: input_boolean.nachtmodus
            state: "on"
        sequence:
          - service: input_boolean.turn_off
            data: {}
            target:
              entity_id: input_boolean.nachtmodus
mode: single

This automation is triggered on the ios.action_fired event type with actionName: Nachtmodus. It then checks if the Input Boolean we created earlier is on or off. Depending on the state it will either toggle the Input Boolean and turn off all lights or it will simply toggle the Input Boolean.

To make sure your motion sensors are not triggering the lights again we need to also modify the motion sensor automations. For ease of use I directly edited the Blueprint template I use for turning on or off lights with motion sensors. See the example below.

blueprint:
  name: Motion-activated Light
  description: Turn on a light when motion is detected.
  domain: automation
  source_url: https://github.com/home-assistant/core/blob/dev/homeassistant/components/automation/blueprints/motion_light.yaml
  input:
    motion_entity:
      name: Motion Sensor
      selector:
        entity:
          domain: binary_sensor
          device_class: motion
    light_target:
      name: Light
      selector:
        target:
          entity:
            domain: light
    no_motion_wait:
      name: Wait time
      description: Time to leave the light on after last motion is detected.
      default: 120
      selector:
        number:
          min: 0
          max: 3600
          unit_of_measurement: seconds

# If motion is detected within the delay,
# we restart the script.
mode: restart
max_exceeded: silent

trigger:
  platform: state
  entity_id: !input motion_entity
  from: "off"
  to: "on"
condition:
  condition: state
  entity_id:
    - input_boolean.nachtmodus
  state: "off"
action:
  - alias: "Turn on the light"
    service: light.turn_on
    target: !input light_target
  - alias: "Wait until there is no motion from device"
    wait_for_trigger:
      platform: state
      entity_id: !input motion_entity
      from: "on"
      to: "off"
  - alias: "Wait the number of seconds that has been set"
    delay: !input no_motion_wait
  - alias: "Turn off the light"
    service: light.turn_off
    target: !input light_target

In the condition section I added the check for the input_boolean.nachtmodus. This will prevent the lights from turning on when the night mode is set.

Conclusion

This post should help you setup your own night mode in Home Assistant. You should expand on it with different automations for example setting your thermostat or security devices for the night.

If you like this post also check out my Home Assistant post about Home Assistant washing machine notification. This will you more inspiration to build out your Home Assistant setup.

Leave a Reply

Your email address will not be published. Required fields are marked *