Control the air conditioner

Does not work for me

I use Broadlink to control my dumb daikin air conditioner.
Each code includes every setting involved. i.e. One code tells the aircon to turn on to a set mode, temp, fan speed, & directional movement. So, I got the codes for each setting that I wanted and created a script for each, plus one to turn it off. Each script is labeled in a specific way. ie. Fan 4 (Fan 4th Speed), Cool 23l (Cool 23ºc Low Speed), Heat 14h (Heat 14ºc High Speed). I only did the settings & temps I’d be likely to use.

  scripts:
    aircon_fan_1:
       sequence:
         - service: broadlink.send
           data:
             host: 192.168.1.4
             packet: 
               -  'CODE'
         - delay: "00:00:01"

      aircon_cool_23l:
       sequence:
         - service: broadlink.send
           data:
             host: 192.168.1.4
             packet: 
               -  'CODE'
         - delay: "00:00:01"
               
      aircon_heat_14h:
       sequence:
         - service: broadlink.send
           data:
             host: 192.168.1.4
             packet: 
               -  'CODE'
         - delay: "00:00:01"

I then have 4 Input Selects: Aircon Fan, Aircon Cool, Aircon Heat, Aircon Last Setting. eg. The Heater:

 input_select:
   aircon_heat:
        name: Heater
        options:
          - "Off"
          - "Heat 14l"
          - "Heat 14m"
          - "Heat 14h"       
          - "Heat 15l"
          - "Heat 15m"
          - "Heat 15h"       
          - "Heat 16l"
          - "Heat 16m"
          - "Heat 16h" 
          - "Heat 17l"
          - "Heat 17m"
          - "Heat 17h" 
          - "Heat 18l"
          - "Heat 18m"
          - "Heat 18h"  
          - "Heat 19l"
          - "Heat 19m"
          - "Heat 19h"  
          - "Heat 20l"
          - "Heat 20m"
          - "Heat 20h" 
        icon: mdi:white-balance-sunny

I then have the following automations. Trigger watches for changes in Fan/Heat/Cool Input Selects. Condition is a sensor checking that certain doors & windows are closed. Actions change the other input selects to Off, Changes Aircon Last Setting to the input selected, and runs the appropriate script to send the broadlink code:

automations: 
   - alias: Aircon Off
      trigger: 
         - platform: state
           entity_id: input_select.aircon_fan
           to: "Off"
         - platform: state
           entity_id: input_select.aircon_cool
           to: "Off"
         - platform: state
           entity_id: input_select.aircon_heat
           to: "Off"
      action:
         - service: script.aircon_off

    - alias: Aircon Heat On
      trigger: 
         - platform: template
           value_template: "{{not is_state('input_select.aircon_heat', 'Off')}}"
      condition:
         - condition: template
           value_template: "{{is_state('sensor.aircon_conditions','yes')}}"
      action:
         - service: input_select.select_option
           data:
             option: "Off"
             entity_id: input_select.aircon_fan
         - service: input_select.select_option
           data:
             option: "Off"
             entity_id: input_select.aircon_cool
         - service: input_select.select_option
           data_template:
             entity_id: input_select.aircon_last_setting
             option: "{{ states('input_select.aircon_heat') }}"
         - service_template: script.aircon_{{ states("input_select.aircon_last_setting")|replace(" ","_")|lower}}

    - alias: Aircon Cool On
      trigger: 
         - platform: template
           value_template: "{{not is_state('input_select.aircon_cool', 'Off')}}"
      condition:
         - condition: template
           value_template: "{{is_state('sensor.aircon_conditions','yes')}}"
      action:
         - service: input_select.select_option
           data:
             option: "Off"
             entity_id: input_select.aircon_fan
         - service: input_select.select_option
           data:
             option: "Off"
             entity_id: input_select.aircon_heat
         - service: input_select.select_option
           data_template:
             entity_id: input_select.aircon_last_setting
             option: "{{ states('input_select.aircon_cool') }}"
         - service_template: script.aircon_{{ states("input_select.aircon_last_setting")|replace(" ","_")|lower}}

    - alias: Aircon Fan On
      trigger: 
         - platform: template
           value_template: "{{not is_state('input_select.aircon_fan', 'Off')}}"
      condition:
         - condition: template
           value_template: "{{is_state('person.kat','home')}}"
      action:
         - service: input_select.select_option
           data:
             option: "Off"
             entity_id: input_select.aircon_heat
         - service: input_select.select_option
           data:
             option: "Off"
             entity_id: input_select.aircon_cool
         - service: input_select.select_option
           data_template:
             entity_id: input_select.aircon_last_setting
             option: "{{ states('input_select.aircon_fan') }}"
         - service_template: script.aircon_{{ states("input_select.aircon_last_setting")|replace(" ","_")|lower}}

The Aircon Last Setting allows me to also have a switch to turn on/off the aircon by applying the last selected setting:

 switch:    
   aircon:
         friendly_name: Air Conditioner Switch
         value_template: "{{ is_state('sensor.aircon', 'on') }}"
         turn_on:
          - service: input_select.select_option
            data_template: 
              entity_id: >
               {% if 'Fan' in  states.input_select.aircon_last_setting.state %} 
                 input_select.aircon_fan
               {% elif 'Cool' in  states.input_select.aircon_last_setting.state %} 
                 input_select.aircon_cool
               {% elif 'Heat' in  states.input_select.aircon_last_setting.state %}
                 input_select.aircon_heat
               {% else %}
                script.nope
               {% endif %}
              option: "{{ states.input_select.aircon_last_setting.state }}"
         turn_off:
          - service_template: >
               {% if is_state('sensor.aircon', 'off')%}
                 script.turn_on
               {% else %}
                   input_select.select_option
               {% endif %}
            data_template:
               option: "Off"
               entity_id: >
                 {% if is_state('sensor.aircon', 'off')%}
                   script.nope
                 {% elif  not is_state('input_select.aircon_fan', "Off") %} 
                     input_select.aircon_fan
                 {% elif not is_state('input_select.aircon_cool', "Off") %} 
                      input_select.aircon_cool
                 {% elif not is_state('input_select.aircon_heat', "Off") %} 
                      input_select.aircon_heat
                 {% else %}
                      script.nope
                 {% endif %}
          - service: automation.trigger
            entity_id: automation.aircon_off
         icon_template: >
            {% if is_state('sensor.aircon', 'off') %} 
               mdi:air-conditioner
            {% elif 'Fan' in  states.input_select.aircon_last_setting.state %} 
               mdi:weather-windy
            {% elif 'Cool' in  states.input_select.aircon_last_setting.state %} 
              mdi:snowflake
            {% elif 'Heat' in  states.input_select.aircon_last_setting.state %}
               mdi:white-balance-sunny
            {% else %}
               mdi:air-conditioner
            {% endif %}  

End Result on my main view: Pressing the Last Aircon Setting toggles aircon on/off, or to change the setting, I can use the drop down menus. There might be a simpler way to achieve this, but as it is, it’s working perfectly.

I used Vertical-Stack-In-Card, Entities Card & Button Card in lovelace. This is the relevent code:

type: 'custom:vertical-stack-in-card'
cards:

  - type: 'custom:button-card'
    template: aircon_last
    entity: input_select.aircon_last_setting

  - type: entities
    show_header_toggle: false
    entities:
      - entity: input_select.aircon_fan
        name: Fan
      - entity: input_select.aircon_cool
        name: Cool
      - entity: input_select.aircon_heat
        name: Heater

 button_card_templates:
  aircon_last:
        layout: icon_name_state2nd
        show_name: true
        show_state: true
        icon: 'mdi:help'
        tap_action:
          action: call-service
          service: switch.toggle
          service_data:
            entity_id: switch.aircon
        hold_action:
           action: more-info
        state:
          - color: var(--primary-button-colour)
            icon: 'mdi:fan'
            operator: template
            value: >
              var ac = states['switch.aircon'].state; return (ac ===
              'off' &&
              /F/.test(states['input_select.aircon_last_setting'].state))
              ;
          - color: var(--secondary-button-colour)
            icon: 'mdi:fan'
            operator: template
            value: >
              var ac = states['switch.aircon'].state; return (ac ===
              'on' &&
              /F/.test(states['input_select.aircon_last_setting'].state))
              ;
          - color: var(--primary-button-colour)
            icon: 'mdi:snowflake'
            operator: template
            value: >
              var ac = states['switch.aircon'].state; return (ac ===
              'off' &&
              /C/.test(states['input_select.aircon_last_setting'].state))
              ;
          - color: var(--secondary-button-colour)
            icon: 'mdi:snowflake'
            operator: template
            value: >
              var ac = states['switch.aircon'].state; return (ac ===
              'on' &&
              /C/.test(states['input_select.aircon_last_setting'].state))
              ;
          - color: var(--primary-button-colour)
            icon: 'mdi:snowflake'
            operator: regex
            value:
              - C
          - color: var(--primary-button-colour)
            icon: 'mdi:white-balance-sunny'
            operator: template
            value: >
              var ac = states['switch.aircon'].state; return (ac ===
              'off' &&
              /H/.test(states['input_select.aircon_last_setting'].state))
              ;
          - color: var(--secondary-button-colour)
            icon: 'mdi:white-balance-sunny'
            operator: template
            value: >
              var ac = states['switch.aircon'].state; return (ac ===
              'on' &&
              /H/.test(states['input_select.aircon_last_setting'].state))
              ;
        styles:
          name:
            - font-size: 12px
            - padding: 0px 40px 0px 0px
          state:
            - padding: 0px 40px 0px 0px
1 Like

This is pretty cool @PodPerson - thanks for sharing.

This is neat. Thanks for sharing.
Do you then digest the input booleans in automations? Care to share?
Am also curious about your condensation chance sensor… I could see some use for this!

I’m travelling and don’t have access to my config at the moment. Yes all actioned in automations.

The condensation sensor is this:

1 Like

Cheers. That’s great!
Let us know when you’re back. Safe travels…

I use this:

It looks like this:

and works with Broadlink IR bridges. If anyone wants to see the config let me know.

I use something similiar as @zoogara - Instead of purchasing a Broadlink I’m using a Nodemcu to send the IR codes. I’ve also attached a temperature/humidity sensor which sends data back to my HA. The Nodemcu is communicating via MQTT. Works great and the whole set up is no more that $4 per AC.
( I cannot figure out how to change the temperature to F, i have my units set to metric as i need it in celsius for my 3d printer cards.)

Nice. I use the Daikin component. In Lovelace, the card defaults to the standard thermostat card. Unfortunately, I can’t set things like fan speed via these. May need to come up with a custom card for it…

Hi, Can you show me how to put it to work ? Mine only turns off the AC. All the other buttons won’t work.
thanks a lot.

For starters, does your air conditioner appear in this list? https://github.com/smartHomeHub/SmartIR/blob/9691aaaf622de33eaaeab7b02c452ce054d8e395/docs/CLIMATE.md#available-codes-for-climate-devices

If it doesn’t then you have a long and arduous process ahead capturing codes, but no different than most other climate control solutions in HA.

Hello, thx for your reply,
And yes, my ac appears in this list, I have a gree ac.

I am also able to learn the remote codes.
What I can’t figure out os how to create the entities/service/devices ao I can create the ac card amd add the controls to it.

Ok - I am assuming you have installed the SmartIR custom component.

First thing is to enable SmartIR and define your Broadlink IR bridge, substituting your IP, MAC and type:

smartir:

switch:
  - platform: broadlink
    host: 192.168.0.136
    mac: '34:ea:34:e3:ad:52'
    type: rm_mini
    friendly_name: "Kitchen IR"

Then add SmartIR as a climate integration:

climate:
  - platform: smartir
    name: Kitchen AC
    device_code: 1282
    controller_data: 192.168.0.136
    temperature_sensor: sensor.kitchen_temperature
    humidity_sensor: sensor.kitchen_humidity

Your device code should match the one for your A/C, and ensure it exists in /config/custom_components/smartir/codes/climate. Choose a suitable sensor for temp and humidity, if you don’t have these I believe you can leave them out.

Lastly add a suitable card to Lovelace:

  - cards:
      - type: thermostat
        entity: climate.kitchen_ac
        name: Kitchen Air Conditioner
    icon: 'mdi:air-conditioner'
    state_color: true
    title: ac_view

The instructions for the SmartIR are actually on GitHub: https://github.com/smartHomeHub/SmartIR/blob/9691aaaf622de33eaaeab7b02c452ce054d8e395/docs/CLIMATE.md

Otherwise feel free to ask questions in the SmartIR thread: SmartIR - Control your Climate, TV and Fan devices via IR/RF controllers

And don’t forget to post your config if you have an issue.

If it still doesn’t work after this then maybe your a/c is a newer model and you will have to capture your own codes.

1 Like

I got all the, just the card I don’t have.
Still it doesn’t work like it should.

  • platform: broadlink
    host: 172.16.0.56
    mac: ‘24:df:a7:42:c6:8b’
    type: “rm_mini”
    friendly_name: “Mainroom IR”

climate:

  • platform: smartir
    name: Main AC
    unique_id: main_ac
    device_code: 1180
    controller_data: 172.16.0.56
    temperature_sensor: sensor.temperature
    humidity_sensor: sensor.humidity

The only thing I can suggest is that the IR codes don’t match, i.e. that your aircon is a slighly different model.

When you move the slider to a new temperature, your aircon will only get one code when you stop moving it, that code comprises the temperature, fan speed and mode. The air con should normally acknoweledge receipt of a valid sequence, mine beeps.

If you don’t have a card defined I am not sure how you are controlling the component? Through service calls?

Yes, through service calls

I suggest you create a suitable thermostat card, turn on the a/c using one of the mode buttons below the temperature display and then see if you can set the temperature using the circular slider.

If that doesn’t work then it’s probably time to ask some questions on the other thread.

Hi there, my AC model is not on the supported list is there an easier way to add support, or I have to manually learn all the codes?

Hi Tom

Are you able to share the automation configuration you are using?

Thanks

There’s nearly 400 lines of code to my lounge heating and cooling automations so I pastebinned it: https://paste.ubuntu.com/p/WH7wGB7ppN/

These take care of:

  • manually selecting a heating or cooling mode
  • scheduled heating and cooling on/off
  • switching off the heating/cooling if an external door or window is opened
  • manual temperature set point adjustment
  • automatically boosting/retarding the heat or cooling power as required to quickly get to the set point
  • automatic temperature set point adjustment based on season and morning weather forecast

There are also a bunch of binary sensors associated with these automations: https://paste.ubuntu.com/p/BxWXpSw3Vj/