#!/bin/sh
# Set heater priority: default 1 (DHW tank); 2 is Thermino as of 2025.
# Picks up credentials from ~/.netrc so may not be suitable for batch.

# Usage:
#     $0 [heater]

heater=1
if [ $# -gt 0 ]; then
    heater=$1
    shift
fi

# Check interval in minutes; default 15.
cpm=15

# Get configuration.
. script/myenergi/.config

exec curl -u "$hubsn":"$APIkey" --silent --digest --netrc -H 'accept: application/json' -H 'content-type: application/json' --compressed "https://s18.myenergi.net/cgi-set-heater-priority-E$eddisn-${heater}-${cpm}"

# Eg from default:
# % sh script/myenergi/eddiStatsAll-netrc.sh
#{"eddi":[{"deviceClass":"EDDI","sno":0,"dat":"13-01-2025","tim":"14:44:13","ectp1":0,"ectp2":69,"ectp3":1057,"ectt1":"Internal Load","ectt2":"Grid","ectt3":"Monitor","bsm":0,"bst":0,"div":0,"frq":50.07,"gen":0,"grd":121,"pha":1,"pri":1,"sta":1,"tz":0,"vol":2415,"che":0,"isVHubEnabled":false,"hpri":1,"hno":1,"ht1":"Tank 1","ht2":"Tank 2","r1a":0,"r2a":0,"rbc":0,"rbt":2,"tp1":127,"tp2":127,"batteryDischargeEnabled":false,"g100LockoutState":"NONE","cmt":254,"fwv":"3200S3.048","newAppAvailable":false,"newBootloaderAvailable":false,"productCode":"3200"}]}
# % sh script/myenergi/eddiSetHeaterPri-netrc.sh 2
#{"hpri":2,"cpm":15}[localhost:~/Env] dhd% !ti
# % sh script/myenergi/eddiStatsAll-netrc.sh
#{"eddi":[{"deviceClass":"EDDI","sno":0,"dat":"13-01-2025","tim":"15:43:43","ectp1":0,"ectp2":99,"ectp3":29,"ectt1":"Internal Load","ectt2":"Grid","ectt3":"Monitor","bsm":0,"bst":0,"div":0,"frq":49.95,"gen":0,"grd":104,"pha":1,"pri":1,"sta":1,"tz":0,"vol":2415,"che":0,"isVHubEnabled":false,"hpri":2,"hno":2,"ht1":"Tank 1","ht2":"Tank 2","r1a":0,"r2a":0,"rbc":0,"rbt":2,"tp1":127,"tp2":127,"batteryDischargeEnabled":false,"g100LockoutState":"NONE","cmt":0,"fwv":"3200S3.048","newAppAvailable":false,"newBootloaderAvailable":false,"productCode":"3200"}]}


##########
# May be used / adapted / etc without any promise of fitness for purpose
# under the terms of the Apache License Version 2.0, January 2004
#     http://www.apache.org/licenses/LICENSE-2.0
##########
