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:
- Daily “Inject Timestamp” node at 22:30 as my OilFox updates the data one hour before that
- 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.
-
JSON-Node with “Convert JSON and object”, property “msg.payload” and checked box at “format JSON”
-
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];
-
InfluxDB Out-node with the measurement and the database you want.
-
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 -
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 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