Script to automate control of an home reverse cycle aircon system based on custom logic and temperature measurements.
Go to file
Rob Pearce 7a5452ddfa Add -W option to check availablity of devices rather than 'people' (since a person can have multiple devices associated)
Delete ARP entries before availability check.
2022-02-02 14:09:02 +11:00
README.md better config file parsing 2021-12-04 20:24:25 +11:00
aircon.sh Add -W option to check availablity of devices rather than 'people' (since a person can have multiple devices associated) 2022-02-02 14:09:02 +11:00

README.md

Overview

aircon.sh in action

Script to automate control of an home reverse cycle aircon system based on custom logic and temperature measurements.

This was originally written for an AdvantageAir system. It just calls an external script to interface with the aircon, so should be easily adaptable to other systems.

It can also log to an influxdb database for easy integration into Grafana or similar.

grafana integration

Requirements

Features

  • Log temperature measurements to a CSV file or InfluxDB
  • Control zone temperature by opening/closing its vents
  • Control zone temperature by opening/closing vents in adjacent zones
  • Automatically adjust aircon settings based on defined temperature thresholds
  • Turn zones on/off based on ARP table entries for specific MAC addresses (for example, if a TV is turned on or a person's phone is detected)
  • Define temperature rules based on weekday and/or time

Usage

root@gridbug:~# scripts/aircon.sh  -h
usage:  scripts/aircon.sh [options]

    Modifies aircon based on configured parameters in /root/.airconrc.

    -h          Show this text.
    -c          Cron mode.  Only show output if actions were taken.
    -i x.x.x.x  Specify IP address for aircon (default is 10.99.99.1)
    -I db       Log all zone temperatures to given influxdb database, then exit (see -o).
    -A db       Log actions to given influxdb database.
    -f file     Specify an alternate config file.
    -k file     If file exists, never change aircon settings (default: /root/.aircon_noaction).
    -l num      Set number of too hot/cold zones at which to taking action.
    -L          Log all zone temperatures to CSV file, then exit (see -o).
    -o file     Specify CSV output file.  Default:  /root/acstats.csv
    -m          Generate a config file based on current aircon setup.
    -p          Profiler mode.
    -w          List which zone owners' devices are available then exit.
    -t num      Specify degrees below min temperature before taking action.
    -T num      Specify degrees above max temperature before taking action.
    -y          Actually run commands/db inserts.  By default, commands are just displayed.

Examples

Sample .airconrc file

root@gridbug:~# cat .airconrc

options -t 0.5

modelock heat

constant Family

owner Study robsphone
owner Rob&Beth robsphone bethsphone
owner Brendan brendansphone
owner Media lgtv_wifi

@Thu-Fri;0830-1630 force Nursery close   # Childcare hours
@1830-0630 temp Nursery 17-19


@0600-2359 temp Family 18-21
temp Media 18-22
temp Rob&Beth 18-22
@Mon-Fri;0830-1730 temp Study 18-22 # Rob working
@Sat-Sun ignore Study               # Not working

adj Brendan Family
adj Media Brendan
adj Rob&Beth Family
adj Study Family

person Rob robsphone
person Beth bethsphone
person Mel melsphone
person Brendan brendansphone

Generate ~/.airconrc based on your a tual aircon zones

bash$ aircon.sh -m

Log temperature for each zone to csv then exit

bash$ aircon.sh -L -o /root/acstats.csv -x /usr/local/bin/pymyair -f /root/.airconrc

Preview influxdb inserts for zone temperatures

bash$ aircon.sh -I myinfluxdb
/usr/local/bin/influx -database myinfluxdb -execute INSERT temperature,room=Family value=18.7
/usr/local/bin/influx -database myinfluxdb -execute INSERT temperature,room=Brendan value=19.1
/usr/local/bin/influx -database myinfluxdb -execute INSERT temperature,room=Media value=21
/usr/local/bin/influx -database myinfluxdb -execute INSERT temperature,room=Rob&Beth value=18.4
/usr/local/bin/influx -database myinfluxdb -execute INSERT temperature,room=Study value=19.2
/usr/local/bin/influx -database myinfluxdb -execute INSERT temperature,room=Nursery value=17.8
/usr/local/bin/influx -database myinfluxdb -execute INSERT attendance,person=Rob value=1
/usr/local/bin/influx -database myinfluxdb -execute INSERT attendance,person=Beth value=1
/usr/local/bin/influx -database myinfluxdb -execute INSERT aircon running=0
/usr/local/bin/influx -database myinfluxdb -execute INSERT aircon mode=0

Log temperature for each zone to local influxdb then exit

bash$ aircon.sh -I myinfluxdb -y

Determine required aircon changes and display them only (dry run)

bash$ aircon.sh
Aircon mode:    heat (locked to heat)
Current myzone: Family (zone 1)
Tolerance: 0.5 degrees low, 0 degrees high
                Valid          Set    Actual Proposed
Zone            Temp   State   Temp   Temp   Action
Family (C)      18-21  open    19     21.6   close_vent
Brendan         n/a    close   19     19.3   n/a
Media           18-22  close   20     21.6   n/a
Rob&Beth        18-22  close   18     19.5   n/a
Study           n/a    close   19     20.6   n/a
Mel&Rob         18-21  close   18     19.5   n/a
Nursery         17-19  open    19     18.9   set_myzone

Analysis:
- Family is too hot (constant zone)

Proposed commands:
myair 10.99.99.1 set --zone 1 --state off --temp 19    # In zone Family, close vent
myair 10.99.99.1 myzone --zone 7                       # Set MyZone to Nursery

Make required aircon changes

bash$ aircon.sh -y
Aircon mode:    heat (locked to heat)
Current myzone: Family (zone 1)
Tolerance: 0.5 degrees low, 0 degrees high
                Valid          Set    Actual Proposed
Zone            Temp   State   Temp   Temp   Action
Family (C)      18-21  open    19     21.6   close_vent
Brendan         n/a    close   19     19.3   n/a
Media           18-22  close   20     21.6   n/a
Rob&Beth        18-22  close   18     19.5   n/a
Study           n/a    close   19     20.6   n/a
Mel&Rob         18-21  close   18     19.5   n/a
Nursery         17-19  open    19     18.9   set_myzone

Analysis:
- Family is too hot (constant zone)

Proposed commands:
myair 10.99.99.1 set --zone 1 --state off --temp 19    # In zone Family, close vent
myair 10.99.99.1 myzone --zone 7                       # Set MyZone to Nursery

Running action: In zone Family, close vent
RUNNING myair 10.99.99.1 set --zone 1 --state off --temp 19
Running action: Set MyZone to Nursery
RUNNING myair 10.99.99.1 myzone --zone 7

Make required aircon changes and log actions to influxdb

bash$ aircon.sh -y -A myinfluxdb

Make required aircon changes and only produce output if actions taken (cron mdoe)

bash$ aircon.sh -y -c

Show which owners are detected, then exit

bash$ aircon.sh -w
Person    Availability
Rob       At home
Beth      At home
Mel       Out of the house
Brendan   At home