chises / ha-oilfox Goto Github PK
View Code? Open in Web Editor NEWHomeAssistant Sensor for Oilfox
HomeAssistant Sensor for Oilfox
Hi, I've just installed the OilFox integration - So I am not sure, if all sensors will be provided by the API directly - or some only on certain occasions... but I would like to get the following information from the Integration as well:
batteryLevel | string, optional | enum of the battery level, see below |
---|
name | description |
---|---|
FULL | Full battery level |
GOOD | Good battery level |
MEDIUM | Medium battery level |
WARNING | Low battery level |
CRITICAL | Critical battery level |
and maybe also the Failure Information:
validationError | string, optional | enum with errors regarding the measurement, see below |
---|
name | description |
---|---|
NO_METERING | No measurement yet |
EMPTY_METERING | Incorrect Measurement |
NO_EXTRACTED_VALUE | No fill level detected |
SENSOR_CONFIG | Faulty measurement |
MISSING_STORAGE_CONFIG | Storage configuration missing |
INVALID_STORAGE_CONFIG | Incorrect storage configuration |
DISTANCE_TOO_SHORT | Measured distance too small |
ABOVE_STORAGE_MAX | Storage full |
BELOW_STORAGE_MIN | Calculated filling level implausible |
these are documented in the API documentation from OilFox:
https://github.com/foxinsights/customer-api/tree/main/docs/v1
Thanks a lot :)
Until now, the sensors provided different information only as an attribute.
For example, the next update or last update timestamp was within the different sensors (for which I have then created template sensors)
oilfox_kachelofen_updatetimeleft:
value_template: >-
{% set currentTime = as_timestamp(states('sensor.date_time_iso')) %}
{% set nextUpdateTimestamp = as_timestamp(state_attr('sensor.oilfox_of7090001854_filllevelpercent', 'Next Measurement')) %}
{% set timeLeft = nextUpdateTimestamp - currentTime %}
{% if timeLeft > 0 %}
{% set minutes = (timeLeft / 60)|int % 60 %}
{% set hours = (timeLeft / 3600)|int %}
{{ '{:02}:{:02}'.format(hours, minutes) }}
{% else %}
00:00
{% endif %}
unit_of_measurement: hrs
oilfox_kachelofen_lastupdate:
value_template: >-
{% set lastUpdateTimestamp = state_attr('sensor.oilfox_of7090001854_filllevelpercent', 'Last Measurement') %}
{{ (as_timestamp(lastUpdateTimestamp)) | timestamp_custom('%d.%m.%Y - %H:%M' ) }}
icon_template: mdi:update
oilfox_kachelofen_nextupdate:
value_template: >-
{% set nextUpdateTimestamp = state_attr('sensor.oilfox_of7090001854_filllevelpercent', 'Next Measurement') %}
{{ (as_timestamp(nextUpdateTimestamp)) | timestamp_custom('%d.%m.%Y - %H:%M' ) }}
icon_template: mdi:update
After the last update, it seems that the attributes aren't longer available (Bugfix for #10 )
But it might be an idea, to implement own sensors for the last update and next update?
I can not restart HA anymore, because I got the following error Message:
Platform error sensor.oilfox - Exception importing custom_components.oilfox.sensor
Thanks for YouTube help
Hi, sorry if this was already solved or i'm doing something wrong.
The integration itself is working, but it goes unavailable like every few hours. See in graphic below
This is from the log:
Logger: custom_components.oilfox.UpdateCoordinator
Source: helpers/update_coordinator.py:193
Integration: OilFox (documentation, issues)
First occurred: 12. April 2023 um 14:56:38 (31 occurrences)
Last logged: 19:18:04
Timeout fetching oilfox data
The Adapter on my tank sends an update every 24 hours also to the oilfox app, so is it because HA tries to often to check for an update? Is there a way to prevent this?
Many thanks!
Oilfox Entity is reporting all devices as being unavailable on two different HA instances since update on 2024.2. App is working correctly, so most probably the update broke something. A fresh logon of the integration did not help either.
Since a few days i lost connection, is there a change in the API ?
with recent HA Version, the log is throwing the following warning:
Detected integration that called async_setup_platforms instead of awaiting async_forward_entry_setups; this will fail in version 2023.3. Please report issue to the custom integration author for oilfox using this method at custom_components/oilfox/__init__.py, line 22: hass.config_entries.async_setup_platforms(entry, (Platform.SENSOR,))
the usage counter does not output any values, always 0
Der Konfigurationsfluss konnte nicht geladen werden: 500 Internal Server Error Server got itself in trouble this Error i will get after trying to add this integration. HA is still loading and after a few seconds this error message apears. I have no ideas what i can do.
Hallo chises,
danke für deine Entwicklung, das hört sich sehr gut an. Lass mich bitte fragen, es gibt verschiedene Oilfox Varianten.
Ist es auch für diesen hier nutzbar:
https://www.baywa.de/de/haus-hof/tanken/diesel/baywa-oilfox-radar-digitaler-fuellstandsmesser-fuer-heizoel--und-dieseltanks-aus-kunststoff-ohne-tankoeffnung/p-000000000002078174/
ich habe keine Öffnung frei am Tank und müsste auf den Radar zurückgreifen, da er aber scheinbar in die Cloud senden müsste es doch gehen oder?
Hello chises,
thanks for your development, it sounds very good. Let me ask please, there are different Oilfox variants.
Is it also usable for this one:
https://www.baywa.de/de/haus-hof/tanken/diesel/baywa-oilfox-radar-digitaler-fuellstandsmesser-fuer-heizoel--und-dieseltanks-aus-kunststoff-ohne-tankoeffnung/p-000000000002078174/
I have no opening free on the tank and would have to resort to the radar, but since he seems to send to the cloud it would have to go or?
BR
oliver
Based on @ChristophCaina his idea we add the attributes as entities.
The attributes will stay as additional information but i will be easier to access that parameters in scripts and workflows. Same happened to Battery attribute already.
Original Post: https://github.com/ChristophCaina #11 (comment)
since a few days the sensor is no longer available
As an future improvement for the Integration, the Integration should use the "device" information from HomeAssistant.
Right now, it will create entities without any assignment to a device:
In my case, I do have two Sensors - and it would be nice, if the integration could differenciate between them.
In that case - it would show: "2 devices - 14 Entities" - 7 for each device.
Since each sensor does provide a "unique" device identifier with its name, it should be not too difficult to assign the devices...
The naming of the sensors would be pretty much the same, I guess...
Hi,
Maybe, you can provide some support on the following?
Since I am using the Oilfox (which is for over a year now) - my intention was to get an information not about how much oil is left in the tanks, but about the Oil Usage itself.
For this, I have created Sensor Templates, which are calculating the usage based on the fill level of the tank - and the value how much the tank can acutally store.
Unfortunately, this is always causing issues, whenever the connection to the cloud has failed, as you can see in the following screenshot with the history...
Another issue is, the Template Sensor is using "Measurement" as state_class, which is throwing a warning in my logs, because the State_Class should either be total - or total_increasing... but this will cause further issues within the Statistics whenever such a wrong calculation happens.
Your Integration does already provide a sensor for the kWh (energy usage) - and I know, that this sensor will not be provided by the cloud-platform itself - so you are calculating this within your integration...
So would it be possible, to do a similar thing for the oil usage itself?
I am not sure, but maybe the API is already providing such information, because the APP does have information about how much Oil you have used per week / month / year... I'm not sure, if this calculation will be done within the app (where you have calculated the max volume of your tank)
In theory, you could just "invert" the values from filllevel -> this is decreasing with each measurement - and therefore, the fuel_used should increase by the same amount ... (but this might cause a conflict, when the tank will be refilled ?)
If that's not possible, maybe you have an idea on how to improve my template sensor to overcome such peaks?
- sensor:
- name: oilfox_of7090002028_fuelused
unique_id: "oilfox_of7090002028_fuelused"
unit_of_measurement: L
device_class: volume_storage
state_class: measurement # this should be total or total_increasing
state: >
{% set max_of7090002028_filllevel = 3000 | float(0) %} # the max capacity of the tank(s)
{% set current_of7090002028_filllevel = states('sensor.oilfox_of7090002028_filllevelquantity') | float(0) %}
{% set of7090002028_fuelused = max_of7090002028_filllevel - current_of7090002028_filllevel | float(0) %}
{{ '{:.2f}'.format(of7090002028_fuelused) }}
availability: >
{{ states('sensor.oilfox_of7090002028_filllevelquantity') not in ['Unknown', 'Unavailable', 'None'] }}
with HA 2024.1.0b0 the following Deprication warning will be raised:
TIME_DAYS was used from oilfox, this is a deprecated constant which will be removed in HA Core 2025.1. Use UnitOfTime.DAYS instead, please create a bug report at https://github.com/chises/ha-oilfox/issues
ENERGY_KILO_WATT_HOUR was used from oilfox, this is a deprecated constant which will be removed in HA Core 2025.1. Use UnitOfEnergy.KILO_WATT_HOUR instead, please create a bug report at https://github.com/chises/ha-oilfox/issues
TEMP_CELSIUS was used from astroweather, this is a deprecated constant which will be removed in HA Core 2025.1. Use UnitOfTemperature.CELSIUS instead, please create a bug report at https://github.com/mawinkler/astroweather/issues
This issue should be fixed with PR #43
Hello,
thanks for your work on the oilfox integration :-)
As it seems there is a problem with the new version of HA ?
Dont know if this is an error that occures when connection failes or what ever.
File "/config/custom_components/oilfox/sensor.py", line 49, in setup_platform entities.append(OilFoxSensor(OilFox(email, password, item['hwid'])))
File "/config/custom_components/oilfox/sensor.py", line 140, in init self.OilFox.updateStats()
File "/config/custom_components/oilfox/sensor.py", line 81, in updateStats self.daysReach = response.json()['daysReach']
KeyError: 'daysReach'
Maybe you can see whats the problem there ?
As i see in your source code there is no option if the connection fails to set the sensors to NAN or something like that ? My Phyton knowledge is not that good so maybe i am wrong.
Greetings from Austria
Kilowatt
Someone know how to add OilFox to my Energy Dashboard?
Can't use the filllevelquantity entity as an input for statics.
Would like to have a diagram card with my oillevel, but can't select filllevelquantity as the input for any statics. Only usagecounter works.
Maybe this is the solution?
https://www.home-assistant.io/more-info/statistics/
Currently daysReach is a DURATION with TIME_DAYS as unit. This works but is converted into hh:mm:ss by homeassistant:
based in HA documentation DURATION is used for "days, hours minutes or seconds. But it is not converted into days. Need to check this.
Hi :)
After the recent issue I've noticed some strange issues with the integration...
Sometimes, the sensor: filllevelquantity seems to receive a wrong value - and is then resetting again to the correct value:
The strange thing here is:
"Kachelofen" is only a 1000 L tank...
I am using a second Oilfox sensor for another tank - which is 3 times 1000 L (3000L in total) - where I cannot see this behave:
Anyway - I have created utility meters for both sensors - to count the monthly and yearly usage... and this behave does affect the statistics / value of these sensors.
Probably - this could be related due to the move to the config flow?
Please fix in line 63 of Oilfox.py:
timeout=aiohttp.ClientTimeout(total=self.TIMEOUT)
This fix is tested.
Solved with V 1.16 and pull request #53
Hi chises,
I think something in HA changed because of the message in the screenshot and because it worked well before (except missing data caused by WLAN connection sometimes).
Thanks for your great integration,
Dieter
`Dieser Fehler wurde von einer benutzerdefinierten Integration verursacht
Logger: custom_components.oilfox.UpdateCoordinator
Source: helpers/update_coordinator.py:300
Integration: OilFox (documentation, issues)
First occurred: 3. Februar 2024 um 22:29:06 (860 occurrences)
Last logged: 17:39:59
Unexpected error fetching oilfox data: ValueError("timeout parameter cannot be of <class 'int'> type, please use 'timeout=ClientTimeout(...)'")
Traceback (most recent call last):
File "/config/custom_components/oilfox/UpdateCoordinator.py", line 37, in _async_update_data
await self.oilfox_api.update_stats()
File "/config/custom_components/oilfox/OilFox.py", line 62, in update_stats
async with aiohttp.ClientSession(timeout=self.TIMEOUT) as session:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/aiohttp/client.py", line 292, in init
raise ValueError(
ValueError: timeout parameter cannot be of <class 'int'> type, please use 'timeout=ClientTimeout(...)'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 300, in _async_refresh
self.data = await self._async_update_data()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/oilfox/UpdateCoordinator.py", line 39, in _async_update_data
raise ConfigEntryNotReady(repr(err))
homeassistant.exceptions.ConfigEntryNotReady: ValueError("timeout parameter cannot be of <class 'int'> type, please use 'timeout=ClientTimeout(...)'")
`
After update HA to 2024.1.6 it wont work.
Setup failed for custom integration 'oilfox': Requirements for oilfox not found: ['aiohttp==3.9.1'].
13:01:02 – (FEHLER) setup.py
Unable to install package aiohttp==3.9.1: ERROR: Cannot install aiohttp==3.9.1 because these package versions have conflicting dependencies. ERROR: ResolutionImpossible: for help visit https://pip.pypa.io/en/latest/topics/dependency-resolution/#dealing-with-dependency-conflicts
13:01:02 – (FEHLER) util/package.py - Die Nachricht ist zum ersten Mal am 13:00:58 aufgetreten und erscheint 3 mal
Integration is in an initailizing loop.
Debug log shows:
``
2024-02-02 14:01:16.407 ERROR (MainThread) [custom_components.oilfox.UpdateCoordinator] Unexpected error fetching oilfox data: ValueError("timeout parameter cannot be of <class 'int'> type, please use 'timeout=ClientTimeout(...)'")
Traceback (most recent call last):
File "/config/custom_components/oilfox/UpdateCoordinator.py", line 37, in _async_update_data
await self.oilfox_api.update_stats()
File "/config/custom_components/oilfox/OilFox.py", line 62, in update_stats
async with aiohttp.ClientSession(timeout=self.TIMEOUT) as session:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/aiohttp/client.py", line 292, in init
raise ValueError(
ValueError: timeout parameter cannot be of <class 'int'> type, please use 'timeout=ClientTimeout(...)'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 300, in _async_refresh
self.data = await self._async_update_data()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/oilfox/UpdateCoordinator.py", line 39, in _async_update_data
raise ConfigEntryNotReady(repr(err))
homeassistant.exceptions.ConfigEntryNotReady: ValueError("timeout parameter cannot be of <class 'int'> type, please use 'timeout=ClientTimeout(...)'")
2024-02-02 14:01:18.020 ERROR (SyncWorker_5) [homeassistant] Error doing job: Unclosed client session
2024-02-02 14:01:41.199 DEBUG (MainThread) [custom_components.oilfox.OilFox] Update Refresh and Access Token: ok
2024-02-02 14:01:41.202 DEBUG (MainThread) [custom_components.oilfox.OilFox] Update Refresh Token: True
2024-02-02 14:01:41.203 ERROR (MainThread) [custom_components.oilfox.UpdateCoordinator] Unexpected error fetching oilfox data: ValueError("timeout parameter cannot be of <class 'int'> type, please use 'timeout=ClientTimeout(...)'")
Traceback (most recent call last):
File "/config/custom_components/oilfox/UpdateCoordinator.py", line 37, in _async_update_data
await self.oilfox_api.update_stats()
File "/config/custom_components/oilfox/OilFox.py", line 62, in update_stats
async with aiohttp.ClientSession(timeout=self.TIMEOUT) as session:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/aiohttp/client.py", line 292, in init
raise ValueError(
ValueError: timeout parameter cannot be of <class 'int'> type, please use 'timeout=ClientTimeout(...)'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 300, in _async_refresh
self.data = await self._async_update_data()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/oilfox/UpdateCoordinator.py", line 39, in _async_update_data
raise ConfigEntryNotReady(repr(err))
homeassistant.exceptions.ConfigEntryNotReady: ValueError("timeout parameter cannot be of <class 'int'> type, please use 'timeout=ClientTimeout(...)'")
2024-02-02 14:01:41.213 DEBUG (MainThread) [custom_components.oilfox.UpdateCoordinator] Finished fetching oilfox data in 0.090 seconds (success: False)
2024-02-02 14:01:41.589 ERROR (SyncWorker_10) [homeassistant] Error doing job: Unclosed client session
``
Logger: homeassistant.components.sensor
Source: custom_components/oilfox/sensor.py:159
Integration: Sensor (documentation, issues)
First occurred: 06:08:14 (1 occurrences)
Last logged: 06:08:14
Error while setting up oilfox platform for sensor
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 304, in _async_setup_platform
await asyncio.shield(task)
File "/config/custom_components/oilfox/sensor.py", line 159, in async_setup_entry
oilfox_devices = coordinator.data["items"]
TypeError: 'NoneType' object is not subscriptable
Might be relevant für your Integration:
SensorDeviceClass.VOLUME_STORAGE
https://developers.home-assistant.io/docs/core/entity/sensor/
Don't know If this will be used/implemented in specific areas of ha later... So might be used for the filllevel entities?
Hi, since I have your Integration running,
I've noticed that the Sensors do not refresh / Update their readings regulately.
I have to reload the Integration every now and then to Update their readings.
Since OilFox does one Scan every 24hrs it would be great, of the Integration could try to read the API every time when the Date / time from the Attribute 'next update' has been reached / past.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.