Heating Automation based on two triggers in one automation

Hello. I have recently moved from Homebridge to Home Assistant because one lightbulb stopped playing ball and I’m well impressed with what HA can do. But, I have an issue that I cannot resolve. On HB I set the triggers for heating as an any temp change so it constantly checked the conditions. It worked very well and never had issues. But with HA I can get the heating on by using the same type of trigger but not off. Most of the answers online are not what I am looking for as it’s a single temperature based trigger which doesn’t really work all of the time. I have two triggers in the one automation. One for on and one for off as I saw this in an online tutorial. The logic behind the triggers must be sound as it’s coming on. I would greatly appreciate any help. Below is the YAML of the automation
alias: Office Heating Full Day
description: “”
trigger:

  • platform: state
    entity_id:
    • sensor.office_motion_sensor_temperature
      id: Office-heat-on
      alias: Office On Trigger
      from: null
      to: null
  • platform: state
    entity_id:
    • sensor.office_motion_sensor_temperature
      from: null
      to: null
      id: Office-heat-off
      alias: Office off Trigger
      condition:
  • condition: time
    after: “08:05:00”
    before: “17:00:00”
    weekday:
    • mon
    • tue
    • wed
    • thu
    • fri
  • condition: zone
    entity_id: device_tracker.marc_iphone_2
    zone: zone.home
    action:
  • choose:
    • conditions:
      • condition: trigger
        id: Office-heat-on
      • condition: numeric_state
        entity_id: sensor.office_motion_sensor_temperature
        below: 16
        sequence:
      • type: turn_on
        device_id: 1818c9ff45a0bfa855a8
        entity_id: switch.office_heater_outlet
        domain: switch
        alias: “On”
  • choose:
    • conditions:
      • condition: trigger
        id: Office-heat-off
      • condition: numeric_state
        entity_id: sensor.office_motion_sensor_temperature
        above: 18
        sequence:
      • type: turn_off
        device_id: 1818c9ff45a0bfa855a8
        entity_id: switch.office_heater_outlet
        domain: switch
        alias: “Off”
        mode: single

Please use the ‘preformatted text’ image button to format your yaml code, so we can read it properly :thinking:

alias: Office Heating Full
description: ""
trigger:
  - platform: state
    entity_id:
      - sensor.office_motion_sensor_temperature
    id: temperature-trigger
    alias: Office On Trigger
    from: null
    to: null
condition:
  - condition: trigger
    id: temperature-trigger
action:
  - choose:
      - conditions:
          - condition: numeric_state
            entity_id: sensor.office_motion_sensor_temperature
            below: 16
          - condition: zone
            entity_id: device_tracker.marc_smith_iphone
            zone: zone.home
          - condition: time
            after: "08:00:00"
            before: "17:00:00"
            weekday:
              - mon
              - tue
              - wed
              - thu
              - fri
        sequence:
          - type: turn_on
            device_id: cc0c5be322971818c9ff45a0bfa855a8
            entity_id: switch.office_heater_outlet
            domain: switch
      - conditions:
          - condition: numeric_state
            entity_id: sensor.office_motion_sensor_temperature
            above: 18
        sequence:
          - type: turn_off
            device_id: cc0c5be322971818c9ff45a0bfa855a8
            entity_id: switch.office_heater_outlet
            domain: switch
mode: single

Right…

I think you should use 2 triggers:
sensor.office_motion_sensor_temperature above 16
sensor.office_motion_sensor_temperature below 18
and choose you actions based on that.
And then in the choices you can add your conditions again :wink:
This will also prevent the unneccesary triggering on every temperature change :smiley:

alias: Office Heating Full
description: ""
trigger:
  - platform: numeric_state
    entity_id: sensor.office_motion_sensor_temperature
    above: 16
    id: Below
  - platform: numeric_state
    entity_id: sensor.office_motion_sensor_temperature
    above: 18
    id: Above
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - Below
          - condition: time
            weekday:
              - tue
              - mon
              - wed
              - thu
              - fri
          - condition: zone
            entity_id: device_tracker.marc_iphone_2
            zone: zone.home
        sequence:
          - service: switch.turn_on
            data: {}
            target:
              entity_id: switch.office_heater_outlet
      - conditions:
          - condition: trigger
            id:
              - Above
        sequence:
          - service: switch.turn_off
            data: {}
            target:
              entity_id: switch.office_heater_outlet
mode: single

You could still add a trigger to turn off the switch when leaving home, but once the temp is above 18 it will turn off anyway (and stay off) :thinking:

Watch out…here comes my rival @123 :rofl:
For sure his solution is better :roll_eyes:

Is there a reason why you are not using the Generic Thermostat integration to control the heater?

Your automation would simply enable/disable the Generic Thermostat at the appropriate time (i.e. only on weekdays between 8:05 and 17:00 when you are home). The Generic Thermostat is responsible for maintaining the temperature at the desired setpoint. It’s represented by a climate entity so it can (optionally) be displayed in the UI using a Thermostat card.

@123 Hmm…that was not the answer I expected :stuck_out_tongue:

Better nevertheless…

PS: In addition to @123, you’de still have to create a trigger based on when your home (or in the weekends) to set preset_mode: away

Thank you for this. I have not heard of the GTI control. That sounds much better. I will read up on this now and try that instead.

Cheers

Hi all,
If anyone is looking for an answer to the same issue this is the solution that I came up with. It has worked flawlessly for about 3 weeks and it keeps it neat. I basically have different options depending on the time of day. So a heating run in the am. Heating run at lunchtime etc etc. It does trigger about 6 times per hour but that’s acceptable if it works. If HA started to neaten up it’s automations I would perhaps write something for each time. For now that would be incredibly messy.

alias: Dining Room Heating am
description: ""
trigger:
  - platform: state
    entity_id:
      - sensor.dining_temperature
    alias: heat-on
    to: null
    id: Temp-trigger
    from: null
condition:
  - condition: trigger
    id:
      - Temp-trigger
    enabled: false
action:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - Temp-trigger
          - condition: zone
            entity_id: device_tracker.unifi_12_17_3f_37_f2_83_default
            zone: zone.home
            enabled: true
          - condition: zone
            entity_id: device_tracker.jazz_iphone
            zone: zone.home
            enabled: false
          - condition: time
            after: "07:00:00"
            before: "09:00:00"
            weekday:
              - mon
              - tue
              - wed
              - thu
              - fri
              - sat
              - sun
          - type: is_temperature
            condition: device
            device_id: 53b8a9fb591f41ff5eaa84768d1ff81b
            entity_id: sensor.dining_temperature
            domain: sensor
            below: 17
        sequence:
          - service: scene.turn_on
            target:
              entity_id: scene.morning_heating
            metadata: {}
      - conditions:
          - condition: trigger
            id:
              - Temp-trigger
          - type: is_temperature
            condition: device
            device_id: 53b8a9fb591f41ff5eaa84768d1ff81b
            entity_id: 117bb39207a98538e90cdcfe42ce0ca6
            domain: sensor
            above: 20
        sequence:
          - device_id: 53b8a9fb591f41ff5eaa84768d1ff81b
            domain: climate
            entity_id: 77791c4a635aa2b950e37bd6c75359f6
            type: set_hvac_mode
            hvac_mode: "off"
          - device_id: 13391a52d72bf2bd16a03650f7606352
            domain: climate
            entity_id: 58e0301f1347364164a42dd14e4520e6
            type: set_hvac_mode
            hvac_mode: "off"
          - device_id: 9309bebb96934524d29837e98d1d64cb
            domain: climate
            entity_id: 55624a4f719623c052fb221411b75847
            type: set_hvac_mode
            hvac_mode: "off"
      - conditions:
          - condition: trigger
            id:
              - Temp-trigger
          - condition: time
            before: "13:30:00"
            after: "11:30:00"
            weekday:
              - mon
              - tue
              - wed
              - thu
              - fri
              - sat
              - sun
          - condition: zone
            entity_id: device_tracker.unifi_12_17_3f_37_f2_83_default
            zone: zone.home
          - condition: numeric_state
            entity_id: sensor.dining_temperature
            below: 16
        sequence:
          - service: scene.turn_on
            target:
              entity_id: scene.morning_heating
            metadata: {}
      - conditions:
          - condition: trigger
            id:
              - Temp-trigger
          - condition: time
            after: "16:00:00"
            before: "19:00:00"
            weekday:
              - mon
              - tue
              - wed
              - thu
              - fri
              - sat
              - sun
          - condition: zone
            entity_id: device_tracker.unifi_12_17_3f_37_f2_83_default
            zone: zone.home
          - condition: numeric_state
            entity_id: sensor.dining_temperature
            below: 16
        sequence:
          - service: scene.turn_on
            target:
              entity_id: scene.morning_heating
            metadata: {}
    alias: "On"
mode: single

It’s triggered every time the value of sensor.dining_temperature changes.

If you used the Generic Thermostat integration, the automation that would control it would be more concise, easier to maintain, and more flexible than what you posted above.

The Generic Thermostat integration produces a climate entity whose sole responsibility is to maintain a target temperature. The automation’s task is to control the climate entity’s operation based on your preferences such as occupancy, schedule, etc. You could optionally use the Schedule integration to specify operating hours.

Your reply got me thinking if I also should be using the generic thermostat and how to nest additional functions inside the automation.

I have an automation already working that cools or heats at certain times using the scheduler. But when the temp is reached the AC fan stays on (without cooling or heating). From what I gather this is normal AC behavior. But I would rather have the AC turn off when the temp is within range. Reason for this is that in my climate it can be days, weeks or even months between operations. All that time the AC will create a draft with its fan and use electricity.

I control the AC through ESPHome:

climate:
  - platform: midea
    name: Midea Climate         

My automation is as follows:

alias: AC keuken test
description: ""
trigger:
  - platform: state
    entity_id:
      - schedule.ac_schedule_keuken
condition: []
action:
  - if:
      - condition: state
        entity_id: schedule.ac_schedule_keuken
        state: "on"
    then:
      - service: climate.set_temperature
        data:
          hvac_mode: heat_cool
          target_temp_high: 24
          target_temp_low: 18
        target:
          device_id: 420c7c08d2be1c310c16763a2461294f
    else:
      - service: climate.set_hvac_mode
        data:
          hvac_mode: "off"
        target:
          device_id: 420c7c08d2be1c310c16763a2461294f
mode: single```

I’ve been playing with Generic Thermostats and scheduler. The Scheduler is an amazing tool and works well. The same can’t be said for the generic thermostats. I’m not sure what in the hell I’m doing wrong but when I set the temperature in the config/yaml it’s blindly ignored and does whatever it wants. Whilst I set it at 18 on some mornings it comes on at 25C. No idea why either. It’s always wrong, just different every time. Maybe it doesn’t work with Tado as I have them working successfully on 3 oil filled electric heaters.
I have kept the thermostats in play and the automation now triggers a scene based on the schedule I set. This way I can specifiy the exact temperature I want and it just works.
The only reason I have kept the GT as it’s useful for adjusting the temperature after the automation has triggered. Or if you want a quick blast in between schedules.
In the next week I will create an video that explains the entire process for anyone else that has had this convoluted process keep them up a night. For the past week my heating has works perfectly using automation, schedules and scenes so feel I can offer something to newbies like me who just want something simple.

If anyone else is having issues with Tado and Generic Thermostat this is the solution I have found works well. I’m guessing they are just don’t work together.

Good morning @Perla
i am trying out your code and i am also having a midea unit, but i dont get the options for min and max temp and so on…
in your code it states the max and min and how does your scheduler look like?
Just standard time x on and time y off?
Thx alot, cause i would love to use this ac in a way that she turns on and off as needed and not staying on the hole time blowing air…