I haven’t done anything for any stats, but as i store all the oilpal data in mariadb it shouldn’t be hard to pull 30 days worth of data, average that to get a daily usage amount and then divide the current tanks volume by the daily used value to get a rough days left.
But as you say there’s a few factors that could mess with that, a fill or a leak.
I’m going to assume you’re running Influx, if so, the following should expose 2 new sensors that will give you a 30 day average usage and days left.
In your configuration.yaml (or sensors.yaml) add the following under sensor:/platform: influxdb
(you won’t need the queries: line if it’s already there)
queries:
- name: OilPalData 1 Hour Ago
unit_of_measurement: Litres
value_template: '{{ value | round(0) }}'
group_function: last
where: '"entity_id" = ''oilpaldata'' and time < now() - 1h'
measurement: '"Litres"'
field: value
database: homeassistant
- name: OilPalData 30 Days Ago
unit_of_measurement: Litres
group_function: mean
where: '"entity_id" = ''oilpaldata'' and time < now() - 30d'
measurement: '"Litres"'
field: value
database: homeassistant
value_template: '{{ value | round(0) }}'
under sensor:/platform: template add the following
(you probably won’t need the sensors: line as it should already be there)
While you’re at it, you may also want to edit the following, as I’ve added a quicker update to the original script to update the oilpal value from influx if there has been no reading from the modem. The value is taken from the previous hour reading.
Wow. Thanks for the effort @c0rnflake . I’m not yet running Influx, but you’ve given me lots to play with there.
I know the oilpal system used to have a fill alert and a theft alert where you’d get a notification if there was a sudden change in oil level. Do you have any idea if that gets triggered by data from the sensor itself (in one of those other data fields) or if that was calculated on the Web service?
But I’ve absolutely no idea how to interpet the values or how often they change. I’m pretty sure that the FL is Fill and would only be populated when the tank is filled so it wouldn’t be practical to test that.
So the above posts gave me a little motivation to tinker with the original scipt. I’m now using the Apex Charts integration and have finally settled with the below chart and information. Once I’m 100% happy that everythings working as expected I’ll post the updates needed to reproduce this.
I have my oilpal up and running, but can’t seem to get the right dimensions reporting back. My oil tank is a horizontal cylinder type, and the dimensions are
95 cm (w) x 165 cm (l) x 95 cm (h)
Could someone tell me what settings I need to put in, it’s a horizontal cylinder type tank
change the tank type to 2, and put your dimensions in height, width, and length. If you keep the tank type as 1 you’ll get volume calculation for a cylindrical tank with height and radius as specified.
The height you need is from the floor of the tank to the sensor, which might be slightly less than the total height, depending on the sensor mounting position on your tank.
Also if anyone has developed anything to check optimal time to buy , I was thinking if could check qty of tank needed and trend oil pricing , it could be an a nice automation to secure oil at best price.
The updates seem to be working just fine. Famous last words eh?
As for the tracking you mentioned, I’ve had something similar running for a while now also. The problem is where to scrape the info from. As I’m in the UK, i’m scraping local suppliers for mine.
That looks good , do you correlate the two , oil level and price via some automation to alert that now is time to order or just eyeball them and order when looks good.
Hi @c0rnflake. Many thanks for sharing your code - bringing my OilPal data into HA was always a goal of mine but I hadn’t a clue how to do it until your post!
So I’ve got the IP address of my OilPal modem and can connect to it via a browser no problem. My tank is rectangular and I also have the dimensions (l x w x h) - I also have the volume (1040 litres) as it’s printed on a label on the tank!
A few questions:
After 24 hours, I am getting a state of “unknown”. It was “waiting for first reading” but that updated to “unknown”, presumably after the first reading between the oilpal sensor and the oilpal modem. Any ideas what I’m doing wrong? My template sensor code is:
If I know the volume, do I need the other dimensions? Can I just simply set the tank_volume variable to “1040” and remove the other calculations, as per below?
- platform: scrape
resource: http://192.168.86.54/diag.htm
name: OilPalDataq
select: 'table:nth-of-type(2) td:nth-of-type(5)'
unit_of_measurement: 'Litres'
value_template: >-
{% set modem_values = value.split(' ') %}
{% set tank_temp = modem_values[1] %}
{% if tank_temp != "Data" %}
{% set tank_depth = modem_values[0] | int %}
{% set tank_volume = "1040" %}
{{ tank_volume.value | round (0) }}
{% else %}
{% if states.sensor.oilpaldata.state == "" %}
Waiting for first reading
{% else %}
{{ states.sensor.oilpaldata.state }}
{% endif %}
{% endif %}
scan_interval: 60
Would you mind sharing your yaml for the Apex Charts (post #32 above)? I think it looks great and is exactly what I’d like for my own dashboard!
Thanks again for sharing your code - I really appreciate it.
Hi @dunner I’ll come back to this in the morning, but your second code paste has completely removed any of the tank volume steps, so you definately aren’t going to get any values with that. You need your dimensions at the moment as the tank volume is calculated using those.
It scrapes diag.htm (once) and publishes data for all sensors to MQTT.
(There are still hardcoded values for my test setup.)
The table headings disagree with the data. For example we get:
Device #
RF Address
#Rx
Rx Time (h)
Data Aux Bat [Cache]
[FL Hi Lo Dif]
1
662
363
8/1/15 02:01
1177 50 0 [80 64 99 ]
2
282
157
8/1/15 01:57
No Data
3
0
0
0/0/0 00:00
No Data
4
0
0
0/0/0 00:00
No Data
In our case the Data field is actually temperature and Aux field is the depth reading.
What was interesting was decoding some of the cache values - noting that the high bits for temperature overlap the low bits for the depth reading.
Speed of sound varies with temperature increasing more-or-less ~0.6m/s per ⁰C.
So Tekelek record the depth reading at a resolution of 0.5cm leading to a (rather compact) adjustment for temperature. And that’s close enough: