Display Oilfox Data

I really do not like to use multiple apps when there is the possibility to include all relevant stuff within the Home Assistant app. But although there already is a lot of cool stuff around here, there still are some corner use cases that apparently no one has dealt with - yet.
As my growing smart home still has a not-so-smart oil heating with thick and non-transparent oil tanks in the basement in a room where I have to climb into, I was looking for a solution to check the remaining oil level remotely. So, one day, I bought the really-good working OilFox.

It comes with an app for a smartphone and - after googling for a while - also an API which I used for this project.

Used plugins & prerequisites

With NodeRed, I update the current oil level by doing the following:

  1. Daily “Inject Timestamp” node at 22:30 as my OilFox updates the data one hour before that
  2. Exec-Node with the following curl-Request, a time limit of 5 seconds and “wait until complete execution” setting
token=`curl -d '{"email":"user@domain","password":"pwd"}' -H "Content-Type: application/json" -H "Connection: Keep-Alive" -H "User-Agent: HomeAssistant" -X POST https://api.oilfox.io/v3/login | tail -2 | head -1 | tail -c +40 | head -c 346`;curl -H "Authorization: Bearer $token" -H "Connection: Keep-Alive" -H "User-Agent: HomeAssistant" -H "Content-Type: application/json" https://api.oilfox.io/v4/summary

Note: replace the ’ before curl and after 346 with ` as this is replaced within this thread due to formatting.

  1. JSON-Node with “Convert JSON and object”, property “msg.payload” and checked box at “format JSON”

  2. Function-node with the function:
    var msg7 = {}; msg7.payload = [{"value": msg.payload.devices[0].lastMetering.value, "percentage": msg.payload.devices[0].lastMetering.fillingPercentage, "liters": msg.payload.devices[0].lastMetering.liters, "fuellhoehe": msg.payload.devices[0].lastMetering.currentOilHeight, "battery": msg.payload.devices[0].lastMetering.battery}]; return [msg7];

  3. InfluxDB Out-node with the measurement and the database you want.

  4. In Grafana, I created an “OilFox”-Dashboard with currently four different panels:


    My time range is from the first usage of the OilFox until “now”. Just type that in in the respective field in Grafana.
    1 - Fuel level
    query: SELECT "percentage" FROM "oilfox_reporting" WHERE $timeFilter
    visualization: single stat with selected “gauge”
    thresholds: 15, 30 with the colors red, yellow, green
    2 - Remaining amount of liters
    query: SELECT mean("liters") FROM "oilfox_reporting" WHERE $timeFilter GROUP BY time($__interval) fill(null)
    3 - battery level:
    query: SELECT “battery” FROM “oilfox_reporting” WHERE $timeFilter
    visualization: gauge
    4 - weekly consumption
    query: SELECT difference(mean("liters")) *-1 FROM "oilfox_reporting" WHERE $timeFilter GROUP BY time($__interval) fill(null)
    min time interval: 7d
    visualization: graph
    draw mode: bars

  5. In order to display the graphs in my Lovelace UI, you need to select the link from the “Embed” tab under “Share panel”, e.g. https://URL:PORT/d-solo/ffwvQMRgk/oilfox?tab=visualization&orgId=1&from=1537394400000&to=1552939991321&panelId=4. Strip both &from and &to parts in order to always see the latest information and add &theme=light to the URL. This should now look like this: https://URL:PORT/d-solo/ffwvQMRgk/oilfox?tab=visualization&orgId=1&panelId=4&theme=light
    Take this URL and add an Iframe card.

Also, here the NodeRed stuff to import: https://pastebin.pl/view/5f163262

That’s all :slight_smile: I hope, you can follow my ideas and use it for your own project! Feel free to give me advice how to do it different or even better :slight_smile:

Beautiful.
Thinking about getting an Oilfox myself and wanting to integrate it into hassio (btw: feature request from Andreas here: FeatureRequest: Support for OilFox).
I stopped using influxdb and grafana, since mariadb and lovelace work well enough for me. Do you think this can also be done with these built-in tools (with node-red or without)?
Has anyone done this?
Thanks and cheers.

Ah, thanks for the feedback and the link to the FeatureRequest. An official add-on / support would be awesome.
I do not see why it should not be possible to do it with mariadb. Currently, I am not really happy with my solution as you always need to login into Grafana in order to be able to watch the dashboards’ contents.

I will definitely check out mariadb. But I do not see how to get the Oilfox data without NodeRed.

Just updated the cURL request as Oilfox changed their authentication method.

Hi Sebastian,
Do you have also experience to integrate the oilfox in red node used with homematic CCU3? Thank you alpha

Hi, no I don‘t. But the First Four steps can be used exactly the same way, only the storage and the graphics needs to be adapted to Homematic.

Hi Sebastian,
nice work, I have tried to implement your solution in my homeassistant. I set up everything like it is in your description, but get an error in Node red:
“TypeError: Cannot read property ‘0’ of undefined”
Maybe you can help with this. Thanks a lot.

Hi all,
I was a bit borred of today. So I did a bit of testing

Now it works.
The issue was the cutting of the first return. So I rearranged the flow a bit.

You just need to enter your credentials in the first “Tokenabruf”

[{"id":"3079ee36.02c2d2","type":"tab","label":"Export","disabled":false,"info":""},{"id":"b6c3089d.f66b08","type":"exec","z":"3079ee36.02c2d2","command":"","addpay":true,"append":"","useSpawn":"false","timer":"10","oldrc":false,"name":"cURL","x":530,"y":480,"wires":[["5a76b930.b342e8"],[],[]]},{"id":"6061be1b.e2865","type":"inject","z":"3079ee36.02c2d2","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":480,"wires":[["a211bae9.c4bc88"]]},{"id":"a211bae9.c4bc88","type":"change","z":"3079ee36.02c2d2","name":"Befehl: Tokenabruf ","rules":[{"t":"set","p":"payload","pt":"msg","to":"curl -d '{\"email\":\"XXXX\",\"password\":\"XXXX\"}' -H \"Content-Type: application/json\" -H \"Connection: Keep-Alive\" -H \"User-Agent: HomeAssistant\" -X POST https://api.oilfox.io/v3/login ","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":480,"wires":[["b6c3089d.f66b08"]]},{"id":"5a76b930.b342e8","type":"json","z":"3079ee36.02c2d2","name":"parsing","property":"payload","action":"","pretty":true,"x":680,"y":480,"wires":[["cf9e78e7.aec908","7dd998ea.76e2c8"]]},{"id":"cf9e78e7.aec908","type":"change","z":"3079ee36.02c2d2","name":"Befehl: Datenabruf","rules":[{"t":"set","p":"payload","pt":"msg","to":"curl -H \"Content-Type: application/json\" -H \"Authorization: Bearer TOKEN\"  -X GET https://api.oilfox.io/v3/user/summary","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":910,"y":480,"wires":[["23bc6c15.c79bc4"]]},{"id":"23bc6c15.c79bc4","type":"change","z":"3079ee36.02c2d2","name":"fĂŒge Token ein","rules":[{"t":"change","p":"payload","pt":"msg","from":"TOKEN","fromt":"str","to":"Oilfox.Token","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":1140,"y":480,"wires":[["f5680855.4a1b38"]]},{"id":"fc4bca20.d705c8","type":"debug","z":"3079ee36.02c2d2","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1670,"y":480,"wires":[]},{"id":"f5680855.4a1b38","type":"exec","z":"3079ee36.02c2d2","command":"","addpay":true,"append":"","useSpawn":"false","timer":"10","oldrc":false,"name":"cURL","x":1310,"y":480,"wires":[["dbc9c6a7.145ae8"],[],[]]},{"id":"7dd998ea.76e2c8","type":"change","z":"3079ee36.02c2d2","name":"Speichere Token","rules":[{"t":"set","p":"Oilfox.Token","pt":"flow","to":"payload.access_token","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":910,"y":420,"wires":[[]]},{"id":"dbc9c6a7.145ae8","type":"json","z":"3079ee36.02c2d2","name":"parsing","property":"payload","action":"","pretty":true,"x":1480,"y":480,"wires":[["fc4bca20.d705c8"]]}]

Hi, this looks nice, I have imported it but don’t see any new value in my InfluxDB or somewhere else. When I run debug mode then I see all the data and everything is correct.
The Workflow runs without any issue, but I don’t know where I will find the values getting from the Oilfox App.
Maybe you can help with this.
Thanks

Is it possible to integrate withouth NodeRed? Like some custom component for start?

Haven’t heard about that yet, but to install NodeRed is not really difficult, I would be happy to find out how to extract the data I get via NodeRed from msg.payload to my influxdb.

Why not to extract or better to show data from NodeRed to Lovelace?

yes but do you know how??

When I will manage wherento get OilFox 2 WLAN and will have it I will dig into it

I knoe that my friend present data from NodeRed to Lovelace - so I will dig into it

But firstly need to find out where I can buy OilFox
 I just can not find any web site where I can buy it


I only can provide a link where you can buy in Austria, I guess that is a bit too complicated for you.
So if your friend extracts data directly from Oilfox to Lovelace I would be interested on how he did it. Maybe you can ask him or he can publish here in the forum. I guess many people would be interested.

Please give me link
 If they ship to Slovenia I will buy it


Regarding NodeRed and Lovelace
 it’s not so simple - every NodeRed project is customized - but we will solve this
 I’m sure


here is the link where I bought mine:


if they don’t ship to Slovenia then I could help you with this since I live in Austria

Yea
 I will send them e-mail
 3 months ago this would not be a problem
 now is
 I have 1 hour of driving to Klagenfurt and I see that they have store there
 but now - we know that it’s a little problem :wink:
If they do not ship to Slovenia and if I could pay you via PayPal then we can of course agree
 in other way I will simply wait until border is not opened again


whatever option you choose, usually I drive at least once a month from Graz to Rovinj, so I pass through Slovenija of course, now the situation is a bit difficult. But if you want I can ship it to you if you order and let them send to my address. Whatever you prefer, or just wait until situation is better, then I could even drop it off somewhere in Slovenija.

Great to know
 we will wait so that we will see what they will response and after that we will know

Maybe the situation will make us to go to a home assistant coffie :wink: