Climate Automation With Sensor Template and SmartIR

I’m struggling with an automation for a “dumb” mini-split HVAC in the bedroom. It has no active thermostat - just off and on, heat or cool, etc.

So, I’m using the temperature sensor on a Broadlink RM Pro; created a template to adjust it since it’s in an equipment cabinet.

I created an Automation to turn it on and set the temp to 74 anytime that the sensor is over 75 and it worked (once). Never triggered again after the first day (the Smart IR integration is working fine; the sensor and template sensor are working fine).

Here’s some YAML if anyone can spot something I’ve done wrong:

alias: Climate - Bedroom AC On Via Sensor (Turn On At 74 Degrees)
description: Turn on bedroom AC to cool when temperature is over 74.
trigger:
  - platform: numeric_state
    entity_id: sensor.master_bedroom_adjusted_temperature
    for:
      hours: 0
      minutes: 10
      seconds: 0
    above: 75
condition:
  - condition: state
    entity_id: climate.bedroom_ac
    state: "off"
action:
  - service: climate.turn_on
    data: {}
    target:
      entity_id: climate.bedroom_ac
  - service: climate.set_temperature
    data:
      temperature: 74
      hvac_mode: cool
    target:
      entity_id: climate.bedroom_ac
mode: single
- id: 'automation.climate_bedroomac_cool_sensor_2000'
  alias: Climate - Bedroom AC On Via Sensor (Set To 68 After 8:00PM)
  description: 'Cool down to 68 after 8:00PM.'
  trigger:
    - platform: numeric_state
      entity_id: sensor.master_bedroom_adjusted_temperature
      for:
        hours: 0
        minutes: 10
        seconds: 0
      above: 69
  condition:
    - condition: time
      after: "20:00:00"
  action:
    - service: climate.set_temperature
      data:
        temperature: 68
        hvac_mode: cool
      target:
        entity_id: climate.bedroom_ac
  mode: single

You don’t tell what should happen if the target temperatures have been reached and until what time the temperature should stay at 68 in the morning.

Assuming the AC should stay ON all the time and the temperature should be kept at 74°F from 08:00AM to 08:00PM and the climate is OFF you can merge the two automations into one. Change data as needed:

- id: Climate_Bedroom_Temperature_Control
  alias: Keep temperature below 75°F (daytime) and below 69°F (at night).
  description: >-
    Automatically keep room temperature below 75°F during day time and below
    69°F during the night.
  trigger:
    - platform: state
      entity_id: sensor.master_bedroom_adjusted_temperature
  condition:
    condition: []
  action:
    - choose:
        - conditions:
            - condition: numeric_state
              entity_id: sensor.master_bedroom_adjusted_temperature
              above: '74.00'
              for: '00:10:00'
            - condition: time
              after: '08:00:00'
              before: '20:00:00'
            - condition:
                - "{{ is_state('climate.bedroom_ac', 'off') }}"
          sequence:
            - service: climate.turn_on
              target:
                entity_id: climate.bedroom_ac
            - service: climate.set_hvac_mode
              data:
                entity_id: climate.bedroom_ac
                hvac_mode: cool
            - service: climate.set_temperature
              data:
                entity_id: climate.bedroom_ac
                temperature: 74
        - conditions:
            - condition: numeric_state
              entity_id: sensor.master_bedroom_adjusted_temperature
              above: '68.00'
              for: '00:10:00'
            - condition: time
              after: '20:00:00'
              before: '08:00:00'
            - condition:
                - "{{ is_state('climate.bedroom_ac', 'off') }}"
          sequence:
            - service: climate.turn_on
              target:
                entity_id: climate.bedroom_ac
            - service: climate.set_hvac_mode
              data:
                entity_id: climate.bedroom_ac
                hvac_mode: cool
            - service: climate.set_temperature
              data:
                entity_id: climate.bedroom_ac
                temperature: 68
      default: []
  mode: single
1 Like

Thanks Tamsy, this is great. Had no idea you can combine multiple conditions.

Forgive my ignorance, I’m just a few weeks into HA: It appears that is_state() within the conditional clause is a simple function. Do you know of a list of global functions for HA?

You are welcome.

Regarding templating maybe this helps?

1 Like

Did you have a look at SmartIR
It knows a lot of AC’s by default, and it ain’t too hard to add a new one.

More important in your case, it allows the use of external sensor(s):

Name Type Default Description
temperature_sensor string optional entity_id for a temperature sensor
humidity_sensor string optional entity_id for a humidity sensor
power_sensor string optional entity_id for a sensor that monitors whether your device is actually on or off. This may be a power monitor sensor. (Accepts only on/off states)
1 Like

Yes! That’s great. Thanks!

Hi Aceindy, yes - I did add the custom sensor to the temperature_sensor variable in SmartIR; this allowed the value of the sensor to show on the card in lovelace; but, the only way I can see to have it “do something” with that value is via automation.

Yes, that is correct…the locelace card is ’ just’ a climate entity, using it as thermostat is something else…
But also not impossible :stuck_out_tongue:

Which you can use to control the climate entity :thinking:

1 Like

Well, that’s “cool”, pun intended! Thanks for the heads up!

I’ve been messing with this for the last few days; and I do have it working - again, great Thanks!

For the longest time, I could not get HA to take the automation (it wouldn’t show up when I loaded it). I have all automations in their own YAML file.

So, I started deconstructing the code line by line; couldn’t figure it out. So, I started new Automation in UI and checked the syntax.

I had to change

    - platform: state
      entity_id: sensor.master_bedroom_adjusted_temperature

to

    - platform: state
      entity_id:
        - sensor.master_bedroom_adjusted_temperature

Every other automation I’ve ever written is formatted on one line: entity_id: {entity_id}

Anyone else seen this? This is the first time I’ve used a template entity_id; is there a different syntax?

Do you by any chance edit those files (i.e. automations.yaml, configuration.yaml etc.) using Windows Notepad? :thinking:

Note that Notepad as per default is using Windows Line endings (CRLF) which are different to Unix/Linux line endings (LF). This can lead to all sorts of hard to spot errors because you dont “see” the difference. More information about the latter here.

To remove Windows/DOS characters from a Unix file you can use a Linux app like i.e. dos2unix which easily converts files to Unix format.

As for editing Linux files in Windows better use an editor like the free Notepad++ which will automagically take care of the above.

No, I’m using Dreamweaver. I setup a SFTP connection via SSH. Everything should be UTF-8.

I compared the hidden characters side by side and there were no differences; other than the entity_id being on a separate line with the hyphen (thought the hypen was a specification of a mapping entity only)

I’ve written 30 automations and 67 scripts over the past two weeks; and all have the entity_id: entity_id format with no issues. Just this one. And, I deconstructed the script feature by feature and this is definitely the reason HA wouldn’t take it.

I created 2 identical versions: one with the entity_id on the same line, one without and same line won’t show up.