Possible Bug with time_pattern

Hi All,

I’m trying to use an input boolean to control a reminder which is to occur every night. It’s not working unless I comment out the condition test for the input boolean.

I’ve double checked and the binary sensor is in the correct state, so I’m confused as to why it’s not working. The way I checked the boolean was via the states panel. I also did the following from the template editor and it was showing as true:

{{ states.input_boolean.repeat_reminder.state == 'on' }}

I’ve been struggling with this for hours, so any help would be awesome.

Here’s the configuration:

input_boolean:
  repeat_reminder:
    name: Repeat Electric Blanket Reminder
    initial: off

automation:
  - alias: 'Electric Blanket Enable Input Boolean'
    trigger:
      - platform: time
        at: '20:58:00'
    action:
      - service: input_boolean.turn_on
        data:
          entity_id: input_boolean.repeat_reminder

  - alias: 'Electric Blanket Reminder'
    trigger:
      - platform: time_pattern
        hours: '21'
        minutes: '/5'
    condition:
      - condition: state
        entity_id: input_boolean.repeat_reminder
        state: 'on'
    action:
      - service: tts.google_translate_say
        entity_id: group.google_home_devices_all
        data:
          message: "It's cold outside. Time to turn on the electric blankets and close the bedroom curtains."

The input boolean is turned off via a call to the following script from google home:

script:
      turn_off_reminder:
        alias: "Turn Off Electric Blanket Reminder"
        sequence:
          - service: input_boolean.turn_off
            data:
              entity_id: input_boolean.repeat_reminder
          - service: tts.google_translate_say
            entity_id: group.google_home_devices_all
            data:
              message: "OK. Blankets are on. I'll stop reminding you now"

I looked at this, and can’t see anything particularly wrong with your code. Have you tried restarting HASS?

Can’t see anything wrong with those, I have slight coding style variances in my automations.yaml that shouldn’t make a difference but just in case:

  • the dash in front of condition can go, as there’s only one condition.
  • I use double quotes around “on” and any state test - rather than ‘single’
  • Though unnecessary these days, I still use initial_state: 'on' right under alias in all my automations.

Thanks for the replies.

I’ve already tried all those suggestions except the double quotes around “on”. I’ll build a set of test cases today to see if I can get any further idea as to what’s happening.

Any other ideas would be much appreciated.

Try the following, I added initial_state: ‘on’ to your automations as sometimes HA turns the automation off during startup. Also it doesn’t matter if you use single or double quotes as long as they are paired together.

input_boolean:
  repeat_reminder:
    name: Repeat Electric Blanket Reminder
    initial: off

automation:
  - alias: 'Electric Blanket Enable Input Boolean'
    initial_state: 'on'
    trigger:
      platform: time
      at: '20:58:00'
    action:
      service: input_boolean.turn_on
      entity_id: input_boolean.repeat_reminder

  - alias: 'Electric Blanket Reminder'
    initial_state: 'on'
    trigger:
      platform: time_pattern
      hours: '21'
      minutes: '/5'
    condition:
      condition: state
      entity_id: input_boolean.repeat_reminder
      state: 'on'
    action:
      service: tts.google_translate_say
      entity_id: group.google_home_devices_all
      data:
        message: "It's cold outside. Time to turn on the electric blankets and close the bedroom curtains."

Thanks all for the comments.

After quite a bit of testing, I’m fairly confident that I’ve hit a but in the time_pattern platform.

I’ve opened a new issue. You can follow it here if interested: https://github.com/home-assistant/home-assistant/issues/24691

So 21 hours is 9PM and then you have every 5 minutes? That sounds like a logic flaw rather than a bug?

but = bug…:slight_smile:

I’m taking the doc here: https://www.home-assistant.io/docs/automation/trigger/ to mean that I can trigger every 5 minutes during the hour 21:00.

I found this post https://github.com/home-assistant/home-assistant/issues/21547

Ottowinter who wrote the cron code indicates that it should work the way I’m trying to use it. Maybe I’m misreading his comments but I don’t think so.

Fair enough… should work - just looked like an odd condition to me…

I spent a lot of time on this. Even pulled the relevant entities out of the database as I wasn’t trusting the state panel. In the issue I opened, I listed some test cases that trigger with the identical condition to the time_pattern condition.

There was another issue opened along similar lines some time ago, but the op did not provide some information that was requested and it was closed, so I think this issue might have been around for a while

1 Like

Bug has been identified now and will be rectified in 0.95.0

1 Like

I completely forgot about that particular Issue (21547)! I had tested the scenario (repeat every 5 minutes within a specified hour) but could not replicate the reported bug. :man_shrugging: Definitely an elusive one!

Corrective PR is here:

It was pretty much an all day effort today to identify it. Ended up building heaps of different test cases to narrow it down.

This was tricky to reproduce because the bug only showed when restarting Home Assistant and hours did not match … and of course, most people testing will just put in the current hour because they are impatient.

When Pete made a test at 17:31 and it triggered at 18:35, I suddenly knew where to look. Good job!

Disparaging the people who tried to help?

Quite sure I, and others, volunteered their time to investigate a problem they weren’t even experiencing (and I even tested at two different hours).

Let’s chalk this one up to the bug being more elusive than originally suspected and not due to anyone’s alleged impatience.

Thank you, and everyone involved, for your time, insight, and effort to resolve the issue.

Hardly. That description includes myself since I did it twice, once for each bug report. Maybe I should have said efficient rather than impatient.

Anyway, I was just trying to explain why it took so long before someone could reproduce it.

2 Likes

Perhaps you said it because you were … impatient.

/s