I have an IR blaster and I’m trying to control my air conditioner with it. I want to enable the selection of mode (cooling, auto, heating), fan strength (1-5, auto), and temperature (from 18 to 30). Using input select for mode and fan strength makes sense to me, as well as a number input for temperature. Since I don’t have a smart plug and don’t know if the AC is on or off, I would use automation triggered by a button, and that automation would then run a script.
Now, the problem is with the script and how to make it simple to maintain. The issue is that there is a separate code for each of these options, and I need to somehow retrieve it.
I don’t know about that, though I wonder if it would work. Here, the remote for the AC gives a different code for the same command each time, although the code I capture consistently works.
This is what im trying to make it work:
alias: AC Control Script
description: Control AC via IR blaster with improved error handling and flexibility
variables:
mode: "{{ states('input_select.ac_mode') | lower }}"
fan_speed: "{{ states('input_select.ac_fan_speed') | lower }}"
temperature: "{{ states('input_number.ac_set_temperature') | int }}"
ir_codes:
cold:
"18":
"1": CEoM9CUCAvgFAuAEAOAHD+AfAEA3QAPgDwAH+AUCAvgFAgI=
"2": CSsM9iUBAv8FAQLgAwHgBw/gHwFAN8ADwAHADwv/BQECAQIBAgECAQI=
"3": >-
CSEMAiYMAjkGDALgAwHgAQ8DxQEMAuADAUAPwAPgAwGAEwE5BoAD4AMPAFsgG0ADCzkGxQEMasUBOQbFAQ==
"4": >-
CSYMDib/AfsF/wHgAwHgBw8F/wEzAv8B4AUB4AkRAf8BQDfAA0ABQAtAAUAHC/sF/wH/Af8B+wX/AQ==
"5": >-
CdoL9SX4ARgG+AHgAwHgBw8F+AEoAvgB4AcB4AkTQDdAA0AZQAdAAUALQAMLGAb4ARgG+AEYBvgB
auto: CUgM+SUrAgoG/gHgAwHgBw/gHwFAN0ADQAHgAwfACwcrAv4B/gH+AQ==
sequence:
- service: persistent_notification.create
data:
title: AC Control Debug - Initial Variables
message: >-
Mode: {{ mode }}, Temperature: {{ temperature }}, Fan Speed: {{
fan_speed }}
- choose:
- conditions:
- condition: template
value_template: "{{ mode == 'cold' }}"
- condition: template
value_template: "{{ temperature | int == 18 }}"
- condition: template
value_template: "{{ fan_speed in ['1', '2', '3', '4', '5', 'auto'] }}"
sequence:
- service: mqtt.publish
data:
topic: zigbee2mqtt/remote.living/set
payload: |
{"ir_code_to_send": "{{ ir_codes['cold'][18][fan_speed] }}"}
- service: persistent_notification.create
data:
title: AC Control - IR Code Sent
message: >-
Sent IR code for {{ mode }} mode, {{ temperature }}°C, Fan
Speed: {{ fan_speed }}
default:
- service: persistent_notification.create
data:
title: AC Control Error
message: >-
No matching IR code found for: Mode: {{ mode }}, Temperature: {{
temperature }}, Fan Speed: {{ fan_speed }}
mode: queued
max: 5