Repeat Automation whenever the two trigger states are reached

Hi all,

I have built an automation for my covers with the following logic:
The status of a LUX as well as the sun azimut sensor are checked. Once the azimut sensor reports >127 and the LUX sensor gives >9000, the cover will be closed. This is for the season autumn und winter.

In an other automation I have the action to open the covers again, once the LUX sensor is below 9000.

Both automations are working perfectly fine.

Problem now is that the automation is triggered only ones: Once the LUX values goes under 9000 (and the cover is opened via the above described automation) and the sensor reaches 9001 again later, the automation is not triggered anymore. During cloudy conditions it can easily be that the threshold of LUX 9000 is passed several times and hence the automation to close should trigger every time.

Below my automation:

alias: Rollladen LUX WZ Sud Winter
description: ''
trigger:
  - platform: numeric_state
    entity_id: sensor.sonne_azimut
    above: '127'
  - platform: numeric_state
    entity_id: sensor.000d5d899bf9ed_average_illumination
    above: '9000'
condition:
  - condition: and
    conditions:
      - condition: numeric_state
        entity_id: sensor.sonne_azimut
        above: '127'
      - condition: numeric_state
        entity_id: sensor.000d5d899bf9ed_average_illumination
        above: '9000'
      - condition: state
        entity_id: input_boolean.coverwzsud
        state: 'off'
      - condition: or
        conditions:
          - condition: state
            entity_id: sensor.season
            state: autumn
          - condition: state
            entity_id: sensor.season
            state: winter
action:
  - service: script.rollladen_lux_wz_sud_winter
mode: single

What do I need to change so that it is triggered multiple times?

Thanks for your help and Regards,
Aleardo

It looks like you are mixing up “AND” and “OR”.
By default, the triggers in an automation are handeled as “OR”, and not as “AND”.
Try this:

alias: Rollladen LUX WZ Sud Winter
description: ''
trigger:
  - platform: numeric_state
    entity_id: sensor.sonne_azimut
    above: '127'
  - platform: numeric_state
    entity_id: sensor.000d5d899bf9ed_average_illumination
    above: '9000'
condition:
  - condition: and
    conditions:
      - condition: or
        conditions:
        - condition: numeric_state
          entity_id: sensor.sonne_azimut
          above: '127'
        - condition: numeric_state
          entity_id: sensor.000d5d899bf9ed_average_illumination
          above: '9000'
      - condition: state
        entity_id: input_boolean.coverwzsud
        state: 'off'
      - condition: or
        conditions:
          - condition: state
            entity_id: sensor.season
            state: autumn
          - condition: state
            entity_id: sensor.season
            state: winter
action:
  - service: script.rollladen_lux_wz_sud_winter
mode: single

Thanks Ed for your reply.
Does the “OR” in the conditions of your suggestion not valuate if either LUX > 9000 or azimuth >127? The condition must be that LUX > 9000 AND azimuth > 127 are true, in order to close the cover.

The triggers are fine as OR. The conditions must be an AND.
Sorry, my descritpion above was not clear enough.

Regards,
Aleardo

Would something like this work for you?

alias: Rollladen LUX WZ Sud Winter
description: 'Trigger every 5 minutes, azimuth>127 and illumination > 9000 and coverwzsud off, season autumn or winter'
trigger:
  - platform: time_pattern
    minutes: "/5"
condition:
  - condition: and
    conditions:
      - condition: numeric_state
        entity_id: sensor.sonne_azimut
        above: '127'
      - condition: numeric_state
        entity_id: sensor.000d5d899bf9ed_average_illumination
        above: '9000'
      - condition: state
        entity_id: input_boolean.coverwzsud
        state: 'off'
action:
- choose
  - conditions:
    - conditions: state
      entity_id: sensor.season
      state: autumn
    sequence:
    - service: script.rollladen_lux_wz_sud_winter
  - conditions:
    - conditions: state
      entity_id: sensor.season
      state: winter
    sequence:
    - service: script.rollladen_lux_wz_sud_winter
    default: []
mode: single

I think I got all the spacing right but check me

It should because the lux sensor’s value is crossing the threshold value of 9000. Are you sure it’s due to the trigger failing and not because the condition blocked it?

Add an id to the automation, save the file and execute Reload Automations. The next time the automation is triggered it will generate a trace. The trace tells you exactly what happened and how far it progressed through the automation.

alias: Rollladen LUX WZ Sud Winter
id: rolladen_lux_wz_sud_winter
description: ''

Thanks for your replies. I was checking the automation over the weekend. The 5min Trigger works perfectly fine and to move the “autumn” / “winter” condition to the action is a good idea. I am getting closer :slight_smile:

What is strange is the following: My old automation I made with no proper understanding of the “AND” function is somehow triggering the automation whenever lux >9000 and azimuth > 127, although the “AND” parameter is not properly set. Does anyone know why?

Here is the code:

alias: Rollladen LUX WZ Sud Winter
description: ''
trigger:
  - platform: numeric_state
    entity_id: sensor.sonne_azimut
    above: '104'
  - platform: numeric_state
    entity_id: sensor.000d5d899bf9ed_average_illumination
    above: '9000'
condition:
  - condition: numeric_state
    entity_id: sensor.000d5d899bf9ed_average_illumination
    above: '9000'
  - condition: and
    conditions:
      - condition: numeric_state
        entity_id: sensor.sonne_azimut
        above: '104'
  - condition: and
    conditions:
      - condition: state
        entity_id: input_boolean.coverwzsud
        state: 'off'
action:
  - service: script.rollladen_lux_wz_sud_winter
mode: single

The “AND” parameter must me useless…but still it is doing the right thing.

Regards,
Aleardo

My guess, and it is only a guess, is the AND gets thrown away because there is only one condition to each AND.

…might be.

So I am using now the 5 min time pattern, which is doing the job.

The end code I am using:

alias: Rollladen LUX WZ Sud
description: >-
  Trigger every 5 minutes, azimuth>127 and illumination > 9000 and coverwzsud
  off, season autumn or winter
trigger:
  - platform: time_pattern
    minutes: /5
condition:
  - condition: and
    conditions:
      - condition: numeric_state
        entity_id: sensor.sonne_azimut
        above: '127'
      - condition: numeric_state
        entity_id: sensor.000d5d899bf9ed_average_illumination
        above: '9000'
      - condition: state
        entity_id: input_boolean.coverwzsud
        state: 'off'
action:
  - choose:
      - conditions:
          - condition: state
            entity_id: sensor.season
            state: autumn
        sequence:
          - service: script.rollladen_lux_wz_sud_winter
      - conditions:
          - condition: state
            entity_id: sensor.season
            state: winter
        sequence:
          - service: script.rollladen_lux_wz_sud_winter
    default:
      - service: script.rollladen_lux_wz_sud_sommer
mode: single

Thanks for the help guys!!

The use of a Time Pattern Trigger is unnecessary and inefficient. There’s no need to poll sensors 24x7 because they are perfectly capable of reporting their values.

If you find the Numeric State Trigger isn’t working the way you want, replace it with a State Trigger. Any change to the entity’s value will cause the automation to evaluate its condition (but only when the value changes and not needlessly like every 5 minutes with a Time Pattern Trigger).

alias: Rollladen LUX WZ Sud Winter
description: ''
trigger:
  - platform: state
    entity_id: 
      - sensor.sonne_azimut
      - sensor.000d5d899bf9ed_average_illumination
    for: '00:00:30'
condition:
  - condition: numeric_state
    entity_id: sensor.sonne_azimut
    above: 127
  - condition: numeric_state
    entity_id: sensor.000d5d899bf9ed_average_illumination
    above: 9000
  - condition: state
    entity_id: input_boolean.coverwzsud
    state: 'off'
action:
  - service: "script.rollladen_lux_wz_sud_{{ 'winter' if states('sensor.season') in ['autumn', 'winter'] else 'sommer' }}"
mode: single

I added for: '00:00:30' to the State Trigger. It means the sensor’s value must persist for at least 30 seconds before the trigger occurs. This prevents the automation from being overly sensitive to very brief changes (like if the illumination value rises and falls within a few seconds).

1 Like

Thanks Taras - good hint. I am exluding the trigger of the sensor “sonne_azimut” then, as the azimuth is constantely changing - in fact every minute 24/7. The lux sensor value is only changing during day light timings - hence no unnecessary triggers during the night.