Automation to turn off lights does not do the job

I have created an automation to turn on the lights at sunset. That part does work. And another to turn of the lights later in the evening. The light do never turn off, or much to late.

I thought I could create a time trigger in a pattern, every 5 minutes from 23:00-2:00 o’clock. And a condition like: No motion detected in a certain time period. And then action … I created a notify to check when and if the automation is triggered.

Half an hour after we went upstairs, the lights where still on, so I put them off. This morning I noticed a message that the script was triggered at: 3:55.

How is this working? Could someone advise me in this and with this script?

alias: Woonkamer verlichting Uit
description: ''
trigger:
  - platform: time_pattern
    hours: '23'
    minutes: /5
  - platform: time_pattern
    hours: '0'
    minutes: /5
  - platform: time_pattern
    hours: '01'
    minutes: /5
condition:
  - condition: and
    conditions:
      - type: is_no_motion
        condition: device
        device_id: 4fb6ad16f95aa4c48aff4db2f8a6d381
        entity_id: binary_sensor.motion_sensor_voorhuis_motion_sensor_status
        domain: binary_sensor
        for:
          hours: 0
          minutes: 10
          seconds: 0
          milliseconds: 0
      - type: is_no_motion
        condition: device
        device_id: fd77e27895471e53828f69afec12731f
        entity_id: binary_sensor.motion_sensor_achterhuis_motion_sensor_status
        domain: binary_sensor
        for:
          hours: 0
          minutes: 10
          seconds: 0
          milliseconds: 0
      - type: is_no_motion
        condition: device
        device_id: 3773fa4a3123bd88d921002c9149f735
        entity_id: binary_sensor.motion_sensor_keuken_motion_sensor_status
        domain: binary_sensor
        for:
          hours: 0
          minutes: 10
          seconds: 0
          milliseconds: 0
action:
  - service: notify.domoticzbot
    data:
      message: De lichten uit Woonkamer geactiveerd!
      title: HomeAssistant woonkamerverlichting
  - delay:
      hours: 0
      minutes: 1
      seconds: 0
      milliseconds: 0
  - type: turn_off
    device_id: 69f411b2fb4623a436347e24be63d3c1
    entity_id: switch.lamp_voorhuis_pp_switch
    domain: switch
  - delay:
      hours: 0
      minutes: 1
      seconds: 0
      milliseconds: 0
  - type: turn_off
    device_id: d59ed76543d2f3c5a1135b654241554d
    entity_id: light.philips_hue_staande_lamp
    domain: light
  - delay:
      hours: 0
      minutes: 2
      seconds: 0
      milliseconds: 0
  - type: turn_off
    device_id: e4caaa67b10f435f7cca09d7d2ff3dae
    entity_id: light.philips_hue_bol
    domain: light
  - delay:
      hours: 0
      minutes: 3
      seconds: 0
      milliseconds: 0
  - type: turn_off
    device_id: 7dc96f21eab74dcdcfd8ea6b7080766d
    entity_id: light.philips_hue_led_strip_keuken
    domain: light
  - delay:
      hours: 0
      minutes: 5
      seconds: 0
      milliseconds: 0
  - type: turn_off
    device_id: 7f282181b987c2f43747de9b5ff05e1b
    entity_id: light.lamp_mug_dimmer_dimmer
    domain: light
  - delay:
      hours: 0
      minutes: 0
      seconds: 0
      milliseconds: 0
  - type: turn_off
    device_id: 7a014d0596e1e39bce465c3a0cd2ad9f
    entity_id: switch.lamp_openslaande_deuren_switch
    domain: switch
  - type: turn_off
    device_id: 24e0844b40a7a276f1c135072d7e0e70
    entity_id: switch.lamp_eettafel_switch
    domain: switch
  - type: turn_off
    device_id: 12a580facc12ebe231a3e5465ae4f3d1
    entity_id: switch.ijsblok_lampje
    domain: switch
  - type: turn_off
    device_id: ba5a2e0b9584e547d2a98e07a8b7a397
    entity_id: switch.lamp_voordeur_switch_1
    domain: switch
mode: single
max: 10

I created this code in GUI. Home-assistant in docker. core-2021.9.7
These are all Zwave devices controlled by ZwaveJS2MQTT in seperated docker. Which works well.
Happy to learn from you!

What does the trace say for the recent run? I have a fairly simple automation that fails to resume after a delay (that I’ve documented here) and wonder if it might be the same issue.

Not sure I can be of much help but I did notice that your last time trigger is ‘01’ and as such should be ‘1’ the zero will cause an error.

Also your last delay is all zeros so serves no purpose as such.

Also may be easier to group the 3 motion sensor and simply use if group off for x minutes.

Also why the delays between most of the light being turned off, what’s the reason?

Thank you Rossk,
The 01 is automatically placed when I enter a 1. So I assume this should be 01. It;s hard to get rid of the zero in Gui.
You’re right about the 00:00 delay. I’ve changed that.

I do not want the light go off in one. Someone with bad intentions could assume that nobody is at home than. I want it to look ‘natural’.

Andy, I will have a look at your post.

Sorry, ignore me I read it as minutes (that should not have zeros)

Having looked at this again I personally would use the no motion for 10 mins as the trigger and the time range as the condition.

You could also create a sensor group containing the motions sensors and trigger off the group being off for 10 mins.

Just to make sure that I have no time issue causing some problems.
Is it normal that when I select the date and time in the log book, that it ‘translated’ 2 hours back in time?
I run the docker with:

-v /etc/localtime:/etc/localtime:ro \
  -e TZ=Europe/Amsterdam \

And have Europe/Amsterdam configured in Gui.

Yes I’ve learned that just right now and implemented this. I created different groups. Good functionality!

Considering the time issue, I see in the Automation list that all the automations are last executed 2 hours earlier that they are. I read 9:00 but it was in reality 11:00 o’clock. This looks like an issue. Isn’t it?

Edit: I just saw this post. And tried Chrome browser instead of Firefox. In Chrome the time is correct displayed! That is really strange!

I changed that too! Now have wait till tonight.

1 Like