HTTP binding cache and ignore response value

I am using the HTTP binding to control my CT50 thermostat. I am using caching since the status returns a handful of values and the thermostat’s webserver is not that great and times out and hangs sometimes. A valid response looks like:
{“temp”:74.50,“tmode”:3,“fmode”:2,“override”:0,“hold”:0,“tstate”:2,“fstate”:1,“time”:{“day”:2,“hour”:13,“minute”:21},“t_type_post”:0}

An invalid response looks like:
{“error”:-1}

A valid response with incorrect data looks like:
{“temp”:-1,“tmode”:-1,“fmode”:-1,“override”:-1,“hold”:-1,“tstate”:-1,“fstate”:-1,“time”:{“day”:2,“hour”:13,“minute”:21},“t_type_post”:0}

I am persisting these into mysql and graphing the temp, however the -1 values throughs the graph off like crazy.

So my question is, is there a way to ignore the -1 value and not persist it?

Several approaches come to mind.

  • A JavaScript transform that extracts the value and converts the -1’s to 0s (or some other more “sane” value)
  • A proxy Item and a Rule; your current Item gets updates, triggers a rule which only postUpdates the proxy Item when the value isn’t -1; make sure to use the proxy Item for your chart
  • Don’t automatically persist the Item and instead have a rule that triggers when the Item is updated and call MyItem.persist only if the value isn’t -1 (if mysql isn’t your default persistence the call would be MyItem.persist(“mysql”))
1 Like

I went ahead and wrote a few line bash script to just look through all the tables and delete the ones that had a -1 value.