Help with Heater config

Hi,

iam trying to schedule my Heater but don’t know how.

I have made this:

- id: '1569740962461'
  alias: Mon - Thu
  trigger:
  - below: '21'
    entity_id: sensor.hz_temp
    platform: numeric_state
  condition:
  - after: 05:15:00
    before: '22:20:00'
    condition: time
    weekday:
      - mon
      - tue
      - wed
      - thu
  action:
  - alias: ''
    data:
      entity_id: switch.heater
    service: switch.turn_on

This works, but if the temp drops below 21 before 05:15 it does not start.

You need to check every minute after 05:15. To do this add a time pattern trigger and another condition like this:

- id: '1569740962461'
  alias: Mon - Thu
  trigger:
  - platform: numeric_state
    entity_id: sensor.hz_temp
    below: 21
  - platform: time_pattern
    minutes: "/1"
  condition:
  - condition: numeric_state
    entity_id: sensor.hz_temp
    below: 21
  - condition: time
    after: '05:15:00'
    before: '22:20:00'
    weekday:
      - mon
      - tue
      - wed
      - thu
  action:
    service: switch.turn_on
    entity_id: switch.heater

Now the automation will trigger every minute or if the temperature falls below 21.

The actions will only occur if the temperature is below 21 (in case it was a time trigger) and during the time range you specified.

Tom, I agree this would work but the purest in me objects as this is unnecessarily processor intensive (just 1 check a minute so yeah I’m being picky) surely it would be better to have 2 triggers (the time (05:15) and the temp) and two conditions (again the time slot and the temp)?
Or have I missed something ?

Oh by the way, my apologies, following tink’s reprimand for “tagging you on another thread”

It’s really not that intensive but on further reflection you are right. If the temp goes below 21 during the time period it will trigger so we really do only need to check at the start of the time period.

- id: '1569740962461'
  alias: Mon - Thu
  trigger:
  - platform: numeric_state
    entity_id: sensor.hz_temp
    below: 21
  - platform: time
    at: '05:15:01'
  condition:
  - condition: numeric_state
    entity_id: sensor.hz_temp
    below: 21
  - condition: time
    after: '05:15:00'
    before: '22:20:00'
    weekday:
      - mon
      - tue
      - wed
      - thu
  action:
    service: switch.turn_on
    entity_id: switch.heater

I set the trigger time to ‘05:15:01’ just to make sure the condition after: '05:15:00' is met.

I’m not fussed about being tagged. I’ll just ignore it if I cant help :slight_smile:

Thanks I will try it :slight_smile: I guess I need another automation so that it will stop at 22:20 or can I include it somehow?

Please see : -

Petro said it succinctly.
It’s cleaner, easier to read, find what you’re looking for and maintain with a second automation.

Got another question :slight_smile:
Will this config work or do I have to do a automation for other days?

- id: '1569740962461'
  alias: Mon - Thu
  trigger:
  - platform: numeric_state
    entity_id: sensor.hz_temp
    below: 21
  - platform: time
    at: '05:15:01'
  condition:
  - condition: numeric_state
    entity_id: sensor.hz_temp
    below: 21
  - condition: time
    after: '05:15:00'
    before: '22:20:00'
    weekday:
      - mon
      - tue
      - wed
      - thu
  - condition: time
    after: '08:15:00'
    before: '23:15:00'
    weekday:
      - sat
  - condition: time
    after: '08:15:00'
    before: '22:15:00'
    weekday:
      - sun
  action:
    service: switch.turn_on
    entity_id: switch.heater

Okay I’m not going to answer this, I’m going to get you to answer it.
I will set the scene : - it’s 08:20 on a Saturday and the temperature has just dropped below 21 degrees
So start at the top, what triggers the automation ?
Then take us through what your code is and the decision tree from that point.

The automation is triggered by the second time block because only there Saturday is mentioned.
Well that is the idea, but I don’t know if its working like I think it should work, thats why Iam asking :slight_smile:

No, it will NEVER get there because it stops the whole automation processing at the second condition because the time doesn’t match.
First fail and you’re out.!

(clue: the Saturday does not meet the criteria)
See post 6 again

By default, multiple conditions are logically ANDed. That means the first AND the second AND the third AND the fourth condition must all evaluate to true in order to execute the automation’s action.

What you want is a logical OR. The first condition OR the second condition OR etc. See the documentation for examples: OR condition

Taras, never seen it done but I assume I can use nested or / and conditions in actions and scripts similarly.?

Yes. That’s the very next section in the documentation: Mixed AND and OR conditions. Here’s the example:

condition:
  condition: and
  conditions:
    - condition: state
      entity_id: 'device_tracker.paulus'
      state: 'home'
    - condition: or
      conditions:
        - condition: state
          entity_id: sensor.weather_precip
          state: 'rain'
        - condition: numeric_state
          entity_id: 'sensor.temperature'
          below: 20

Paulus has to be home AND either weather is rain OR the temperature is below 20.

Yes, I read that, but it’s in the conditions section of an automation.
I asked specifically about the action section or in a script

Sorry, but you know not all things are available in all places, eg (probably, but maybe not, as its off the top of my head) template_service

Same answer; I encourage you to try it.

So, this will work, right?

- id: '1569740962461'
  alias: Mon - Thu
  trigger:
  - platform: numeric_state
    entity_id: sensor.hz_temp
    below: 21
  - platform: time
    at: '05:15:01'
condition:
  condition: and
  conditions:
  - condition: numeric_state
    entity_id: sensor.hz_temp
    below: 21
  - condition: or
    conditions:
      - condition: time
        after: '05:15:00'
        before: '22:20:00'
        weekday:
          - mon
          - tue
          - wed
          - thu
      - condition: time
        after: '08:15:00'
        before: '23:15:00'
        weekday:
          - sat
      - condition: time
        after: '08:15:00'
        before: '22:15:00'
        weekday:
          - sun
  action:
    service: switch.turn_on
    entity_id: switch.heater


No, this won’t work
Your yaml spacing is wrong, the first condition header should be in line with trigger, also you will need time triggers for the sat and sun in the trigger section (ie the times for the opening slot as discussed for the first slot) then you will need to indent to follow the preceeding spacings too
The logic otherwise seems sound

Just to be clear: your weekend start times are the same so you only need the 1 extra trigger

Thank you all for your help here is the complete thing it passed the config check :slight_smile:

- id: 'Week'
  alias: Week
  trigger:
  - platform: numeric_state
    entity_id: sensor.hz_temp
    below: 21
  - platform: time
    at: '05:15:01'
  - platform: time
    at: '08:15:01'
  condition:
    condition: and
    conditions:
    - condition: numeric_state
      entity_id: sensor.hz_temp
      below: 21
    - condition: or
      conditions:
        - condition: time
          after: '05:15:00'
          before: '22:15:00'
          weekday:
            - mon
            - tue
            - wed
            - thu
            - fri
        - condition: time
          after: '08:15:00'
          before: '22:15:00'
          weekday:
            - sat
            - sun
  action:
  - device_id: b379fb57788d44baa998b6a5a4589835
    domain: switch
    entity_id: switch.brenner
    type: turn_on

You may wish to add the weekend schedule to the trigger:

  - platform: time
    at: '08:15:01'

EDIT

Never mind. You already posted it while I was composing my message …

EDIT 2
I must admit that the new Device Automation feature is nifty when used in the Automation Editor. However, the YAML it generates is considerably more verbose than the traditional way.

This:

  action:
  - device_id: b379fb57788d44baa998b6a5a4589835
    domain: switch
    entity_id: switch.brenner
    type: turn_on

versus this:

  action:
  - service: switch.turn_on
    entity_id: switch.brenner

One more thing :smile:

I have found the Holiday Sensor. Can I combine this with my automation above so that on holidays the times from saturday and sunday are used?