Automation problem, what am i doing wrong?

I hope somebody can put me in the right direction.
I have an automation that doesn’t work as i expected.

The purpose of the automation is: when the temperature drops below 22 degrees, and the time of the day is between 7:15 - 8:15, and light is already off, then turn on the light(The light is in real a heater). the automation is checked every 2 minutes.
This is the yaml code of the automation.

alias: IR Paneel - Aan door temperatuur - Ochtend
description: ""
trigger:
  - platform: time_pattern
    minutes: /2
condition:
  - condition: or
    conditions:
      - condition: numeric_state
        entity_id: sensor.badkamer_temperatuur_vochtigheid_temperatuur
        below: 22
      - condition: time
        after: "06:15:00"
        weekday:
          - mon
          - tue
          - wed
          - thu
          - fri
        before: "07:15:00"
      - condition: device
        type: is_off
        device_id: ca5bc10110af4b93e948bed4a701a16d
        entity_id: b09e3d7336835bd6fc37a0e0d2afc634
        domain: light
action:
  - type: turn_on
    device_id: ca5bc10110af4b93e948bed4a701a16d
    entity_id: b09e3d7336835bd6fc37a0e0d2afc634
    domain: light
mode: single

In real the light is going on when it is after the supposed time 11:00 in the morning, en when the temperature is already 23 degrees. I don’t understand this.

somebody does?

Stupid of me, on the moment i posted this yaml code i see “condition: or”

This must be “And” il try again.

Conditions are “and” by default, you don’t need to specify.

Looks to me as if the real trigger is the temperature dropping below 22 degrees and the condition is the time of day. Checking every two minutes is unnecessary.

For your time condition, you could make things easier by using a schedule helper - that would be either on or off depending on the day and the time.

Not sure what your exact requirement is, but you may not need to check whether the heater is on - if it’s already on, turning it on again will make no difference.

Best to avoid device IDs if you can.

1 Like
Checking every two minutes is unnecessary.

You are right, i have to fine tune the automation, 2 minutes was for testing purposes. I think when all works well, i set it for 10 minutes.

and i take a look to the other suggestions you made.
Thanks.

Don’t trigger off a time pattern, write it like you want it to work.

trigger:
  - platform: numeric_state
    entity_id: sensor.badkamer_temperatuur_vochtigheid_temperatuur
    below: 22
  - platform: time
    at: "07:15:00"
condition:
  - condition: numeric_state
    entity_id: sensor.badkamer_temperatuur_vochtigheid_temperatuur
    below: 22
  - platform: time
    after: "07:15:00"
  - platform: time
    before: "08:15:00"
  - platform: state
    entity_id: light.YOUR_LIGHT_ID
    state: 'off'
action:
  - service: light.turn_on
    target:
      entity_id: light.YOUR_LIGHT_ID

This triggers when it gets cold OR at 07:15 (in case it’s already cold at that time). It then checks if it’s cold AND in your time range (AND the light is off, probably not necessary), and only turns on the light if both are true.

I’ve replaced the messy device action: you’ll need to put in your light’s entity ID if you use that. Note that your words said 07:15 to 08:15 but your code is an hour earlier than that. Did you not want it to work on a weekend?

In general, if you’re checking every x minutes, you’re doing it wrong.

2 Likes

Caution not to switch on/off to often/fast since that might have consequeces.

1 Like

Thanks. the time is not important yet, first i wanted the automation to work, after that fine tuning for temperatures and time. I had to change your code a little bit, because it give me some errors.

This is what i made of it.

alias: IR paneel - Aan door temperatuur 2
description: ""
trigger:
  - platform: numeric_state
    entity_id:
      - sensor.badkamer_temperatuur_vochtigheid_temperatuur
    below: 22
  - platform: time
    at: "07:15:00"
condition:
  - condition: numeric_state
    entity_id: sensor.badkamer_temperatuur_vochtigheid_temperatuur
    below: 22
  - condition: time
    after: "07:15:00"
    before: "08:15:00"
    weekday:
      - mon
      - tue
      - wed
      - thu
      - fri
action:
  - service: light.turn_on
    target:
      entity_id: light.zigbee_switch_01_licht
    data: {}
mode: single

This is working.

But i had a plan whith the heater with different conditions to turn on and off the heater. i post the yaml code i have, but that code get false temperatures an times to turn on, i don’t know what the cause of that is.
I have 2 automations, 1 to turn the heater on, and on to turn the heater of

for on:

alias: IR Paneel - Aan door temperatuur
description: ""
trigger:
  - platform: time_pattern
    minutes: /4
condition:
  - condition: or
    conditions:
      - condition: numeric_state
        entity_id: sensor.badkamer_temperatuur_vochtigheid_temperatuur
        below: 22
      - condition: time
        after: "06:15:00"
        weekday:
          - mon
          - tue
          - wed
          - thu
          - fri
        before: "07:15:00"
  - condition: or
    conditions:
      - condition: numeric_state
        entity_id: sensor.badkamer_temperatuur_vochtigheid_temperatuur
        below: 23
      - condition: time
        after: "18:45:00"
        weekday:
          - mon
          - tue
          - wed
          - thu
          - fri
          - sat
          - sun
        before: "20:15:00"
  - condition: or
    conditions:
      - condition: numeric_state
        entity_id: sensor.badkamer_temperatuur_vochtigheid_temperatuur
        below: 22
      - condition: time
        after: "07:15:00"
        weekday:
          - sat
          - sun
        before: "08:30:00"
action:
  - service: light.turn_on
    target:
      entity_id: light.zigbee_switch_01_licht
    data: {}
mode: single

the automation for turning the heater off:

alias: IR Paneel - Uit door Temperatuur
description: ""
trigger:
  - platform: time_pattern
    minutes: /4
condition:
  - condition: or
    conditions:
      - condition: numeric_state
        entity_id: sensor.badkamer_temperatuur_vochtigheid_temperatuur
        above: 22.5
      - condition: time
        after: "06:15:00"
        weekday:
          - mon
          - tue
          - wed
          - thu
          - fri
        before: "07:15:00"
  - condition: or
    conditions:
      - condition: numeric_state
        entity_id: sensor.badkamer_temperatuur_vochtigheid_temperatuur
        above: 23.5
      - condition: time
        after: "18:45:00"
        weekday:
          - mon
          - tue
          - wed
          - thu
          - fri
          - sat
          - sun
        before: "20:15:00"
  - condition: or
    conditions:
      - condition: numeric_state
        entity_id: sensor.badkamer_temperatuur_vochtigheid_temperatuur
        above: 22.5
      - condition: time
        after: "07:15:00"
        weekday:
          - sat
          - sun
        before: "08:30:00"
action:
  - service: light.turn_on
    target:
      entity_id: light.zigbee_switch_01_licht
    data: {}
mode: single

I don’t know how i can put this conditions in your code.