cometblue icon indicating copy to clipboard operation
cometblue copied to clipboard

Reading values breaks the config

Open Benjalien opened this issue 5 years ago • 5 comments

Hi, I'm working on a project to monitor my temperatures using the comet blue devices. All is OK so far, I have a ll my scripts and get a Cacti/RRDtool graph. Here's my issue: I call all my devices ervery 15 minutes to get a backup (and I extract the info from there in bash). Doing this I notice that my devices have screwed up schedules. Looking closer there are 2 scenario: one of the steps is missing and so my devices are ending up closing when they should open - a timing over 24 appears (so the devices should open/close at 37:20...)

Could this be fixed? Can I help with the debug? (the same happens when you read a measure rather than taking a backup, this is why I moved to backup at first place) BR Benjamin

Benjalien avatar Apr 12 '19 13:04 Benjalien

Hi, can you please elaborate a bit more on how you use the tools? Perhaps provide your scripts reading the devices?

xrucka avatar Apr 13 '19 09:04 xrucka

First of all, thanks for your time. Here's the line I execute every 15 minutes on all my CometBlues: temperatures=$(/usr/local/bin/cometblue device -p ${myDevices[$cptr, PIN]} ${myDevices[$cptr, MAC]} backup) It's part of a far bigger script (I'll post it at the bottom), but the rest is mostly related on getting/putting stuff in my DB (and a lot of commented stuff from previous tries).

I checked again today and it seems like

  1. the devices jump to "4 timings a day" even if I don't use it (not so bad)
  2. they loose one of the values: Thursday: Start 1 @ 5:30 (OK) End 1 @ 7:30 (OK) Start 2 @17:00 (OK) End 4 @ 5:30 (should be start 1 for next day) Friday: Start 1 @ 7:30 (should be stop 1) End 1 @ 17:00 (should be start 2) Start 2 @ 22:00 (should be stop 2) Start 4 @7:00 (???) Stop 4 @ 21:00 (???) And saturday is my favourite: Start 1 @ OFF End 1 @ 37:20 :) (I have screenshots...)

Herby my complete script: (I removed the code tag as it's messy, sorry ) #!/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 user -p password -D database --host localhost -BN -e "select id , '|', MAC, '|', PIN, '|', Name , '|', description from CometBlueDevices;")

#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 "Backup, try "$counter
	#temperatures=$(cometblue device -p ${myDevices[$cptr, PIN]} ${myDevices[$cptr, MAC]} get temperatures 2>/dev/null)
	#temperatures=$(cometblue device -p ${myDevices[$cptr, PIN]} ${myDevices[$cptr, MAC]} get temperatures)
	temperatures=$(/usr/local/bin/cometblue device -p ${myDevices[$cptr, PIN]} ${myDevices[$cptr, MAC]} backup)
	if [ $counter -ge 2 ]
		then break
	fi
	
done


#echo "temperatures " $temperatures
myMeasures[$cptr, t_current]=$(echo $temperatures | jq -r '.temperatures.current_temp')
myMeasures[$cptr, t_manual_mode]=$(echo $temperatures | jq -r '.temperatures.manual_temp')
myMeasures[$cptr, t_target_low]=$(echo $temperatures | jq -r '.temperatures.target_temp_l')
myMeasures[$cptr, t_target_high]=$(echo $temperatures | jq -r '.temperatures.target_temp_h')
myMeasures[$cptr, t_offset]=$(echo $temperatures | jq -r '.temperatures.offset_temp')
myMeasures[$cptr, W_open_detection]=$(echo $temperatures | jq -r '.temperatures.window_open_detection')
myMeasures[$cptr, W_open_minutes]=$(echo $temperatures | jq -r '.temperatures.window_open_minutes')
myMeasures[$cptr, Battery]=$(echo $temperatures | jq -r '.status.low_battery')

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)

myMeasures[$cptr, Battery]=$(cometblue device -p ${myDevices[$cptr, PIN]} ${myDevices[$cptr, MAC]} get battery)

if [ $counter -ge 5 ]

then break

fi

done

#remove the % sign

myMeasures[$cptr, Battery]=${myMeasures[$cptr, Battery]//%}

echo "Battery_Low: "${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 CometBlueMeasures (device, t_current, t_manual_mode,  t_target_low, t_target_high, t_offset, W_open_detection, W_open_minutes, Battery_Low) values ((SELECT id from CometBlueDevices 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 user -p password -D database --host localhost -BN -e "$SQLInsert"
if [ $? -eq 0 ];then
	echo -ne ""
else
	echo "SQL insert failed: "$SQLInsert
fi

done

I guess (but it's really only a guess) that it's happening rarely, but as I'm calling my devices every 15 minutes I have those issues almost daily :(

Just as an info, the "original" im-0/cometblue also has that issue (but never answered me...)

BR Benjamin

image image image

Benjalien avatar Apr 14 '19 19:04 Benjalien

No idea? :)

Benjalien avatar Jul 16 '19 20:07 Benjalien

Hi there, autumn is there so I start working on this again. Did you had a chance to look at it by any chance? Thanks!

Benjalien avatar Oct 10 '19 10:10 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