Query API sometimes returns null values in data

I’m using the query API function in a Hubitat driver. The query I was using is below:

http://iotawatt.local/query?select=[L1_Vrms.Volts.d0,L1_Main.Watts.d1,L2_Main.Watts.d1,GarageOT_2.Watts.d1,Dryer_5_7.Watts.d1,AC_Cond_6_8.Watts.d1,Oven_10_12.Watts.d1,AirHandler_15.Watts.d1,Washer_20.Watts.d1,Dishwasher_23.Watts.d1,PcRm_KitLT_24.Watts.d1,KitIsCntrOT_25.Watts.d1,Mcrwv_Rng_33.Watts.d1,Fridge_36.Watts.d1,MBdrmLT_OT_40.Watts.d1,I_L1.Amps.d3,I_L2.Amps.d3,L1_Misc.Watts.d1,L2_Misc.Watts.d1,]&begin=s-5s&end=s&group=5s&format=json&header=yes

The driver was making queries every 30 seconds. I occasionally would see all null values in the response like this:

[range:[1591027160, 1591027165], labels:[L1_Vrms, L1_Main, L2_Main, GarageOT_2, Dryer_5_7, AC_Cond_6_8, Oven_10_12, AirHandler_15, Washer_20, Dishwasher_23, PcRm_KitLT_24, KitIsCntrOT_25, Mcrwv_Rng_33, Fridge_36, MBdrmLT_OT_40, I_L1, I_L2, L1_Misc, L2_Misc], data:[[null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null]]]

It wouldn’t happen very often, maybe once an hour or so. Since I was asking for the most recent 5 seconds of data, it would appear that if the query was made at just the right time, the requested data wouldn’t be available. I put the query in my browser, just to make sure it wasn’t something to do with the Hubitat driver, and I still got the null responses occasionally.

When I asked for the previous 5 seconds of data by changing the last part of my query to the following:

&begin=s-10s&end=s-5s&group=5s&format=json&header=yes

I never got any null values. That works fine for me. Just thought I’d document this behavior in case someone else is also seeing it. I’ve been using my IoTaWatt for over a year now and it works great!

Hi @bdh79,

I’ll look into that. It probably has to do with the query beating out the posting to the datalog.

If you have the opportunity to use grafana with influxDB, you will see that there is a parameter to delay the query - essentially what you are doing with your solution, so it’s not a unique problem when dealing with pulling real-time data.

Without getting into a lot of the technical details, I think the ESP32 version that I am working on will not have this problem.

Thanks for documenting this.