How to turn off movement sensor when I am sleeping

Hi Guys,

I’d like my movement sensor to not respond when I’m sleeping. It’s really annoying when the lights turn on automatically. And I also don’t sleep at the same time so I can’t use the time feature. BTW I’m new with home assistant and I am still learning.

Is there a way for my automation, I couldn’t figure it out on my own.

My code that I used ( I juist created it with the UI but for you guys I wanted to just put in the code here):

<alias: 'Lampen aan wanneer iemand ''s avonds in mijn kamer is ' *(lights turn on when someone in the evening is in my room)*
description: ''
trigger:
  - type: motion
    platform: device
    device_id: cb94b1cec5b86b0d1f8706830f5e670a
    entity_id: binary_sensor.bewegingssensor_occupancy
    domain: binary_sensor
    for:
      hours: 0
      minutes: 0
      seconds: 0
      milliseconds: 0
condition:
  - condition: state
    entity_id: sun.sun
    state: below_horizon
action:
  - type: turn_on
    device_id: d9499e90f72b48b0c9fb0ad0ba2153da
    entity_id: light.lamp_1
    domain: light
    brightness_pct: 50
  - type: turn_on
    device_id: 3ccdeda492be66246d3e04d8d035439b
    entity_id: light.lamp_2
    domain: light
    brightness_pct: 50
  - type: turn_on
    device_id: 31b7253e68a4b361608dba61b93d629f
    entity_id: light.lamp_3
    domain: light
    brightness_pct: 50
mode: single>

How do you intend to signal to HA, that you are sleeping?

Btw: For posting code (or logs), please use the code formatting option of this editor (</> icon).

I would create a template binary sensor “asleep”, and then use this sensor in your automations as a condition.
I set my sleep-sensor automatically through the sensors in the android companion app. If my phone is charging AND is in “do not disturb”-mode HA assumes I’m sleeping. Both conditions are never both true when I’m not sleeping.

But you might as well base the sensor on a boolean input and set it manually or through voice command.

At that point, creating a boolean is just extra work.

Just turn the switch off on the automation. Same thing.

- entity: automation.whatever_its_named

Search the forum for bed sensors. Include a condition to ignore the motion trigger when the in bed sensor is on.

This is how I do it.

@fiftys you are right, boolean input is just a work around, until he get’s appropriate sensors in place.
Adding the abstraction of the template sensor makes it easier to change things around without having to touch every automation again, that references the sleep-status

@m0wlheld If that makes my light stop turning on in the middle of the night then yes. And sorry about that code.

Hi Guys,

Thanks for the great suggestions. I will take a look at it in the evening and try your suggestions. I’m at work now. I will keep you guys informed.

Hi guys,

I think seanomat idea is great for now. But I’d like to add my phone battery state into a template and use that template to add it as a condition for when I charge my phone. But I don’t really know how to do it. This is the template what I’ve got for now. But on value template I need to fill in that it needs to read my battery state but I can’t figure out what to fill in exactly. Can someone help me out?

- platform: template
    sensors: iphone_van_metehan_battery_state
    friendly_name: Battery state 
    value_template:  

Value template is where I’m stuck. I use the HA app and I can find the battery state data but I don’t know how to use it in this template.

New code:

  - platform: template
    sensors:
      sensor.iphone_van_metehan_battery_state:
        friendly_name: iPhone battery state 
        value_template: >
          {{ state_attr('iphone_van_metehan_battery_state', 'battery_charging') }}

I’ve to say, I’m not really sure if this is the correct way of doing it.