Time Condition on Automation Not Working

I am exciting I finally got my home assistant setup on my raspberry pi with reolink integration which is awesome!

Next, I am trying to setup a person detection alert that sends me a critical alert between 12:00am to 5:00am CST. I have confirmed in my settings that the my time zone in HA is set to Central Time -6 but its now 8:30am and I am still getting critical alerts any idea what is wrong?

alias: Front Yard Person
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.front_driveway_person
    from: "off"
    to: "on"
condition:
  - condition: time
    after: "00:00:00"    
    before: "05:00:00"
    weekday:
      - sun
      - mon
      - tue
      - wed
      - thu
      - fri
      - sat
action:
  - service: notify.mobile_app_rich_howards_iphone
    data:
      message: Person detected at the front yard!
      title: Person detected at the front yard!
      data:
        push:
          sound:
            name: default
            critical: 1
            volume: 1
mode: single

Are you testing the automation by making the Binary Sensor change state from off to on or are you testing it by executing its Run command?

Testing it via the Run command only executes the action section (trigger and condition are skipped).

I have tested it and it works perfectly, the automation is firing when someone walks by the garage but its after the 5am time and its still sending the alerts each time. It’s not respecting the time condition is the problem.

Copy-paste the following into the Template Editor. Does it report the correct current date, time, and timezone offset for your location?

{{ now() }}

No, so here’s what I got back:
The current time is:
2023-08-09 04:44:02.068505-06:00

For example I am on CST and right now its 10:50 am I ended up having to convert my time to UTC in my automations but I noticed this morning its not back working. It would be great if I could get out of UTC and on my local time, here’s my automation now:

alias: Garage Person Detected
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.garage_person
    from: "off"
    to: "on"
condition:
  - condition: time
    before: "23:52:00"
    weekday:
      - sun
      - mon
      - tue
      - wed
      - thu
      - fri
      - sat
    after: "18:52:00"
action:
  - service: notify.mobile_app_rich_howards_iphone
    data:
      message: Person detected at the garage!
      title: Person detected at the garage!
      data:
        push:
          sound:
            name: default
            critical: 1
            volume: 1
mode: single

If it failed to report the correct time then nothing time-based will ever run at the correct, local time. Your first priority is to set the correct timezone.

Go to Settings > System > General > Timezone and ensure it’s set correctly.

Thanks it was set to
Time Zone
(GMT-06:00) Central Time - Mexico City

I set it up this way as soon as I configured HA so not for sure why it wont accept the time zone?

If you are in the USA

Then restart Home Assistant and check {{ now() }} in the Template Editor to confirm the reported local time is correct.

Thanks updated to the time zone you mentioned above and restart HA no luck, reboot entire RPI and no luck :frowning:

What is the time difference between what the time should be and what Home Assistant reports?

Here’s what I get with the template:

The temperature is 25 °C.

The sun will rise at 2023-08-10T05:58:33.152049-05:00.

The current time is:
2023-08-10 03:49:21.333639-05:00

My actual time where I live in CST is:
2023-08-10 08:56

So the difference is 5 hours and 7 minutes behind

There are several ways to install Home Assistant . Which installation method did you use for your Raspberry Pi?

Compare installation methods

OS, I actually was stuck on preparing HA and couldnt get past Raspberry PI 4 Stuck on Preparing HA - #4 by KruseLuds

I actually resolved the issue by setting the time manually Fresh Installation Stuck on Preparing HA - #26 by juagicre that was the only way I could get the installation to finish. After I ran that command and set my time manually to my local time the HA finished installing after a reboot. So maybe something I did with that command screwed it up?

ha>login

#date -s "yyyy-mm-dd hh:mm:ss"

A Raspberry Pi has no internet internal real time system clock. In other words, it has no internal time reference so whatever time you may have set on the command line is lost after a reboot.

The most common way for a Raspberry Pi to set its system time is to synchronize itself with an external, internet-based time reference. Normally Home Assistant OS takes care of this task, unless it can’t reach the internet-based time reference.

I’m unfamiliar with the ‘stuck on preparing HA’ issue so I can’t comment on it or whatever workarounds were devised for it.

I assume by now it’s apparent that all time-based automations cannot work properly because the Raspberry Pi’s system clock isn’t set correctly.

It’s easy to setup as part of your installation, a service to keep the clock up to date, just like with any computer, it’s essentially configuration. The only difference with the RPI is, as there is no battery typically when it is off it is completely off and no onboard battery powered clock, which is resolved by the clock on it being set automatically at boot time.

I see from the other link you supplied that you are or have installed Home Assistant Supervised. Welcome! I am surprised there is any issue with your time setting on the RPI, as the exactly perfect correct way to set up HA Supervised is specified here - all those steps include ensuring the clock (and everything else) is perfectly configured. To do it perfectly right though, you must follow those instructions to the letter.

HA Supervised is the most flexible version of HA out there but due to it’s complexity it only has a small reported number of installations. You can click on the legend (using that link) to hide or show the different installation types:

From what I have heard (third hand), Nabu Casa supposedly tried to get rid of the Supervised method of running the Home Assistant environment, but there was a huge amount of blowback from developers so they backed down and continued to support it. As I am concerned about the HA Supervised usage and want to very actively support the growth of the number of installations, I am more than happy to help with any issues you may have. I do not have a huge amount of time to help and I am not at all an expert (a pretty new I would say ‘intermediate’ level) but I want to as strongly as possible encourage you and help you to use HA Supervised…

Lastly let me say that if you continue to have any issues at all, it is very much worth it to back up your HA configuration, then start from scratch following these instructions (same link as above), then just restore your backup - it should only take you about an hour and you will not lose anything in your configuration. The best way to back it up I have found is to use this add-on - so install that and do a full backup before you blow away your installation (or just use this for backups regardless). I have actually done that myself a few times and my whole system is runing like a top -

Add it under Add-Ons - I have mine backed up daily :slight_smile:

1 Like

Sorry, but it’s not. That would be Container, or running a Hypervisor like Proxmox and multiple VMs and CTs.

As much as you may wish to try and bump up the numbers for Supervised, the devs decision to slowly and methodically deprecate Supervised is inevitable.

1 Like

Thank you for the correction, I still have alot to learn!

So @kanga_who I just wanted to ask, the below table is why I chose supervised (I disagree with the OS control, I can do whatever I want with the bare metal Debian running on it and have unrelated daemons running on it which is not allowed with the HAOS, right?). Is that incorrect or out of date? Thanks for your help -

image

All of that seems to be true.

But…

the problem with a Supervised install method is that it can fail at any point at the whim of the HA dev team.

there have been many reports of a “system is unhealthy” causing HA to not be able to be updated. This can be caused by running apps/etc that the Supervisor deems to conflict with the HA ecosystem.

And as noted the dev team could simply remove support for a Supervised install as they tried to do a few years ago. The only reason it wasn’t discontinued then was a huge outcry from users. But ever since then the Supervised install has become a third class citizen just waiting to be shutdown.

So the expectation of the Supervised install being the best of both worlds is overblown and could result in you having a broken system at some point.

but of course this is just my opinion. But it’s based on my experience here and with running a test install of the Supervised version on my own server for a while. At some point I gave up on trying to maintain it because it wasn’t worth the extra effort with the minimal benefit that it provided over a Container install.

Thank you for your thoughts

1 Like