Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Old version:
- 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
Add Comment
Please, Sign In to add comment