Need some help with first heating automation

Hello…

I’m still learning, so please bear with me :), also my programming skills are very beginner. I have HA setup, my devices are integrated, and I want to start with automation. This is my automation for heating. if I manually trigger the automation its working…also if i have only 1 condition under time…so obviously multiple AND / OR statements for time is giving me trouble.

What i want to achieve:

turn on AC heating if temperature is below certain point in the morning time frame and afternoon time frame during the week, if someone is at home, and additional time frame condition for weekends.

here is what i came up with;

Thank you for your help.

- alias: Turn on AC heating
  initial_state: True
  trigger:
    platform: numeric_state
    entity_id: sensor.current_temperature
    below: '26'
    for:
      hours: 0
      minutes: 1
      seconds: 0
  condition:
   condition: and
   conditions:
     - condition: state
       entity_id: 'device_tracker.xxx'
       state: 'home'
     - condition: or
       conditions:
       - condition: time
         after: '03:30:00'
         before: '05:30:00'
         weekday:
         - mon
         - tue
         - wed
         - thu
         - fri
       - condition: time
         after: '16:30:00'
         before: '22:00:00'
         weekday:
         - mon
         - tue
         - wed
         - thu
         - fri
       - condition: or
         conditions:
       - condition: time
         after: '13:35:00'
         before: '22:00:00'
         weekday:
         - sat
         - sun
  action:
    - service: notify.mobile_app_XXXXX
      data:
        message: Current temperature is below 23 degrees!
        title: Turning AC heating ON!
    - service: climate.set_temperature
      entity_id: climate.melcloud_xxxx
      data:
        temperature: '28'
    - service: climate.set_fan_mode
      entity_id: climate.melcloud_xxxx
      data:
        fan_mode: 'Speed Auto'
    - service: climate.set_hvac_mode
      data:
        entity_id: climate.melcloud_xxxx
        hvac_mode: 'heat'
    - service: climate.set_swing_mode
      entity_id: climate.melcloud_xxxx
      data:
      swing_mode: 'Swing'	

You were pretty close for a first effort. Try this:

  condition:
    - condition: and
      conditions:
        - condition: state
          entity_id: 'device_tracker.xxx'
          state: 'home'
        - condition: or
          conditions:
            - condition: time
              after: '03:30:00'
              before: '05:30:00'
              weekday:
              - mon
              - tue
              - wed
              - thu
              - fri
            - condition: time
              after: '16:30:00'
              before: '22:00:00'
              weekday:
              - mon
              - tue
              - wed
              - thu
              - fri
            - condition: time
              after: '13:35:00'
              before: '22:00:00'
              weekday:
              - sat
              - sun

It helps with lining everything up if you use an editor like VSCode or Notepad++ that shows spacing or columns.

thank you very much for the help…i changed my code…but still i have some issue…

now its weekend, so condition for weekend should take affect, its working if i set the condition: time after: actual time -5 min, if I set it actual time + 5 minutes, and wait for it to trigger after 5 min and HA restart, it doesn’t trigger.

Should the times be in UTC format or local time format? currently I’m using local.

It will only trigger when the temperature goes below 26 for 1 minute. If it’s already below that temperature when your time range occurs it won’t trigger (except after a restart, as you have discovered).

Very similar issue (and solution) here:

You need to add three time triggers.

oh boy…:slight_smile: there goes Sunday for learning :), thank you for pointing me to the right direction…so i added time triggers like this;

- alias: Turn on AC heating
  initial_state: True
  trigger:
   - platform: numeric_state
     entity_id: sensor.current_temperature
     below: '23'
   - platform: time
     at: '05:45:01'
   - platform: time
     at: '16:16:01'
   - platform: time
     at: '07:00:01'
  condition:
    - condition: and
      conditions:
        - condition: state
          entity_id: 'device_tracker.XXXX'
          state: 'home'
        - condition: or
          conditions:
            - condition: time
              after: '05:45:00'
              before: '07:30:00'
              weekday:
              - mon
              - tue
              - wed
              - thu
              - fri
            - condition: time
              after: '16:15:00'
              before: '22:00:00'
              weekday:
              - mon
              - tue
              - wed
              - thu
              - fri
            - condition: time
              after: '07:00:00'
              before: '22:00:00'
              weekday:
              - sat
              - sun

After that i have automation to turn heating off when reaching above XX degrees:

- alias: Heating AC off
  initial_state: True
  trigger:
    platform: numeric_state
    entity_id: sensor.current_temperature
    above: '24'
    for: "00:15:00"
  condition:
   condition: and
   conditions:
      - condition: state
        entity_id: climate.melcloud_XXXX
        state: 'heat'
  action:
    - service: notify.mobile_app_xxxxx
      data:
        message: Current temperature is above 24 degrees!
        title: Turning AC heating OFF!
    - service: climate.set_hvac_mode
      data:
        entity_id: climate.melcloud_xxxxx
        hvac_mode: 'off

So each time inside the condition-time before hh:mm after hh:hh, temperature droops below 23 the heating on automation will trigger heating ? or do I still have to include below 23 for X time?

Good work now the automation actions will occur if the temperature is already below your trigger point when the time ranges start.

You still have to include the temperature trigger for the case when the temperature drops below the trigger point if the time is somewhere in your time range conditions.

Remove the quotes from around the numbers in your below: and above: levels though.

23 to 24 degrees does not seem like much of a temperature range between on and off.

values are just for testing purpose I will adjust them for real world scenario…removed the quotes as you suggested…now the temperature trigger when temperature falls below trigger point in given time frame…no clue how to do that :slight_smile:

i dont suppose this will do it?
¨¨
below: ‘23’
for:
hours: 0
minutes: 30
seconds: 0
¨¨

No that will require the sensor to be below the trigger point for 30 minutes in the time frames you selected in your conditions.

It already does that. I thought that was what you wanted?

yes that was my idea…will set it up and test for tomorrow morning :slight_smile: thanks again for your help, appreciate it.