Time condition in automation not working

Hey guys,
I’m new to home assistant (I used openHAB for more than two years, but the lovelace ui was the reason to switch to home assistant).

I used the frontend automation creator for this automation (copied from the automations.yaml):

- id: '1587897377181'
  alias: 'Badezimmer: Licht einschalten'
  description: ''
  trigger:
  - entity_id: binary_sensor.presence_42
    from: 'off'
    platform: state
    to: 'on'
  condition:
  - condition: state
    entity_id: light.badezimmer_deckenlicht
    state: 'off'
  - after: '13:00:00'
    before: '16:00:00'
    condition: time
  action:
  - data:
      brightness_pct: 5
      entity_id: light.badezimmer_deckenlicht
      kelvin: 2200
    service: light.turn_on

The time is only for testing, but the automation is not working. Light is off and the motion sensor is triggered between the defined time.

Let’s get the simple things out of the way first, ensure the automation is turned on. Go to Developer Tools > States, find the automation in the list and confirm its current state is on.

I assume the automation’s name (in the list) will be something like this:

automation.badezimmer__licht_einschalten

I also have a vague recollection that ‘some lights’ may have an issue with kelvin, prefering the use of color_temp: mireds value
I’m not 100% sure (actually only 60% ish) because I don’t use any colour temperature controls

Thank you for your answers @123 and @Mutt :slight_smile:

The automation is turned on. The error only happened when I add the time condition. Before, it worked as expected.

But I got the automation working now. I changed the before time directly in the automations.yaml from 16:00:00 to 17:00:00 and now it is working :thinking:

The next step is to change it to:

   - after: '22:00:00'
     before: '07:00:00'
     condition: time

I hope it will work… :wink:

Changing the time doesn’t magically make the automation work (unless the test was being performed outside the specified time range).

After changing the automation, directly in automations.yaml, did you execute Configuration > Server Controls > Reload Automations (or restart Home Assistant)?

1 Like

Yes, I restarted the home assistant server (a lot of times, because it did not work).

I don’t have “Reload Automations” in the configuration section “Server Controls”. There is only “Server management” with the two buttons restart and stop:

/ edit: I found the user setting “Advanced Mode” and now I have the option to reload the automations

1 Like

Yeah, I agree with Taras, apart from the times (which you said you adjusted to perform the tests (you did reload the automation each time didn’t you ? ) the automations are identical.

By the way you don’t need the condition, if it detect ‘presence’ turn a light already on at a given value to come on at the same value will not make any difference. Though it might be useful incase you apply other affects between. Basically what I’m saying is if you are having problems with something, try to reduce it to the basics just to get it to work. Then when you add complications you know what you did and therefore where the problem must lie.

Maybe you had a yaml spacing error :man_shrugging:

Good Luck anyway :+1:

1 Like

Hey guys,
I tried to get the bathroom light working with the motion sensor.

I tried to use a condition after 22:00:00 and before 07:00:00. But it was not working. Then I used this:

- id: '1587897377181'
  alias: 'Badezimmer: Licht einschalten'
  description: ''
  trigger:
  - entity_id: binary_sensor.presence_42
    from: 'off'
    platform: state
    to: 'on'
  condition:
  - condition: state
    entity_id: light.badezimmer_deckenlicht
    state: 'off'
  - condition: or
    conditions:
    - after: '15:00:00'
      before: '23:59:59'
      condition: time
    - after: '00:00:00'
      before: '08:00:00'
      condition: time
  action:
  - entity_id: input_boolean.badezimmer_bwm_hat_licht_eingeschaltet
    service: input_boolean.turn_on
  - data:
      brightness_pct: 5
      entity_id: light.badezimmer_deckenlicht
      kelvin: 2200
    service: light.turn_on

But it was not working :frowning:

I found the problem.

First I changed the condition to "after: ‘14:00:00’ ".
image
In the developer tools I can see:

last_triggered: '2020-05-01T14:35:50.659668+00:00'
id: '1587897377181'
friendly_name: 'Badezimmer: Licht einschalten'

The problem is the time setting.

Any idea, how to fix this? :face_with_raised_eyebrow:

// Edit:

I solved it using this two lines in my configuration.yaml:

homeassistant:
  time_zone: Europe/Berlin

I have a set up an automation to detect when the washing machine is finished, but a scheduled reboot of my router once a week at 2am is causing a false notification to be sent. I need the automation to ignore a few minutes let’s say 01:55-02:05. I tried a time condition before 01:55 and after 02:05 but the notification did not work when we did some washing this morning? Do I just need to reverse the numbers or am I doing this all wrong?