bosch-thermostat / bosch-thermostat-client-python

Python3 asyncio package to talk to Bosch thermostat devices.
Apache License 2.0
23 stars 20 forks source link

Support for energy monitoring recordings? #13

Closed philippreissing closed 3 years ago

philippreissing commented 3 years ago

Hi,

I'm having a Bosch Compress 7400 heat pump and I'm keen on getting data on its energy consumption into home assistant. While I'm able to read some sensors such as outdoor temperaturs and supply temperatures, I'm not able to get consumption data. /heatSources/total/energyMonitoring/consumedEnergy just gives a 403 error.

While trying some things, I noticed that my device supports some end points that provide consumption data history. Those are apparently used by the app to show some nice, but limited graphs:

It seems they require a GET parameter for the day and then return something like this:

GET /recordings/heatSources/total/energyMonitoring/consumedEnergy?interval=2021-01-15
{
   "id":"/recordings/heatSources/total/energyMonitoring/consumedEnergy?interval=2021-01-15",
   "type":"yRecording",
   "writeable":0,
   "recordable":0,
   "recordedResource":{
      "id":"/heatSources/total/energyMonitoring/consumedEnergy",
      "uri":"http://xxx/heatSources/total/energyMonitoring/consumedEnergy"
   },
   "interval":"2021-01-15",
   "sampleRate":"P1H",
   "recording-type":"actual",
   "recording":[
      {
         "y":120,
         "c":60
      },
      {
         "y":60,
         "c":60
      },
      {
         "y":120,
         "c":60
      },
      {
         "y":120,
         "c":60
      },
      {
         "y":60,
         "c":60
      },
      {
         "y":60,
         "c":60
      },
      {
         "y":120,
         "c":60
      },
      {
         "y":60,
         "c":60
      },
      {
         "y":60,
         "c":60
      },
      {
         "y":60,
         "c":59
      },
      {
         "y":1,
         "c":0
      },
      {
         "y":1,
         "c":0
      },
      {
         "y":1,
         "c":0
      },
      {
         "y":1,
         "c":0
      },
      {
         "y":1,
         "c":0
      },
      {
         "y":1,
         "c":0
      },
      {
         "y":1,
         "c":0
      },
      {
         "y":1,
         "c":0
      },
      {
         "y":1,
         "c":0
      },
      {
         "y":1,
         "c":0
      },
      {
         "y":1,
         "c":0
      },
      {
         "y":1,
         "c":0
      },
      {
         "y":1,
         "c":0
      },
      {
         "y":1,
         "c":0
      }
   ]
}

There seems to be one record for each hour of the day and you have to divide y by c to get to the figure that is shown in the Easy Remote app.

I was now thinking to work on a new sensor that reads this data and provides it as a figure for the current day. This could then be used by home assistant to show in dashboards and record the history day by day. So it would always query /recordings/heatSources/total/energyMonitoring/consumedEnergy?interval=<current day> as sensor "Daily energy consumption".

Is that something that would be interesting for the project? If yes, I would be happy to give it a try. If you even have some pointers where to start, that would be much appreciated of course :-)

Best, Philip

pszafer commented 3 years ago

I'm in progress of creating sensor with query params already. Unfortunately my Bosch don't accept query params, at least I coulnd't get any answer. I'd try again on Monday.

Do you know if there is anyway to tell which URI needs query param and which doesn't. Why am I asking? because to work on it I need bosch scan, which I use to run bosch simulator, unfortunately I don't know how to automate on which URI try to send query param. Can you provide bosch scan anyway, so I can see how does it look? Is it for Home Assistant?

philippreissing commented 3 years ago

Good news that you're already working on it. In any case, let me know if there's anything I can help with. I have a programming background - haven't been much into Python yet, but I think I could manage.

I have attached my bosch_scan.json. I actually have no idea which ones take parameters or not. I first found this endpoint when looking at decompiled version of the Bosch Remote Android app. And I only discovered the interval parameter when googling the URL and saw that somebody posted it in a forum. What I also tried this week is recording the traffic between the app and my bosch device. Thereby I could check if there's any other end points that use parameters if you think that's useful.

What I also found by trial and error is that the interval parameter for the recordings can be filled as YYYY-MM-DD to get one record for each hour in that day, YYYY-MM to get one record for each day, YYYY to get one record for each month.

And yes, ultimately I would like this data to show up in home assistant. That's the whole goal of this exercise :) bosch_scan.zip

pszafer commented 3 years ago

Hi @philippreissing I think I make one step further. Install new lib version v0.10.2.

bosch_cli scan --host HOST --token TOKEN --password PW --protocol PROTO --device IVT|NEFIT -s RECORDINGS

it will create json file with small scan of just all recording with 3 intervals which might be useful for HA:

YYYY-MM-DD
YYYY-MM
YYYY-WEEKNUMBER

This is scan for my device: https://jsonblob.com/8f88d50e-7853-11eb-a2d3-5d3769fcf727

The problem is that HA sensors wants to have current data and it can create historical data on its own. My only idea is to fetch last hour historical data, but then all this data will be shifted one hour...

pszafer commented 3 years ago

HA component has recording sensors with latest lib.

christian-ek commented 1 year ago

What are really the Y and C values in the recordings? Trying to figure this stuff out @pszafer

pszafer commented 1 year ago

C is sample size withing time range (eg 1 hour) and Y is sum of all this measurement. So you have divide Y/C to get avg of last hour recordings.