Automation that doesn't work properly

I made this automation using UI
The automation should check a sensor value every 10 minutes, if the value is above x, the automation should send a notification through Alexa
The condition is only notify from 10:00 am till 00:30 am, and only when two smartphone is at home.
Unfortunately the automation I made just send the notification through alexa but it doesn’t check the value…in fact if I manually check the sensor value it is above the amount I setted in the automation
Could someone help me to refine the code

- id: Avviso Umidità bagno

  alias: Avviso Umidità bagno

  trigger:

  - minutes: /10

    platform: time_pattern

  condition:

  - condition: and

    conditions:

    - condition: time

      after: '10:30:00'

      before: 00:30:00

    - condition: or

      conditions:

      - condition: zone

        entity_id: device_tracker.22_e0_9b_17_ff_08

        zone: zone.home

      - condition: zone

        entity_id: device_tracker.06_da_cd_d5_7d_f6

        zone: zone.home

      - condition: and

        conditions:

        - condition: numeric_state

          entity_id: sensor.sensore_muffa_bagno

          above: '70'

  action:

  - service: notify.alexa_media

    data:

      target:

      - media_player.echo_dot_1, media_player.echo_dot_2

      data:

        type: announce

        method: all

      message: Umidità alta in bagno apri la finestra

  mode: single

Can the time ever be after 10:30 and before 00:30?

1 Like

It’s possible that the condition you created is responsible for the incorrect behavior. The condition does this:

(Time is between 10:30 and 00:30)
AND
(Tracker1 is home OR Tracker2 is home OR Temperature > 70)

Perhaps what you want is this:

(Time is between 10:30 and 00:30)
AND
(Temperature > 70)
AND
(Tracker1 is home OR Tracker2 is home )

- id: Avviso Umidità bagno
  alias: Avviso Umidità bagno
  trigger:
  - minutes: /10
    platform: time_pattern
  condition:
  - condition: and
    conditions:
    - condition: time
      after: '10:30:00'
      before: 00:30:00
    - condition: numeric_state
      entity_id: sensor.sensore_muffa_bagno
      above: '70'
    - condition: or
      conditions:
      - condition: zone
        entity_id: device_tracker.22_e0_9b_17_ff_08
        zone: zone.home
      - condition: zone
        entity_id: device_tracker.06_da_cd_d5_7d_f6
        zone: zone.home
  action:
  - service: notify.alexa_media
    data:
      target:
      - media_player.echo_dot_1, media_player.echo_dot_2
      data:
        type: announce
        method: all
      message: Umidità alta in bagno apri la finestra
  mode: single

People often seem to get hung up on conditions and end up building over-complex ones. Worth noting conditions are AND by default, so @123’s suggestion plus @Stiltjack’s observation can be expressed as:

  condition:
  - condition: or
    conditions:
      - condition: time
        after: '10:30:00'
      - condition: time
        before: '00:30:00'
  - condition: numeric_state
    entity_id: sensor.sensore_muffa_bagno
    above: '70'
  - condition: or
    conditions:
      - condition: zone
        entity_id: device_tracker.22_e0_9b_17_ff_08
        zone: zone.home
      - condition: zone
        entity_id: device_tracker.06_da_cd_d5_7d_f6
        zone: zone.home

Basically, if you’re putting a condition: and at the top-level, you should have another look.

It isn’t necessary to split the single Time Condition into two separate Time Conditions.

From the documentation for Time Condition:

Time condition windows can span across the midnight threshold if both after and before keys are used.

1 Like

Yes this is whta I would like

(Time is between 10:30 and 00:30)
AND
(Temperature > 70)
AND
(Tracker1 is home OR Tracker2 is home )

I’ll try your code

It also isn’t necessary to pile all this into one automation. I personally would use three input_boolean flags, each toggled on and off by short automations. Then all the main automation has to do is check three simple conditions every 10 minutes:

time on
temperature on
someone home on

OK… do notification

It also makes maintenance easier six months later when you’ve forgotten what the damn thing does and you need to change the time range.

Now we have broached the subject of what isn’t necessary, it’s unnecessary to poll the conditions every 10 minutes with a Time Pattern Trigger.

I’ve never used that - can you point me to the documentation?

Never used what?

Sorry - time pattern trigger.

It’s what Akkor70 has used in the posted automation.

Thanks - found it.