Best practice for On / Off AC automation based on multiple conditions

So i’m trying to figure out the best approach for this, I have an AC in coworking space that i’d like to automate based on 4 conditions :

  • time
  • motion
  • wifi count
  • temperature

Something like this, the syntax might still be incorrect :

condition:
  alias: "Daikin Coworking AC ON"
  condition: and
  conditions:
    - condition: numeric_state
      entity_id: "wifi count"
      state: ">2"
    - condition: state
      entity_id: "Motion detection coworking"
      state: "ON"
    - condition: numeric_state
      entity_id: "temp"
      state: ">23"	  
    - condition: numeric_state
      entity_id: "time"
      state: "0700-2100"	  
	    
	  
	  
condition:
  alias: "Daikin Coworking AC OFF"
  condition: OR
  conditions:
    - condition: numeric_state
      entity_id: "wifi count"
      state: "<2"
    - condition: numeric_state
      entity_id: "temp"
      state: "<23"		  
    - condition: numeric_state
      entity_id: "time"
      state: "2101-0659"

The ON condition is more strict as it has to met all 4 conditions, while OFF condition can be any of the 3.
So what would be the ideal trigger for this purpose? And would it be better to separate them or have them as 1 automation?

Would start by reading about automations to get a solid understanding.

For HVAC triggers I personally TRIGGER based on temperature and then set CONDITIONS that need to be met for the unit to turn on. Worth realizing that temperature (numeric) based triggers only trigger when the THRESHOLD is crossed. So if Temp > 23 is trigger then going from 24->25 would not trigger, only 23 → greater than 23.

To this end, you can then use conditions as triggers and triggers as conditions.

IE.

TRIGGERS:
Temp > 23
Wifi > 2
Motion = ON
Time at 7am

CONDITIONS:
Temp > 23
Wifi > 2
Motion = ON
Time > 7am
Time < 11pm

You could do something similar for the OFF in a second automation

Worth noting that motion is tricky and can false positive (or false negative) often. IE. Someone sitting still would likely show motion = OFF, even though they’re in the office. It would also turn your unit potentially ON/OFF quite often

If these conditions are and then I believe the AC will be off all the time.

@Markus99 Yeah i’m still trying to wrap my head around this.
So you’re saying i should use multiple triggers and multiple conditions like this? :

automation:
  trigger:
    - platform: temp
      state:>23 
    - platform: wifi count
      event: wifi count >2
    - platform: Motion detection
      event : Motion detection ON
    - platform: wifi count
      event: wifi count >2

condition:
  alias: "Daikin Coworking AC ON"
  condition: and
  conditions:
    - condition: numeric_state
      entity_id: "wifi count"
      state: ">2"
    - condition: state
      entity_id: "Motion detection coworking"
      state: "ON"
    - condition: numeric_state
      entity_id: "temp"
      state: ">23"	  
    - condition: numeric_state
      entity_id: "time"
      state: "0700-2100"

Yeah that kinda makes sense, so whenever any of them is triggered HA would evaluate the other conditions. But wouldn’t that mean the same trigger and condition gets double checked? e.g motion then motion?

About motion, i’m open to any option that works with hikvision cam, either hiksink / hikvision built in / motion detection from BI etc

@Hellis81 Because the delay would be too long to execute another check?

No because the motion detector will (probably) not show on for long enough.
Not sure how your wifi count works but that could also be a failpoint.

Sorry should have mentioned, i plan on using hikvision cam’s built in motion detector since it support zoning, that way i could draw only the coworking area to minimize false positive from another area e.g from windows. I think i could reduce the check period to 1 sec to ensure ON is long enough… but i will have to check again.
But i’m open to suggestion as long as i could achieve my goal.

Haven’t used that type of camera setup / detection personally, so can’t exactly speak to how it performs, how long motion ‘on’ would be set, etc.

You could trigger on motion = on and condition based on motion = on has occurred w/in the last XX minutes, so as long as there was motion in the last 10 or 20 or whatever minutes

I use this in one of my automations:

{{ ((( now().timestamp() -  as_timestamp(states.switch.front_porch_lights.last_changed))
      / 3600 ) | int) > 15 }}

You could also trigger a 10, 20, 15, whatever duration minute timer when motion is sensed and use is that timer running as a condition. Worth noting that last_changed wouldn’t accurately survive a restart, but (at least as of 2022.4.x) I believe timers now do.

Really comes down to the specific rules you want to set based on your criteria and how the device(s) report data to Home Assistant to leverage/reference.

I’m testing to see which one is the most ideal option, but i’m stuck cause daikin’s integrated internal temp cannot be used as sensor, it looks like this in developer > entity > daikin internal temp

Name
Daikin Coworking Space Inside Temperature

State 
33.0

State attributes (YAML, optional)
state_class: measurement
unit_of_measurement: °C
device_class: temperature
friendly_name: Daikin Coworking Space Inside Temperature

Putting the sensor with any of the attributes would throw

Daikin_Coworking_OFF' trigger: In 'numeric_state' condition: entity sensor.daikinap_inside_temperature state '°C' cannot be processed as a number

I’ve tried creating template like this but still no luck

template:

  • sensor:
    name : “Coworking_temp”
    value_template: “{{ state_attr(‘daikinap_inside_temperature’, ‘current_temperature’) }}”
    unit_of_measurement: ‘°C’
    friendly_name: ‘Coworking_temp’
    state_class: measurement
    device_class: temperature

any ideas?

isn’t state the temperature?

Ah yes i just realized you don’t have to set attributes…

But I still cant figure out the best method for this whole threshold temperature thing
I just want use temp as trigger / condition as long as it’s between certain values,
let’s say 21 and 30 celcius

So basically, if i use temp as trigger, it’s better if i use generic thermostat?

But if i use temp as condition the ‘above’ and ‘below’ numeric state should work exactly as i want?

Yes the generic thermostat works fine.
But it will not work with all your conditions as it currently is.
You would still need some automation to toggle the thermostat on/off based on the time of day and motion sensor and all that.

- id: '1649917022433'
  alias: Daikin_Coworking_ON
  description: ''
  trigger:
  - platform: template
    id: wifi_count
    value_template: "{{ states('sensor.unifi_counter_sensor') | float > 1 |float }}"
  condition:
  - condition: and
    conditions:
    - condition: template
      value_template: "{{ states('sensor.daikinap57765_inside_temperature') | float
        > 24 |float }}"
    - condition: state
      entity_id: binary_sensor.ip_camera_motion
      state: 'ON'
    - condition: time
      before: '22:00:00'
      after: '07:00:00'
    - condition: state
      entity_id: climate.daikinap57765
      state: 'OFF'
  action:
  - service: climate.set_hvac_mode
    data:
      hvac_mode: cool
    target:
      entity_id: climate.daikinap57765
  mode: restart

Ok i’ve tested with this, just one trigger to see if it works properly. But it wont fire going from wifi client 2 to 3. I’ve checked all the conditions in developre tools and it should be met. Any ideas?
With that code isnt it supposed to check number of connected wifi clients periodically instead of waiting til it drops to x like the one in docs?

Here’s the related entities and their state

sensor.unifi_counter_sensor : 2 (then 3 after i connect my phone)

binary_sensor.ip_camera_motion : ON

sensor.daikinap57765_inside_temperature : 33.0

climate.daikinap57765 : OFF

You have set your template trigger to listen for the changes between 1 and 2… any change in value above 2 has no effect on the trigger. If you want the threshold to be the changes between 2 and 3, then your trigger needs to reflect that.

Also the possible states of binary sensors are ‘on’, ‘off’, ‘unknown’, and ‘unavailable’… never ‘ON’ or ‘OFF’. Similarly, climate entities will never be ‘OFF’.

All together:

- id: '1649917022433'
  alias: Daikin_Coworking_ON
  description: ''
  trigger:
    - platform: template
      id: wifi_count
      value_template: "{{ states('sensor.unifi_counter_sensor') | int > 2 }}"
  condition:
    - condition: template
      value_template: >
        {{ states('sensor.daikinap57765_inside_temperature') | float(0) > 24 }}
    - condition: state
      entity_id: binary_sensor.ip_camera_motion
      state: 'on'
    - condition: time
      before: '22:00:00'
      after: '07:00:00'
    - condition: state
      entity_id: climate.daikinap57765
      state: 'off'
  action:
    - service: climate.set_hvac_mode
      data:
        hvac_mode: cool
      target:
        entity_id: climate.daikinap57765
  mode: restart
1 Like

Thanks, i tested it briefly with 1 to 2 and it seems to work, i will test it again with multiple devices tomorrow.

One more thing, why doesnt this work to turn off when going from 2 to 1 wifi?


- id: '1649917247096'
  alias: Daikin_Coworking_OFF
  description: Turn OFF daikin Coworking IF conditions are not met
  trigger:
  - platform: state
    entity_id: climate.daikinap57765
    from : 'off'
    to: 'on' 
  - platform: time
    at:
    - '22:00:00'
    - '07:00:00'
  - platform: template
    id: wifi_count
    value_template: "{{ states('sensor.unifi_counter_sensor') | int < 2 }}"
  - platform: template
    id: climate.daikinap57765
    value_template: '{{ states(''sensor.daikinap57765_inside_temperature'') | int < 24 }}'
  - platform: state
    entity_id: binary_sensor.ip_camera_motion
    to: 'off'
    for: 00:05:00
  condition:
  - condition: and    
    conditions:
    - condition: template
      value_template: '{{ states(''sensor.daikinap57765_inside_temperature'') | int < 24 }}'
    - condition: state
      entity_id: binary_sensor.ip_camera_motion
      state: 'on'
    - condition: time
      before: '22:00:00'
      after: 07:00:00
    - condition: template
      value_template: "{{ states('sensor.unifi_counter_sensor') | int < 2 }}"      
  action:
  - service: climate.turn_off
    data: {}
sensor.unifi_counter_sensor : 2 (then 1 after i disconnect my phone)

binary_sensor.ip_camera_motion : on

sensor.daikinap57765_inside_temperature : 33.0

climate.daikinap57765 : on

If I’m understanding your post correctly, it is not turning off because your temperature condition is not met… 33 > 24