Ac infinity controller 67 Bluetooth temp, humidity, fan pwm

10 off - 0xa5 0x00 0x00 0x06 0x00 0x64 0x32 0xbb 0x00 0x03 0x10 0x01 0x01 0x11 0x01 0x0a
0xc9 0xf5

9 0ff - 0xa5 0x00 0x00 0x06 0x01 0x4a 0xc4 0x26 0x00 0x03 0x10 0x01 0x01 0x11 0x01 0x09
0xf9 0x96

8 off - 0xa5 0x00 0x00 0x06 0x01 0x75 0x03 0x9a 0x00 0x03 0x10 0x01 0x01 0x11 0x01 0x08
0xe9 0xb7

7 off - 0xa5 0x00 0x00 0x06 0x01 0x81 0xac 0x01 0x00 0x03 0x10 0x01 0x01 0x11 0x01 0x07
0x18 0x58

6 off - 0xa5 0x00 0x00 0x06 0x01 0x87 0xcc 0xc7 0x00 0x03 0x10 0x01 0x01 0x11 0x01 0x06
0x08 0x79

5 off - 0xa5 0x00 0x00 0x06 0x01 0x8d 0x6d 0x8d 0x00 0x03 0x10 0x01 0x01 0x11 0x01 0x05
0x38 0x1a

4 off - 0xa5 0x00 0x00 0x06 0x01 0x93 0x9e 0x72 0x00 0x03 0x10 0x01 0x01 0x11 0x01 0x04
0x28 0x3b

3 off - 0xa5 0x00 0x00 0x06 0x01 0x99 0x3f 0x38 0x00 0x03 0x10 0x01 0x01 0x11 0x01 0x03
0x58 0xdc

2 off - 0xa5 0x00 0x00 0x06 0x01 0x9f 0x5f 0xfe 0x00 0x03 0x10 0x01 0x01 0x11 0x01 0x02
0x48 0xfd

1 off - 0xa5 0x00 0x00 0x06 0x01 0xa5 0xc8 0xe7 0x00 0x03 0x10 0x01 0x01 0x11 0x01 0x01
0x78 0x9e

0 off - 0xa5 0x00 0x00 0x06 0x01 0xab 0x29 0x29 0x00 0x03 0x10 0x01 0x01 0x11 0x01 0x00
0x68 0xbf

10 off - a5000006006432bb000310010111010ac9f5
9 - a5000006014ac4260003100101110109f996
8 - a50000060175039a0003100101110108e9b7
7 - a50000060181ac0100031001011101071858
6 - a50000060187ccc700031001011101060879
5 - a5000006018d6d8d0003100101110105381a
4 - a500000601939e720003100101110104283b
3- a500000601993f38000310010111010358dc
2 - a5000006019f5ffe000310010111010248fd
1 - a500000601a5c8e70003100101110101789e
0 -a500000601ab2929000310010111010068bf
1 Like

@Samsung123 I havenā€™t quite got that far yet, but this script should help. The only line that needs changing is adding your mac address, save it, chmod +x it then run like

./scriptname.sh 0
./scriptname.sh 1
./scriptname.sh 2

etc to change the speed.

Im guessing we can just call it from a shell_command in HA and use an input variable to set the speed. I will give it a go later.

#!/bin/bash

macaddress="c9:e4:xx:xx:xx:xx"
devstring=dev_$(echo ${macaddress^^} | tr ":" _)

if [[ $1 == 0* ]]; then speed="0x00 0xaa 0x33"; fi
if [[ $1 == 1* ]]; then speed="0x01 0xba 0x12"; fi
if [[ $1 == 2* ]]; then speed="0x02 0x8a 0x71"; fi
if [[ $1 == 3* ]]; then speed="0x03 0x9a 0x50"; fi
if [[ $1 == 4* ]]; then speed="0x04 0xea 0xb7"; fi
if [[ $1 == 5* ]]; then speed="0x05 0xfa 0x96"; fi
if [[ $1 == 6* ]]; then speed="0x06 0xca 0xf5"; fi
if [[ $1 == 7* ]]; then speed="0x07 0xda 0xd4"; fi
if [[ $1 == 8* ]]; then speed="0x08 0x2b 0x3b"; fi
if [[ $1 == 9* ]]; then speed="0x09 0x3b 0x1a"; fi
if [[ $1 == 10* ]]; then speed="0x0a 0x0b 0x79"; fi

/usr/bin/expect <(cat <<'EOF'
set prompt "#"
set speed [lindex $argv 0]
set devstring [lindex $argv 1]
set address [lindex $argv 2]
spawn bluetoothctl
expect -re $prompt
send "connect $address\r"
expect "Connection successful"
send "menu gatt\r"
send "select-attribute /org/bluez/hci0/$devstring/service001b/char001e\r"
send "notify on\r"
send "select-attribute /org/bluez/hci0/$devstring/service001b/char001c\r"
send "write \"0xa5 0x00 0x00 0x06 0x00 0x67 0x02 0xd8 0x00 0x03 0x10 0x01 0x02 0x12 0x01 $speed\"\r"
send "quit\r"
expect eof
EOF
) "$speed" "$devstring" "$macaddress"

3 Likes

Riiiiiiiiiiiiiiiiiiiiiiight on thankyou! Sorry I thought everyone was doing something magical in the HA automation gui that I couldnt figure out.

So I can basically just make an automation with a threshold helper or in node red where if my SCD-41 temp is is 25c send command 5, when temp is 27c send command 6 and so on?

For example this is how Iā€™m controlling my intake fan to kick in.

I could do some kind of threshold thing where the fan incrementally increases until the input temperature target is met with 1 minute waits or something? Hmmmm ok thanks man this has got me thinking.

1 Like

Iā€™m having trouble calling the script in HA using shell_command, it seems /usr/bin/expect and /usr/lib/expect5.45.4 paths are not available in the context of the process. Will check it out again a bit later.

my rough idea was something like

shell_command:
  set_acinfinity_speed: '/config/ac.sh {{ states("input_number.acinfinity_speed") }}'

input_number:
  acinfinity_speed:
    name: acinfinity_speed
    initial: 5
    min: 0
    max: 10
    step: 1

automation:
  - alias: "run_set_acinfinity"
    trigger:
      platform: state
      entity_id: input_number.acinfinity_speed
    action:
      service: shell_command.set_acinfinity_speed

1 Like

Ok cool this changes everything!

Basically, up until now Iā€™ve only been able to control my dehumidifier/humidifier (on/off), intake fan (on/off) and exhaust ((on/off) or manually adjusting/automating in the AC infinity rubbish trash app).

Iā€™ve got to the point where I can set a leaf VPD target, measure live leaf temperature with an MLX90614, and maintain exact leaf VPD regardless of the tent VPD/environment fluctuations using the dehumidifier where tent temperature is an uncontrollable variable in the automation. This is going to be amazing now I can control exhaust to maintain a more linear Tent VPD instead of relying on kicking in the intake fan, especially remotely and ties the whole thing into HA instead of having everything in HA and then a disjointed exhaust fan. I really like the variable speed settings of AC infinity it just sucks their app is so restricted.

Thank you so much @mikeybatoz @jayrama I really really appreciate your help and work. This is going to be next level.

I am more than happy to share my automations/esphome yaml to maintain exact leaf VPD if you want them.

1 Like

Great, your use case sounds perfect. Definitely feel free to keep sharing in this thread, Iā€™m guessing things will change a bit now that there has been some progress, and maybe a native integration isnā€™t completely out of the question a little further down the track.

The script is amazing. It works instantaneously. So much better than the phone app.

1 Like

Its possible @mikeybatoz had the sleep commands in there for a reason (or maybe just debug?), but seems to work ok here even with them removed. It is ridiculously quick even using expect, I was quite surprised.

1 Like

One other thing mikey, someone pointed me at this thread for an unrelated reason - Could you redo the serial extract running the Pill on Bluetooth isteed? Ā· Issue #1 Ā· BestEnemies/pill Ā· GitHub - it has some interesting info that seemed semi related to what we are doing - mainly the work at decoding the hex pairs into int16_t values which at first glance feels very similar. I wonder if we can drag them in too for some advice, or if you might get some ideas from reviewing that postā€¦

Thanks again!

1 Like

Ooook so Iā€™ve tried to make a bunch of services for each of the settings.

image

It works amazing in terminal:

What am I messing up I donā€™t understand command line and linux etc? Cos it doesnā€™t work the way Ive tried it. Do I nee some ā€œā€ or something?

d

1 Like

im guessing this is the same problem I am running into (i can also run it fine from terminal) - when the script runs by HA it does not seem to have access to /usr/bin/expect binary (which is where it is installed to by apk add expect).

if you turn on debug logging then the error output from the script is in the homeassistant logs.

2023-01-25 14:35:08.588 DEBUG (MainThread) [homeassistant.components.shell_command] Stderr of command: `./ac.sh {{ states("input_number.acinfinity_speed") }}`, return code: 127:
b'./ac.sh: line 37: /usr/bin/expect: No such file or directory\n'

to turn on debug logging, dev tools ā†’ services

service: logger.set_level
data:
  homeassistant.components.shell_command: debug

(dont forget to set this back to error/warning later)

there is probably an easy workaround, but havenā€™t had the chance to poke at it yet. I did try dropping the expect binary and its lib file into the current dir but that did not work (the binary is found but the lib is not).

I think I have a misunderstanding about how the HA user is chrooted or how to grant deeper filesystem access to the HA container (outside of the /config folder).

1 Like

I think I messed up the config yaml.

Trying this lol

image

Edit not that was stupid cant even save config.yamlā€¦

Do you know the correct syntax to run it?

Oh it just clicked,

if you run

docker exec -it homeassistant apk add expect

then itā€™ll work, cause now expect will be installed inside the HA container.

But I think it would revert on update perhaps, unsure really - doesnā€™t seem like the right way to fix it. At the top of the script we can just check if expect is installed, and if not, apk add expect, then itā€™d still work even after the container is recreated, with just a small delay the first time while it installed the package (this may not work if the HA user does not have permission inside the container to apk add).

1 Like

image

Last time I turned of protection mode I bricked my HA instanceā€¦

Good tip, maybe take a snapshot first if you are able!

image

working for me now, I had to make a small change to the script to allow sliders to work in HA, since they set the value at 10.0 rather than 10.

if [[ $1 == 0* ]]; then speed="0x00 0xaa 0x33"; fi
if [[ $1 == 1* ]]; then speed="0x01 0xba 0x12"; fi
if [[ $1 == 2* ]]; then speed="0x02 0x8a 0x71"; fi
if [[ $1 == 3* ]]; then speed="0x03 0x9a 0x50"; fi
if [[ $1 == 4* ]]; then speed="0x04 0xea 0xb7"; fi
if [[ $1 == 5* ]]; then speed="0x05 0xfa 0x96"; fi
if [[ $1 == 6* ]]; then speed="0x06 0xca 0xf5"; fi
if [[ $1 == 7* ]]; then speed="0x07 0xda 0xd4"; fi
if [[ $1 == 8* ]]; then speed="0x08 0x2b 0x3b"; fi
if [[ $1 == 9* ]]; then speed="0x09 0x3b 0x1a"; fi
if [[ $1 == 10* ]]; then speed="0x0a 0x0b 0x79"; fi

1 Like

Oh stop it!! wowā€¦

Would you mind putting like the final working version of the script into one message?

And then also what the configuration.yaml should look like?

I get really mixed up with the replacement variable stuff Iā€™m not a coder.

Have updated that post above with my changed script.

1 Like

Thanks I just need it spelled out slightly more.

Which bit goes into configuration.yaml?

Do I need to create an automation or do I just create a slider with the templated entity? Sorry I know Iā€™m a time waster I just canā€™t quite connect the dots that you assume I would understand if you know what I mean.

As an example it took me half a day to figure out that I had to change notepad++ to unix for the script to work properly.

np, it is not easy to follow since this thread has been mostly a brain dump rather than instructions.

that post above - Ac infinity controller 67 Bluetooth temp, humidity, fan pwm - #65 by jayrama

this can go into your configuration.yaml or similar (you may need to adjust the path to your script), then you will end up a new entity after restart input_number.acinfinity_speed

in lovelace if you create an entity card for this, then when you slide it, it will trigger the automation which runs the script, and uses the value in input_number.acinfinity_speed as the value that gets sent as the argument to the script (which was just set when you moved the slider).

hope that makes sense. this is just one way it could be used, over the next few days/months Iā€™m sure we will improve on these temporary scripts!

2 Likes