cometblue icon indicating copy to clipboard operation
cometblue copied to clipboard

Reading values changes them!

Open Benjalien opened this issue 5 years ago • 4 comments

Hi, I'd like to use this nice piece of code to read the temperatures from my house and see if my setting are good (if my house is cooling down when I leave and warming up again before I come back. I have more foreseen, but one step at a time. Here's my issue: I did setup a script that "calls" all me devices every 15 minutes and fills a DB with the values. Every time I activate this I have about 50% of my devices loosing their config over a single day. Typically one value is missing: I have 2 open/close cycles and when I open the iOS app, I can only see 3 values instead of 4. Did anyone experience this? I was thinking about using only the "backup" command and then splitting the JSON inside my script, but I'm afraid I'll just invest a few hours to come to the same result :(

Hereby my script just in case someone would like to do something similar:

`#!/bin/bash

#read the devices from the DB

declare -A myDevices deviceCount=0 # I have to keep track of it as my 2D array is simulated and Bash can't really loop them itself declare -A myMeasures

while read device do devices+=("$device") done < <(mysql -u CometBlue -pCometBluePass -D CometBlue --host localhost -BN -e "select id , '|', MAC, '|', PIN, '|', Name , '|', description from devices;")

#read the array of devices and split the lines to get the details into a bigger 2D table

for device in "${devices[@]}" do #echo "Device: " $device ((deviceCount++)) IFS='|' read -r -a array <<< "$device" #trimming the whitespaces... should probably be done at "read" part rather than here :( trimmed_ID=$(echo ${array[0]} | xargs) myDevices[$trimmed_ID, MAC]=$(echo ${array[1]} | xargs) myDevices[$trimmed_ID, PIN]=${array[2]} myDevices[$trimmed_ID, Name]=${array[3]} myDevices[$trimmed_ID, Description]=${array[4]} done

#read the data from the CometBlues for ((cptr=1; cptr<=$deviceCount; cptr++)) do myMeasures[$cptr, MAC]=${myDevices[$cptr, MAC]} echo ============================================================ echo $cptr - ${myDevices[$cptr, Description]} - ${myDevices[$cptr, MAC]} echo ============================================================

counter=0
temperatures=""
until [ "$temperatures" ]
do
	((counter++))
	echo "Temperatures, try "$counter
	temperatures=$(cometblue device -p ${myDevices[$cptr, PIN]} ${myDevices[$cptr, MAC]} get temperatures 2>/dev/null)
	if [ $counter -ge 5 ]
		then break
	fi
	
done


#echo "temperatures " $temperatures
myMeasures[$cptr, t_current]=$(echo $temperatures | awk '{print ($3)}')
myMeasures[$cptr, t_manual_mode]=$(echo $temperatures | awk '{print ($9)}')
myMeasures[$cptr, t_target_low]=$(echo $temperatures | awk '{print ($14)}')
myMeasures[$cptr, t_target_high]=$(echo $temperatures | awk '{print ($19)}')
myMeasures[$cptr, t_offset]=$(echo $temperatures | awk '{print ($23)}')
myMeasures[$cptr, W_open_detection]=$(echo $temperatures | awk '{print ($28)}')
myMeasures[$cptr, W_open_minutes]=$(echo $temperatures | awk '{print ($32)}')


counter=0
until [ "${myMeasures[$cptr, Battery]}" ]
do
	((counter++))
	echo "Battery, try "$counter
	myMeasures[$cptr, Battery]=$(cometblue device -p ${myDevices[$cptr, PIN]} ${myDevices[$cptr, MAC]} get battery 2>/dev/null)
	if [ $counter -ge 5 ]
		then break
	fi
done
#remove the % sign
myMeasures[$cptr, Battery]=${myMeasures[$cptr, Battery]//%}



echo "Battery: "${myMeasures[$cptr, Battery]}"%"
echo "T_current: "${myMeasures[$cptr, t_current]}"°C"
echo "T_manual: "${myMeasures[$cptr, t_manual_mode]}"°C"
echo "T_target_low: "${myMeasures[$cptr, t_target_low]}"°C"
echo "T_target_high: "${myMeasures[$cptr, t_target_high]}"°C"
echo "T_offset: "${myMeasures[$cptr, t_offset]}"°C"
echo "W_open_detection: "${myMeasures[$cptr, W_open_detection]}
echo "W_open_miuntes: "${myMeasures[$cptr, W_open_minutes]}" minutes"
SQLInsert="insert into measures (device, t_current, t_manual_mode,  t_target_low, t_target_high, t_offset, W_open_detection, W_open_minutes, Battery) values ((SELECT id from devices WHERE MAC='${myMeasures[$cptr, MAC]}'), '${myMeasures[$cptr, t_current]}', '${myMeasures[$cptr, t_manual_mode]}', '${myMeasures[$cptr, t_target_low]}', '${myMeasures[$cptr, t_target_high]}', '${myMeasures[$cptr, t_offset]}', '${myMeasures[$cptr, W_open_detection]}', '${myMeasures[$cptr, W_open_minutes]}', '${myMeasures[$cptr, Battery]}');"
mysql -u CometBlue -pCometBluePass -D CometBlue --host localhost -BN -e "$SQLInsert"
if [ $? -eq 0 ];then
	echo -ne ""
else
	echo "SQL insert failed: "$SQLInsert
fi

done `

If someone wants the SQL creation script, just ask :)

BR Benja

Benjalien avatar Nov 21 '18 20:11 Benjalien

No idea? :)

Benjalien avatar Jul 16 '19 20:07 Benjalien

I have a good news for you: it's a firmware bug: I adapted my scripts to base them on torsten traenkner's expect scripts and I have the same bug. So good news for you, but worst case for me: what I want to do seems impossible :(

Benjalien avatar Nov 06 '19 21:11 Benjalien

@Benjalien what device/firmware version do you have exactly? I wanted to do just the same as you but after reading your issue I remembered that even with the official app I had the impression that I lost the config some times , but always assumed it was some connection issue...

Also, did you just try writing the whole config after reading? You probably don't change it manually often and it would be easy to detect the default config...

Hades32 avatar Feb 23 '20 17:02 Hades32

Martin,

    I have them all on "COBL0126 - 0.0.6-sygonix1". Meanwhile I got myself a Xavax version to test/compare but I didn't had the time to do so yet.

    Pushing a complete backup after every call is indeed my very last plan if nothing else works... but how would it work if my wife comes home earlier and manually changes the setting? The heating would turn off after 15 minutes max...

Keep me posted please, and good luck!

On 23/02/2020 18:17, Martin Rauscher wrote:

@Benjalien https://github.com/Benjalien what device/firmware version do you have exactly? I wanted to do just the same as you but after reading your issue I remembered that even with the official app I had the impression that I lost the config some times , but always assumed it was some connection issue...

Also, did you just try writing the whole config after reading? You probably don't change it manually often and it would be easy to detect the default config...

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/im-0/cometblue/issues/11?email_source=notifications&email_token=AKN4NUIJUTEVI3QMRPJZMLTREKVTJA5CNFSM4GFXLEOKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEMWBTWY#issuecomment-590092763, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKN4NUNTQE63TBW3JGE3XYLREKVTJANCNFSM4GFXLEOA.

Benjalien avatar Mar 01 '20 20:03 Benjalien