Skip to content

Instantly share code, notes, and snippets.

@aarmot
Last active August 17, 2023 12:55
Show Gist options
  • Save aarmot/f289deac867133c07047292cbf0a3ac8 to your computer and use it in GitHub Desktop.
Save aarmot/f289deac867133c07047292cbf0a3ac8 to your computer and use it in GitHub Desktop.
Generate Gree heatpump IR codes to be used in LIRC
#!/bin/bash
# Generate Gree heat pump IR codes, according to
# https://forum.mysensors.org/uploads/files/1469565493670-gree.pdf
# How to use raw codes in LIRC see e.g.
# https://github.com/suikammd/AirConditioner-Homekit/
MSG_SPACE=20000
HDR_MARK=9000
HDR_SPACE=4500
BIT_MARK=550
ZERO_SPACE=550
ONE_SPACE=1660
BIT0="$BIT_MARK $ZERO_SPACE"
BIT1="$BIT_MARK $ONE_SPACE"
CODE_COOL=1
CODE_HEAT=4
CODE_POWER=8
err() { echo "$@"; exit 1; }
print_bits() {
local bb=$1 cc=$2
while ((cc-- > 0)); do
(( (bb & 1) > 0)) && printf "$BIT1 " || printf "$BIT0 "
((bb >>= 1))
done
}
[[ -z "$2" ]] && err "Please provide temp (16..30) and fan speed (0..3)"
temp=$1
fan=$2
# Remove CODE_POWER to get OFF code
# Replace CODE_COOL with CODE_HEAT to get heating codes
d0=$(( CODE_POWER + CODE_COOL + ( (fan & 3) << 4 ) ))
d1=$(( (temp - 16) & 15 ))
d2=0
d3=80
d4=2
d5=0
d6=32
d7=0
d8=$(( ( ( (d0 + d1 + d2 + d3) << 4 ) + d5 + d6 + d7 + 160 ) & 240 ))
printf "$HDR_MARK $HDR_SPACE "
print_bits $d0 8
print_bits $d1 8
print_bits $d2 8
print_bits $d3 8
print_bits $d4 3
printf "$BIT_MARK $MSG_SPACE "
print_bits $d5 8
print_bits $d6 8
print_bits $d7 8
print_bits $d8 8
printf "${BIT_MARK}\n"
### END ###
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment