Light group status in automation

Hello,

It might be a trivial mistake, but I cannot figure this out.
I want this automation NOT to trigger if the group livingroomlights is already on (the lights might be already on with a different setting than the scene this automation turns on)

I tried both with a normal state condition and the template condition below (which renders fine in the template area, showing True when off).
The condition tests true in every case, regardless of the state of the group, and the lights go on (the other group condition works fine).

Does anybody see an obvious mistake here?

  - alias: PreSundown
    trigger:
      platform: sun
      event: sunset
      offset: '-00:25:00'
    condition:
     condition: and
     conditions:
      - condition: state
        entity_id: group.all_devices
        state: home
      - condition: template
        value_template: {{ is_state("group.livingroomlights", "off") }}
    action:
      - service: scene.turn_on
        entity_id: scene.full_bright

First of all, if you use scenes you will not have this problem since scenes only toggle the enitities which are in the wrong state at the moment.

You can use a condition but use as follow:

  - alias: PreSundown
    trigger:
      platform: sun
      event: sunset
      offset: '-00:25:00'
    condition:
     condition: and
     conditions:
      - condition: state
        entity_id: group.all_devices
        state: home
      - condition: state
        entity_id: group.livingroomlights
        state: off
    action:
      - service: scene.turn_on
        entity_id: scene.full_bright

I do use a scene in the action. I simply do not want to apply the full_bright scene if any of the lights in that group are already on, potentially in the “wrong” state.

I tried the solution you proposed, and it did not work. That’s why I resorted to the template condition, with no joy either :frowning:

Remember that if you use the condition on the entire group (group.livingroomlights), It will only have state “off” if every entity (including switches) in that group is switched off. Perhaps it’s better to use 1 seperate entity_id which is often on (I use this myself as well).

Yep, that’s going to be my next test as a fallback. But I am aware of the way group works…I specifically want the automation to stop if any member of the group is not off. But even if I verify that the group is “on”, the action executes.

Are you absolutely sure? That should simply not be possible with the following condition:

      - condition: state
        entity_id: group.livingroomlights
        state: off

Hence my cry for help :slight_smile: it simply does not make any sense and the problem must lie in something else that I cannot think of
.
Now, trying to revert back to the state condition, my config is invalid, unless i use ‘off’ in quotes.
And in that case, it executes the action even if the group is ‘on’.

I’m very confused.

Try turning off all other automations, see if that makes any difference. Perhaps you have other automations interfering.

The worst thing is that this is an invalid config (see below), while ‘off’ is accepted (but does not work)

2017-11-11 17:59:52 ERROR (MainThread) [homeassistant.config] Invalid config for [automation]: extra keys not allowed @ data[‘condition’][0][‘state’]. Got None
not a valid value for dictionary value @ data[‘condition’][0][‘condition’]. Got None. (See /home/homeassistant/.homeassistant/configuration.yaml, line 131). Please check the docs at https://home-assistant.io/components/automation/

You’re rght about the quotes, I made a mistake. my apologies…
Which Hass version are you usinng?

This has been working fine for me (currently on 0.57.1):

- alias: 'Lights on when entering after sunset'
  trigger:
    platform: state
    entity_id: binary_sensor.door_window_sensor_158d000120dcd4
    to: 'on'
  condition:
      - condition: state
        entity_id: sun.sun
        state: 'below_horizon'
      - condition: state
        entity_id: light.hall_way
        state: 'off'       
  action:
    service: scene.turn_on
    entity_id: scene.evening

I am on 0.55 (updates entail a lot of recompiling of some dependencies, so sometimes I lag behind), but in the release notes of 56 and 57 I saw nothing that looked like a bugfix for this.
Anyway, I will upgrade now.

There’s no reason the way you have it shouldn’t work. It’s hard to tell for sure but in your first post it looks like the indentation is off under the conditions: part, looks like a single space instead of 2. That could be causing the conditions to be ignored?

I believe that as long as the list is indented, it’s fine. I tried with two spaces though, still no joy.
Also updated to 57.2, no joy.

With the code below, and the group “on”, verified in “dev-states”, triggering the automation executes the action, despite the “and” condition should evaluate false.
I’m scratching my head here… It cannot be a bug, it would be too big for not having been caught before.

  - alias: PreSundown
    trigger:
      platform: sun
      event: sunset
      offset: '-00:25:00'
    condition:
     condition: and
     conditions:
       - condition: state
         entity_id: group.all_devices
         state: home
       - condition: state
         entity_id: group.livingroomlights
         state: 'off'
    action:
      - service: scene.turn_on
        entity_id: scene.full_bright

I tried changing the othe condition to “not_home” and it still runs the action, despite me being home.
I checked the syntax for the condition several times… I literally copy pasted it from another double state end that works…

Did you try this state with quotes as well?

         state: 'home'

yep, just tried, same thing. Besides, the device_tracker group has always worked without quotes…

(thanks for helping me out Bob, I appreciate the effort!)

1 Like

I tried quoting the entities names as well (the automation documentation examples have quotes for all now, not sure if it was like that in the past, those are the oldest automations that I have) but it still behaves exactly in the same way.

But… I just realized one thing.
I triggered another known-working automation, with a condition on my presence that - since I am home - should be NOT met, and it runs the action.

Specifically, this one, runs even if I am at home (but not when it actually triggers naturally and I am at home)

  - alias: Vero Arrives
    hide_entity: False
    trigger:
      platform: state
      entity_id: device_tracker.vero
      to: home
    condition:
      - condition: state
        entity_id: device_tracker.mike
        state: not_home
    action:
      - service: notify.jarvismike
        data:
          message: 'Vero is now home, sir.'

And in the following, the action does not run even if I trigger it manually (it’s not one of the listed day - ignore the fact that is an “or” with a single condition. It works, it’s a leftover when I had another condition)

  - alias: RoombaTueThuSat
    hide_entity: False
    trigger:
      platform: state
      entity_id: group.all_devices
      to: not_home
    action:
      - condition: or
        conditions:
          - condition: time
            # At least one of the following is required.
            after: '08:00:00'
            before: '16:00:00'
            weekday:
                - tue
                - thu
                - sat
      - service: script.turn_on
        entity_id: script.run_roomba
      - service: notify.jarvismike
        data:
          message: 'Roomba started'

Could it be that when triggering an automation manually for testing, some of the conditions are not evaluated correctly?
I will probably post an issue on github for this, just in case.

All states have to be quoted I would say after taking a look al all my automations with use of a state. Entity id’s wihout quotes.
How about you try changing the entity id in a single device instead of a whole group (for testing purposes, just to make sure the problem is not in the group).

You’re very welcome, I know how frustrating it can be when ‘simple’ things just will not work as expected.

I am more and more convinced it’s an issue with forced trigger. The automation would work ok when triggering naturally.

Ahh…yea force triggering an automation ignores conditions. Has been like that for a while now, I believe it’s intentional. I didn’t realize that’s what you were doing…

1 Like