Motion automation for climate

Hi,
I am trying to create a simple automation to activate my A/C if there is a movement in the room for a period of time. my climate is running with broadlink RM. my configuration is as following:

  - platform: broadlink
    name: MDV
    host: 192.168.10.225
    mac: '78:0F:77:5A:EE:00'
    type: rm_mini
    ircodes_ini: 'broadlink_climate_codes/mdv.ini'
    min_temp: 17
    max_temp: 24
    target_temp: 20
    target_temp_step: 1
    temp_sensor: sensor.glass_room_feels_like
    default_operation: 'off'
    default_fan_mode: high
    customize:
      operations:
        - 'Off'
        - 'cool'
      fan_modes:
        - low
        - high
        - auto

My Automation:

- id: diningroomac0001
  alias: Turn A/C On @ Dining Room when there is movement for 45 sec
  trigger:
  - entity_id: binary_sensor.glass_room_motion
    platform: state
    from: 'off'
    to: 'on'
    for:
      seconds: 45
  condition:
    condition: and
    conditions:
      - condition: template
        value_template: "{{ states.sensor.glass_room_feels_like.state | float > 25 }}"
      - condition: state
        entity_id: 'sensor.mdv_status'
        state: 'off'
  action:
    - service: climate.set_operation_mode
      entity_id: climate.mdv
      data:
        operation_mode: 'cool'

The problem if I do not test the status of the climate (off/cool), the automation keep triggering and sending a command to the A/C and you can here the A/C getting a command from the remote. so I created a sensor for the state of the climate and it reports correct if off/cool but the automation will not run as all conditions are not met.

  - platform: template
    sensors:
      mdv_status:
        friendly_name: 'MDV Status'
        value_template: "{{ states.climate.mdv.attributes.operation_mode }}"


and testing it:

What does this output in the template editor:

{{ states.climate.mdv.attributes }}

I can’t see anything wrong with what you have done. This does not mean there isn’t anything wrong (I’'m still learning a lot about HA). The only thing I can suggest is that you try adding the entity id to your template sensor.

  - platform: template
    sensors:
      mdv_status:
        entity_id: climate.mdv
        friendly_name: 'MDV Status'
        value_template: "{{ states.climate.mdv.attributes.operation_mode }}"

Also see what this gives in the template editor:

{{ states.sensor.mdv_status.attributes }}

I am also new to HA, and managed to accomplish alot, but this issue is driving me crazy looking around and trying.
adding the entity_id did not help, same issue.

If I try

{{ states.sensor.mdv_status.attributes }}

it will return:
{'homebridge_hidden': True, 'friendly_name': 'MDV Status'}

which has no status off/cool.

{{ states.sensor.mdv_status.state }}
resturn: Off

Try capitalising ‘Off’ in:

  - condition: state
    entity_id: 'sensor.mdv_status'
    state: 'off'

I did actually tried that, but still not working. not sure really what might be the cause for this.

Let’s have a look at the other condition then.

Does {{ states.sensor.glass_room_feels_like.state | float > 25 }} return True/False in the template editor?

It return True

If you put the following into the template editor what does it return when the AC is off?

{{ states.sensor.mdv_status.state }}

When Off:


When turned on:

try this for your automation conditions:

condition:
  - condition: template
    value_template: "{{ states.sensor.glass_room_feels_like.state | float > 25 }}"
  - condition: state
    entity_id: 'sensor.mdv_status'
    state: 'Off'

replacing my trigger block with this will give an error checking the config. the trigger block is actually the same as you wrote.

Umm…:confused:

I said to replace your condition block with what I posted, not your trigger block…

the condition block is exactly matching what I have original if you check my first post. I do not see the what is the difference.

This is what end up working for me (Thanks for the help guys):

  alias: Turn A/C On @ Dining Room when there is movement for 45 sec
  trigger:
  - entity_id: binary_sensor.glass_room_motion
    platform: state
    from: 'off'
    to: 'on'
    for:
      seconds: 45
  condition:
    condition: and
    conditions:
      - condition: template
        value_template: "{{ states.sensor.glass_room_feels_like.state | float > 25 }}"
      - condition: template
        value_template: "{{ is_state('climate.mdv', 'Off') }}"
      - condition: template
        value_template: "{{ is_state('switch.glassroom_ac_control', 'off') }}"
  action:
    - service: climate.set_operation_mode
      entity_id: climate.mdv
      data:
        operation_mode: 'cool'

Glad to hear it’s working. However, I would recommend changing:

  condition:
    condition: and
    conditions:
      - condition: template
        value_template: "{{ states.sensor.glass_room_feels_like.state | float > 25 }}"
      - condition: template
        value_template: "{{ is_state('climate.mdv', 'Off') }}"
      - condition: template
        value_template: "{{ is_state('switch.glassroom_ac_control', 'off') }}"

to:

  condition:
    condition: template
    value_template: >
      {{ states('sensor.glass_room_feels_like') | float > 25 and
         is_state('climate.mdv', 'Off') and
         is_state('switch.glassroom_ac_control', 'off') }}

There are two reasons. First, this collapses three individual templates to one equivalent template, which is more efficient. Second, it’s always recommended to use the states() function when possible to avoid errors. Consider this more “fine tuning.”

The state you had for your AC in the first post was ‘off’. The state I told you to try was 'Off". There is a difference. Capitalization (or not) is important! One will work and the other won’t. As you’ve experienced.

And what’s funny is that was what you eventually got to work in the template that you posted.

@finity
I did not notice that, because couple of post earlier one solution suggested that and I doubled check the the capitalization and fixed that but it was still not working. This is why I did not notice that.

Thanks anyway for your help.

@pnbruckner Thanks for the suggestion, I adopted and it is working perfect now. :+1: