Smart Oil Guage

@lost

Can you post your entities code by any chance? I’ve been struggling with trying to get the data to get represented in a histogram, but it only wants to show me a bar graph…

[
    {
        "id": "679fbd256c1ec156",
        "type": "inject",
        "z": "4a88c65d5156b41a",
        "name": "Website version",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "7200",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 130,
        "y": 320,
        "wires": [
            [
                "1819507890ac02e0"
            ]
        ]
    },
    {
        "id": "1819507890ac02e0",
        "type": "http request",
        "z": "4a88c65d5156b41a",
        "name": "Get Session Cookie",
        "method": "GET",
        "ret": "txt",
        "paytoqs": "ignore",
        "url": "https://app.smartoilgauge.com/login.php",
        "tls": "",
        "persist": false,
        "proxy": "",
        "authType": "",
        "x": 140,
        "y": 360,
        "wires": [
            [
                "4fb8a0f4e7819484"
            ]
        ]
    },
    {
        "id": "4fb8a0f4e7819484",
        "type": "function",
        "z": "4a88c65d5156b41a",
        "name": "LOGIN CONFIG HERE",
        "func": "var smartOilUser = \"[email protected]\";\nvar smartOilPassword = \"YourPassword\";\nvar cookies = msg.responseCookies;\nvar cff_nonce = msg.payload.match(\"(?<=name='ccf_nonce' value=')(?:[^']|'')*(?=')\");\nmsg.headers = {\n        \"Content-Type\": \"application/x-www-form-urlencoded\",\n        \"Cookie\" : \"PHPSESSID=\" + cookies.PHPSESSID.value,\n        \"User-Agent\": \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.55 Safari/537.36\"\n};\n\nmsg.payload =  \"username=\" + smartOilUser + \"&user_pass=\" + smartOilPassword + \"&ccf_nonce=\"+cff_nonce[0];\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 140,
        "y": 400,
        "wires": [
            [
                "e1b71817c7ef2a23"
            ]
        ]
    },
    {
        "id": "e1b71817c7ef2a23",
        "type": "http request",
        "z": "4a88c65d5156b41a",
        "name": "Login to the smartoil website",
        "method": "POST",
        "ret": "txt",
        "paytoqs": "ignore",
        "url": "https://app.smartoilgauge.com/app.php",
        "tls": "",
        "persist": false,
        "proxy": "",
        "authType": "",
        "x": 160,
        "y": 440,
        "wires": [
            [
                "1c8ac8aee89e36fa"
            ]
        ]
    },
    {
        "id": "a7124ae6be1f3c0c",
        "type": "http request",
        "z": "4a88c65d5156b41a",
        "name": "Scrape website for info",
        "method": "POST",
        "ret": "obj",
        "paytoqs": "ignore",
        "url": "https://app.smartoilgauge.com/ajax/main_ajax.php",
        "tls": "",
        "persist": false,
        "proxy": "",
        "authType": "",
        "x": 150,
        "y": 520,
        "wires": [
            [
                "48570d654a9c6c55"
            ]
        ]
    },
    {
        "id": "1c8ac8aee89e36fa",
        "type": "function",
        "z": "4a88c65d5156b41a",
        "name": "Prepare query",
        "func": "var cookies = msg.responseCookies\nmsg.headers = {\n\"X-Requested-With\": \"XMLHttpRequest\",\n\"Content-Type\": \"application/x-www-form-urlencoded\",\n\"User-Agent\": \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.55 Safari/537.36\",\n\"Cookie\" : \"PHPSESSID=\" + cookies.PHPSESSID.value\n};\nmsg.payload =  {\n  \"action\": \"get_tanks_list\",\n  \"tank_id\": \"0\"\n};\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 120,
        "y": 480,
        "wires": [
            [
                "a7124ae6be1f3c0c"
            ]
        ]
    },
    {
        "id": "48570d654a9c6c55",
        "type": "function",
        "z": "4a88c65d5156b41a",
        "name": "Extract required data here",
        "func": "node.status({text:msg.payload.tanks[0].sensor_rt + \" gal: \" + msg.payload.tanks[0].sensor_gallons});\nmsg.payload = Number(msg.payload.tanks[0].sensor_gallons);\nreturn msg;\n",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 150,
        "y": 560,
        "wires": [
            [
                "13b148a7503d5fc7"
            ]
        ]
    },
    {
        "id": "13b148a7503d5fc7",
        "type": "ha-entity",
        "z": "4a88c65d5156b41a",
        "name": "GasLevel",
        "server": "e0ae21e440ba5f41",
        "version": 2,
        "debugenabled": false,
        "outputs": 1,
        "entityType": "sensor",
        "config": [
            {
                "property": "name",
                "value": ""
            },
            {
                "property": "device_class",
                "value": "gas"
            },
            {
                "property": "icon",
                "value": ""
            },
            {
                "property": "unit_of_measurement",
                "value": ""
            },
            {
                "property": "state_class",
                "value": ""
            },
            {
                "property": "last_reset",
                "value": ""
            }
        ],
        "state": "payload",
        "stateType": "msg",
        "attributes": [],
        "resend": true,
        "outputLocation": "payload",
        "outputLocationType": "none",
        "inputOverride": "allow",
        "outputOnStateChange": false,
        "outputPayload": "",
        "outputPayloadType": "str",
        "x": 400,
        "y": 560,
        "wires": [
            []
        ]
    },
    {
        "id": "e0ae21e440ba5f41",
        "type": "server",
        "name": "Home Assistant",
        "version": 2,
        "addon": false,
        "rejectUnauthorizedCerts": true,
        "ha_boolean": "y|yes|true|on|home|open",
        "connectionDelay": true,
        "cacheJson": true,
        "heartbeat": false,
        "heartbeatInterval": "30"
    }
]

@Zalaban I was actually running into the same issue. Your post inspired me:

I did a little digging and came across this. With that in mind, I updated the entity. I have to wait an hour or two to see if it fixes it, but :crossed_fingers: that this will do the trick.

1 Like

@lost :partying_face: thanks :slight_smile:

Many thanks to @Zalaban and @lost for posting the above node-RED solution. I’ve successfully managed to get my Smart Oil Gauge reading to my Home Assistant Dashboard!

I’ve been struggling though to then pass the info on to Homebridge in a way that Homebridge/Homekit can best represent it. I’m using the node-red-contrib-homekit-bridged node-RED Palette. Have either of you done anything similar or have any guesses as to a solution? I’m stumped! By default the Entity in your flow above is shown as an Air Quality sensor, which shows the tank reading as the Air Particulate Density value. However, this value is only available after tapping into the Air Quality sensor to see the details; it’s not visible from the parent screen, which only shows the Air Quality status in the tile. If you have any insight, please let me know. Thanks again for all the work you’ve done and shared in this thread!

Hi, I went and installed the palette to see what the options would be.

So far, the only one I could see working for you would be if you would use the temperature sensor in order the send the level as a percentage in between 0 and 100.

I haven’t been able to find any other services that would report the tank level which would be supported by Homekit.

If you do find a working solution, share it back here so we can use it as well :slight_smile:

Arrived here looking for the sensor code to turn ‘oil level’ into ‘rate of oil use’ for the energy dashboard.

Meanwhile here’s my variation on a DIY ESPhome oil tank sensor for an (indoor and powered) oil tank sensor. It has helped me order the correct amount of oil over a few years without maintenance. Now with the price of oil I’m interested in energy metrics.

https://www.rogerfrost.com/oil-tank-level-sensor-also-water-softener-salt-level/

project: oil tank level sensor oil tank level sensor - Roger Frost's home automation projects

2 Likes

Hey guys,
So I have been working on a way to get data my gauge. I tried using multiscraper but it seems the page uses an ajax call to get the actual dynamic data I’m looking for. I don’t want to run another server just for red node for this one purpose. Did anyone figure out another way?

@Dragon88 here’s a working multiscrape example:

multiscrape:
  - resource: 'https://app.smartoilgauge.com/ajax/main_ajax.php'
    method: POST
    payload: 'action=get_tanks_list&tank_id=0'
    headers:
      X-Requested-With : XMLHttpRequest
      Content-Type : application/x-www-form-urlencoded
    scan_interval: 3600
    form_submit:
      submit_once: False
      resource: 'https://app.smartoilgauge.com/login.php'
      select: ".content-container"
      input:
        username: [email protected]
        user_pass: 'YourPassword'
    sensor:
      - name: smartoiltank
        unique_id: smartoiltank
        value_template: '{{ value_json.tanks[0].sensor_gallons }}'
        unit_of_measurement: "gal" 
        attributes:
          - name: tank_name
            value_template: '{{ value_json.tanks[0].tank_name }}'
          - name: last_updated_time
            value_template: '{{ value_json.tanks[0].sensor_rt }}'
          - name: last_updated_timestamp
            value_template: '{{ value_json.tanks[0].last_read }}'
          - name: battery
            value_template: '{{ value_json.tanks[0].battery }}'
3 Likes

This worked flawlessly, thanks so much for sharing!

As a newbie, quick question for you - how do I make this sensor work with statistics in HA? I haven’t had any luck so far.

I’ll have to wait an hour or two to see once statistics are calculated, but I did find that adding the following below unit_of_measurement allowed the sensor to show up:

sensor_class: measurement
device_class: volume

@zakaban or any one else … Do I need to have API for this code to work ?

No, you don’t. Above method uses your smart oil login to scrape the data.

While back I emailed smart oil people and asked them if they have a api for their app. They told me that it costs $2 per month for api access. So you could use their api, but you’d have to pay for it.

@ Zalaban The above worked perfectly, I cut and paste into configuration.yaml with a quick restart.
My only request is to have the “Fill %” and the “Level”. I’m vry bad at json.

This is how I did it, I use the gauge card.

If you actually want to see the percentage you could also do it with with a template jinja:

{{ (states.sensor.smartoiltank.state|float / 500 * 100) | round(1) }}

Change the 500 with the actual maximum of your tank.

1 Like

I’m an absolute novice with HA, scraping, etc. Im trying to set this up and have MA installed via HACs.

I have added the following to configuration.yaml:
multiscrape: !include multiscrape.yaml

Added the lines above with my UN/PW to the Muliscrape.yaml file in same directory as configuration.yaml and received the error when restarting HA:

Cannot quick reload all YAML configurations because the configuration is not valid: Invalid config for [multiscrape]: [multiscrape] is an invalid option for [multiscrape]. Check: multiscrape->multiscrape->0->multiscrape. (See /config/configuration.yaml, line 12).

HA reloads if Multiscrape.yaml is blank. Any help would be greatly appreciated!! Thanks in advance!!

Logs Show:

[140677240650560] Cannot quick reload all YAML configurations because the configuration is not valid: Integration error: multiscraper - Integration ‘multiscraper’ not found.

11:40:51 AM – (ERROR) Home Assistant WebSocket API - message first occurred at 11:15:48 AM and shows up 17 times

The system cannot reload because the configuration is not valid: Integration error: multiscraper - Integration ‘multiscraper’ not found.

11:40:51 AM – (ERROR) Home Assistant Core Integration - message first occurred at 11:15:48 AM and shows up 17 times

You could try adding the multiscrape YAML directly into configuration.yaml rather than referencing a separate file

1 Like

Thanks, I was able to add and reload without errors. Next episode of complete noob… Assuming that worked where should i be able to find the sensor. I would assume there would be a device or entity names “smartoiltank” but cannot find anything. Thanks for your help!!

Personally I get an error when trying to use multiscrape which is why I haven’t switched to using it. Have you tried enabling logging for the extension?

I did and not seeing anything in log… Ill keep playing and hoping haha