Automation Help with Time Conditions (Turn off lights for ##mintues between certain hours)

No I mean the group, not the automation… what state is reported for the group when you toggle it on and off… I’m just checking that you are triggering for the right state as there doesn’t seem any other reason why it’s not working.

oh i see, yeah when its off, its off, when its on, its on.

removing conditions in the automation makes the automation work tho.


1 Like

Use the automation I posted above. That’s the one where the condition is relocated to the action.

For completeness, add a second automation that triggers at 02:30 and turns off the group if it is already on. It’s needed because the first automation won’t turn off the group if it was turned on close to the end of the duration (i.e. later than 01:45).

Hi taras,

thanks for that I have tried that again this morning:

- id: 'master_bedroom_lights_off'
  alias: Master Bedroom Lights Off
  trigger:
    entity_id: group.all_master_bedroom
    platform: state
    from: 'off'
    to: 'on'
    for: '00:00:01'
  action:
    - condition:
        condition: time
        after: '09:00:00'
        before: '09:15:00'
    - service: homeassistant.turn_off
      data:
        entity_id: group.all_master_bedroom

check config button returns:
image

the automation disappears in states tab

and dev-info returns this:

Conditions are valid within actions, just not the way I wrote it! I’ll use the excuse that it was late last night when I created that …

Try this:

  action:
    - condition: time
      after: '09:00:00'
      before: '09:15:00'
``

ok thanks, lemme try this

Update: yeah, it should work i guess, just saw the documentation, but I’m still getting the same error and, the automation does not show up in states tab.

However, I just discovered in the check config button, its calling a line in my configuration.yaml (line 85)
image
I have no clue why my groups.yaml is being dragged to this, its been working for many months now without problems.

I just tested this automation, using 0.89, and can confirm it passes Config Check and turns off light.mantle after 5 minutes.

- id: 'mantle_light_off'
  alias: Mantle Light Off
  trigger:
    entity_id: light.mantle
    platform: state
    from: 'off'
    to: 'on'
    for: '00:05:00'
  action:
    - condition: time
      after: '13:00:00'
      before: '13:15:00'
    - service: light.turn_off
      data:
        entity_id: light.mantle

I don’t know why you’re receiving an error for line 85. I have the same line in my configuration file (and it isn’t flagged as an error). Sometimes it reports the wrong line number and the actual error is somewhere before line 85.

can you try a group that has a light.device_name + switch.device_name

OK, I created a group containing a light and switch, modified the automation, and everything passes Config Check and turns the group off after the duration expires.

In automations.yaml:

- id: 'dummy_group_off'
  alias: Dummy Group Off
  trigger:
    entity_id: group.dummy
    platform: state
    from: 'off'
    to: 'on'
    for: '00:02:00'
  action:
    - condition: time
      after: '13:00:00'
      before: '13:30:00'
    - service: homeassistant.turn_off
      data:
        entity_id: group.dummy

In groups.yaml:

  dummy:
    name: Dummy
    entities:
      - switch.fountain
      - light.mantle

I can’t explain why this doesn’t work on your system. :frowning:

ah thanks anyway guys, I have no idea why the conditions setting is not playing nice with my setting

did you try:

    - service: homeassistant.turn_off
      entity_id: group.dummy

ie, take out the data: field

no use for that, since there is no extra data to pass along.

trying this one now:
not getting log errors now with the groups yaml

- id: 'master_bedroom_off'
  alias: master bedroom off
  trigger:
    entity_id: group.all_master_bedroom
    platform: state
    from: 'off'
    to: 'on'
    for: '00:00:01'
  action:
    - condition: time
      after: '14:13:00'
      before: '15:00:00'
    - service: homeassistant.turn_off
      entity_id: group.all_master_bedroom

just testing it for 1 second, I don’t see it turning off. :confused:

but if I just remove this portion below and reload automations again, the group turns off after 1 second

- condition: time
  after: '14:13:00'
  before: '15:00:00'

Thre’s something wrong with your instance of Home Assistant. It should not randomly reject/accept the validity of including a condition within an action.

Out of curiosity, what is your Home Assistant’s version number?

BTW, I like the appearance of your Lovelace theme. You posted one screenshot in a previous post and it was very pleasing to the eye. Nice job! I encourage you to start a new topic and share your theme.

ah thank you, I can do that, almost done with the design part (its all picture-elements). I’m running HA 0.88.1 Inside a Docker Container in Synology DS218+

another question, maybe I missed it in the full thread:
why don’t you use this trigger:

      to: 'on'
      for:
        seconds: 5

That’s what I have in most of my timed triggers, and works just fine? (of course adapt to your needs)

thanks for that, same deal, this didn’t work:

- id: 'master_bedroom_off'
  alias: master bedroom off
  trigger:
    entity_id: group.all_master_bedroom
    platform: state
    to: 'on'
    for:
      seconds: 2
  action:
    - condition: time
      after: '14:42:00'
      before: '15:00:00'
    - service: homeassistant.turn_off
      entity_id: group.all_master_bedroom

but removing this below made the automation work, the lights turned off after 2 sec

        - condition: time
          after: '14:42:00'
          before: '15:00:00'

are you editing on a mobile? Sometimes, mobiles do weird things to quote symbols…

ah, no I’m not, I’m using atom on my desktop

could it be an issue with my clock? I’m in Los Angeles where the current time is 3:45pm and that time displays correctly on my dashboard and dev-info log.


image

but when I check the home-assistant.log file I see that it is adding +8 hours ahead

That’s odd. I’m not seeing that behavior on my system (neither the production system running 0.80 as venv installation or the test system running 0.89 in docker). The time is the same in all logs.

Some clock setting (somewhere) needs adjustment …