Why doesn't the condition with "and" work?

Hi,

I have this automation, but it doesn’t work. I don’t know why. Both conditions are true at my tests. This means, it was 21:30 o’clock and the switch was “on”.

What’s strange: If I programm these two conditions without “and” it seems to work.

So my question is, what is the difference between two conditions which stands one after another and two conditions combined with “and”?

The second question is, what can I do to make my automation runable?

- id: '1586202398633'
  alias: Nachtlicht EG Flur
  description: ''
  trigger:
  - device_id: 0c6fc392c2944669b6154b98a341f33c
    domain: light
    entity_id: light.eg_flur_2
    platform: device
    type: turned_on
  condition:
  - condition: and
    conditions:
    - after: '20:00:00'
      before: 06:00:00
      condition: time
    - condition: state
      entity_id: input_boolean.nachtlicht_eg_flur
      state: 'on'
  action:
  - device_id: 0c6fc392c2944669b6154b98a341f33c
    domain: light
    entity_id: light.eg_flur_2
    type: turn_off
  - brightness_pct: 10
    device_id: dc0b66f453714c4f9335ba568c1624f9
    domain: light
    entity_id: light.eg_flur_1
    type: turn_on

Thanks,

Jaques-Ludwig

take a look how it should be.

I know that, but I can’t find my failure.

I’m sorry but if you have an example in front of you and cannot spot the error, you probably should not write code manually and stick to the automation editor.

Just remove “-” from “- condition: and” but make sure its indentation remains the same as conditions.

Answering your question

could you post the whole condition bit that “seems to work”?

The answer is already in the docs - if you use proper syntax, there is no difference.
However, if you don, the result can be anything.

I didn’t write that manually. I made it with the UI!

So there seems to be a bug in the software.

Thanks for your help. I will try it.

Ok, I saw I had made another “and” condition with the automation editor and there it worked. There is also a “-” in the line with “condition: and” and it works!

Here is the code from these other automation:

- id: '1581087409087'
  alias: Keller Flur Licht An Nacht
  description: ''
  trigger:
  - entity_id: binary_sensor.bewegungsmelder_keller_flur
    platform: state
    to: 'on'
  condition:
  - condition: and
    conditions:
    - after: '20:00:00'
      before: 06:00:00
      condition: time
    - condition: state
      entity_id: input_boolean.dummy_switch_keller_flur
      state: 'on'
  action:
  - brightness_pct: 30
    device_id: 81cdf359082e4a3fa678df8cf3cc9fcf
    domain: light
    entity_id: light.licht_keller_flur
    type: turn_on

And that is the code from the first automation that seems to work without “and”:

- id: '1586202398633'
  alias: Nachtlicht EG Flur
  description: ''
  trigger:
  - device_id: 0c6fc392c2944669b6154b98a341f33c
    domain: light
    entity_id: light.eg_flur_2
    platform: device
    type: turned_on
  condition:
  - after: '20:00:00'
    before: 06:00:00
    condition: time
  - condition: state
    entity_id: input_boolean.nachtlicht_eg_flur
    state: 'on'
  action:
  - device_id: 0c6fc392c2944669b6154b98a341f33c
    domain: light
    entity_id: light.eg_flur_2
    type: turn_off
  - brightness_pct: 10
    device_id: dc0b66f453714c4f9335ba568c1624f9
    domain: light
    entity_id: light.eg_flur_1
    type: turn_on

Thanks

Jaques-Ludwig

well, to me the main source of HA knologe is the official documentation.
and yes, there are bugs and limitations in UI editors, that’s probably why I don’t use them :wink:

So are you saying that automation “Nachtlicht EG Flur” doesn’t work and “Keller Flur Licht An Nacht” does? By “doesn’t work” you mean you can see no action performed?
Could you create the same automation as “Nachtlicht EG Flur” but with action from “Keller Flur Licht An Nacht”? For testing purposes you can set a different after time.

yeah, that’s exactly what the docs say - if you need to “and” several conditions, just put them next to each other

Yes, thats right.

If I understand you correctly, for me I can work without “and” condition. I would only need it, if I would use “and” and “or” conditions at the same time.

Jaques-Ludwig

Yes of course. I will try that.

that’s correct.
There are several reasons why you can see no actions performed. One is wrong condition. Another is issues in action.
To debug it, make your automation as simple as possible and get it work. Then gradually add conditions and keep on checking.

Ok. Thank you.

I think I have found the problem. The lights I control are both installed on one Homematic IP switch and normally I turn them off with this switch.
Only if I want to have a night light then I turn off one with zigbee and the other stay on with low brightness.

@Ahmad: I tested what you asked for. If I switched on the lights with the homeatic IP switch manually, it doesn’t work. If I swithched on the EG Flur 2 light manually with zigbee command (before the Homematic switch was switched to on and the lights became “off” command over zigbee protocol)
it worked.

Therefore I use the Homematic IP switch as trigger and not the zigbee light. Now it works.

Thanks,

Jaques-Ludwig

Why have the ‘and’ in there? Conditions are ‘and’ by default so there is no need to put it in there in your simple automation. You would only need to use the ‘and’ condition when creating more complex automation conditions with combinations of ‘and’ and ‘or’.