Calculating Oil Consumption

Thanks Mike, I will update accordingly.

Thank you for your help.

I just tried that. I changed the input_number and restarted. My updated value was not stored. The input_number value was reset to the initial: value after the restart.

What am I doing wrong?

If you specify an initial value, it will always be set to that value on startup or reload. The concept of storing the last known value is lost if you define an initial value.

1 Like

Got it, thanks!!

Not sure why I didn’t see that. I tried again without an initial: value and it saved across restarts as expected.

For future reference, input_select behaves differently. It cannot exist without an initial value; you can’t define an “empty” input_select and then populate it later (via a script or automation). Because it must be initialized, any changes you make to it afterwards are lost after a restart (because it uses its initial value on startup).

I learned this when I tried to use an input_select for general storage of data (it’s a list that can be expanded). Everything worked well until I restarted Home Assistant and all my added data was discarded and replaced by the initial value(s). I thought I could create an empty input_select and then any data I added to it would be stored/restored. No; it must have an initial value (i.e. the input_select must be defined with at least one option).

1 Like

Glad I’m not the only one tripped up by that. Thanks for elaborating!

For anyone who might be interested, I documented my progress on my oil tank level gauge project here:

1 Like

@Mikefila, Just an FYI, I noticed I had an issue where I “deployed” my Node-Red flows and the oil tracker reset my tank value back to 275. Other then that it has been running fine.

Alright this should be it. Apparently node-red by default does not save data, it needs to be enabled. Go to your file editor and navigate to the node red folder. Find the file settings.js and select it. You need to add the following:


  contextStorage: {
    default: {
        module: "localfilesystem"
    }
  },

It’s important to watch your blank spaces, each dot is 1 space.

Save the file, go to supervisor, node-red app and restart node red. Give it a minute or two and check the logs tab inside the node-red app page, see if there are any errors.

Here is the revised flow that will save the count.

[{"id":"49a8a6f8.e3aba8","type":"inject","z":"ec78a76b.a0a4d","name":"Test","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"on","payloadType":"str","x":430,"y":60,"wires":[["381f2c71.f7670c"]]},{"id":"4f4facbf.7c9d5c","type":"ha-entity","z":"ec78a76b.a0a4d","name":"Oil usage","server":"7c85afe1.bbea8","version":1,"debugenabled":true,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"Oil Level"},{"property":"device_class","value":""},{"property":"icon","value":"mdi:propane-tank-outline"},{"property":"unit_of_measurement","value":"gal"}],"state":"count","stateType":"msg","attributes":[{"property":"msg.count","value":"","valueType":"num"}],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","outputOnStateChange":false,"outputPayload":"$entity().state ? \"on\": \"off\"","outputPayloadType":"jsonata","x":1380,"y":100,"wires":[[]],"info":"decimal: 2"},{"id":"244dd0d2.4bfca","type":"poll-state","z":"ec78a76b.a0a4d","name":"Is furnace on?","server":"7c85afe1.bbea8","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"updateinterval":"15","updateIntervalUnits":"seconds","outputinitially":false,"outputonchanged":false,"entity_id":"binary_sensor.furnace","state_type":"str","halt_if":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"x":170,"y":100,"wires":[["381f2c71.f7670c"],[]]},{"id":"c62686c3.3c9558","type":"change","z":"ec78a76b.a0a4d","name":"set to 2 decimal points","rules":[{"t":"set","p":"count","pt":"msg","to":"$round(count, 2)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1160,"y":100,"wires":[["4f4facbf.7c9d5c"]]},{"id":"50d32aa4.cbfa3c","type":"server-state-changed","z":"ec78a76b.a0a4d","name":"Input boolean oil reset","server":"7c85afe1.bbea8","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_boolean.oil_reset","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":true,"ignorePrevStateUnknown":true,"ignorePrevStateUnavailable":true,"ignoreCurrentStateUnknown":true,"ignoreCurrentStateUnavailable":true,"x":200,"y":220,"wires":[["ab075888.bab5e","6f0843b0.c5be9c"],[]]},{"id":"ab075888.bab5e","type":"delay","z":"ec78a76b.a0a4d","name":"","pauseType":"delay","timeout":"250","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":430,"y":220,"wires":[["a979c77d.9d5538"]]},{"id":"a979c77d.9d5538","type":"api-call-service","z":"ec78a76b.a0a4d","name":"turn off reset switch","server":"7c85afe1.bbea8","version":1,"debugenabled":false,"service_domain":"input_boolean","service":"toggle","entityId":"input_boolean.oil_reset","data":"","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":810,"y":220,"wires":[[]]},{"id":"bcf643d5.c3e278","type":"api-call-service","z":"ec78a76b.a0a4d","name":"persistant notification if reset","server":"7c85afe1.bbea8","version":1,"debugenabled":false,"service_domain":"persistent_notification","service":"create","entityId":"","data":"{\t   \"message\":\"Please check your history if you did not initiate this action.\",\t   \"title\":\"Oil level reset\"\t}","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":840,"y":160,"wires":[[]]},{"id":"381f2c71.f7670c","type":"counter","z":"ec78a76b.a0a4d","name":"oil counter","init":"550","step":"0.0104","lower":"","upper":"","mode":"decrement","outputs":"1","x":790,"y":100,"wires":[["b98146ef.0ab288","c62686c3.3c9558"]]},{"id":"b98146ef.0ab288","type":"change","z":"ec78a76b.a0a4d","name":"save count to flow.counter","rules":[{"t":"set","p":"counter","pt":"flow","to":"count","tot":"msg"},{"t":"set","p":"payload","pt":"msg","to":"count/1000","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1170,"y":160,"wires":[[]]},{"id":"6f0843b0.c5be9c","type":"change","z":"ec78a76b.a0a4d","name":"delete flow.counter, reset count","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"},{"t":"delete","p":"counter","pt":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":490,"y":160,"wires":[["381f2c71.f7670c","bcf643d5.c3e278"]]},{"id":"7c85afe1.bbea8","type":"server","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

E. You should also see a new folder inside the node-red folder named context.

Thanks Mike

Don’t thank me yet lol, there is a problem with the math. The counter can encounter errors with decimals. So you have to multiply your burn rate to bring it to a whole number, then multiply the gallons.

my ex
burn rate: .0104
x         10,000
=            104

then 550gal x 10000 = 5,500,000gal.

Enter that in the counter. Now swap these 2 nodes in. Adjust the multiplier as necessary.

[{"id":"c62686c3.3c9558","type":"change","z":"ec78a76b.a0a4d","name":"set to 2 decimal points","rules":[{"t":"set","p":"count","pt":"msg","to":"count/10000","tot":"jsonata"},{"t":"set","p":"count","pt":"msg","to":"$round(count, 2)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1160,"y":100,"wires":[["4f4facbf.7c9d5c"]]},{"id":"b98146ef.0ab288","type":"change","z":"ec78a76b.a0a4d","name":"save count to flow.counter","rules":[{"t":"set","p":"counter","pt":"flow","to":"count","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1170,"y":160,"wires":[[]]}]

This will bring it back to 2 decimals in HA.

So, if I understand this correctly, I would take my burn rate of .00354 (per 15 seconds) and times that by 100000 to get to 354 and then times my tank capacity by 100000, which will make it 27500000 gallons. The new gallons value would be put into the “oil counter” node along with the new burn rate of 354, I then would divide the counter number by 100000 in the “set to 2 decimal flow”.

Is that the correct logic?

You got it

count/100000

is what you would then enter in ‘set to 2 decimal’ node

1 Like

So @Mikefila, it seems I had another reset of the oil tracker during a reboot of Home Assistant. Node-Red restarted from the full tank value even though I had the latest changes you identified. When reviewing the Node-Red flow, how does the Flow know what the last value was during a restart? It only picked up the initial tank value.

Judd

Did you upgrade node-red? The current version is 8.2.1. It seems like the data does not make it through the upgrade.

The way node-red works the designation set flow ties that information to everything directly connected. flow.counter is tied to that set of connected nodes. On deploy or reset it checks the file tied to nodes for values.

Yes I did upgrade, I am on version 8.2.1.

After posting on the node red forums it’s not possible to find out exactly what happened with the current counter. Did the upgrade delete the data or was it reset from something else. :man_shrugging:

This is a new counter that will show the value as null should the data be deleted, rather than reset to the default. I added an inject node to easily restore the previous value. This is a func node so there is no gui. I already set it for your tank size and burn rate. Swap the nodes and inject the current counter value from the new inject node.

[{"id":"9a6e8332.90d2b","type":"inject","z":"ec78a76b.a0a4d","name":"Reset to number set here","props":[{"p":"topic","vt":"str"},{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"set","payload":"47230000","payloadType":"str","x":290,"y":40,"wires":[["40cecc4e.aa8684"]]},{"id":"6f0843b0.c5be9c","type":"change","z":"ec78a76b.a0a4d","name":"reset count","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":530,"y":160,"wires":[["bcf643d5.c3e278","40cecc4e.aa8684"]]},{"id":"40cecc4e.aa8684","type":"function","z":"ec78a76b.a0a4d","name":"counter","func":"var count = context.get(\"count\");\n\nif(msg.topic == \"reset\" || msg.reset == true) {\n    count = 27500000;\n} else if (msg.topic == \"set\") {\n    count = msg.payload;\n} else if (msg.topic == \"increment\" || msg.topic == \"inc\") {\n    count += 354;\n} else {\n    //assume decrement\n    count -= 354;\n}\ncontext.set(\"count\", count); //store it\nnode.status({ text: count });\n\nmsg.count = count; //pass current count in msg.count\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":855,"y":100,"wires":[["aee7a4c6.0cd6f8","c62686c3.3c9558"]],"icon":"node-red-dashboard/ui_numeric.png","l":false},{"id":"c62686c3.3c9558","type":"change","z":"ec78a76b.a0a4d","name":"set to 2 decimal","rules":[{"t":"set","p":"count","pt":"msg","to":"count/100000","tot":"jsonata"},{"t":"set","p":"count","pt":"msg","to":"$round(count, 2)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1080,"y":100,"wires":[["4f4facbf.7c9d5c"]]}]

I found a custom card that works well for the oil level.

positions:
  icon: 'off'
  indicator: inside
  name: outside
type: 'custom:bar-card'
width: 70%
style: |-
  bar-card-value {
    margin-right: auto;
    font-size: 16px;
    font-weight: bold;
    text-shadow: 2px 2px #0005;
  }
entities:
  - entity: sensor.oil_level
min: '0'
max: '550'
severity:
  - from: '0'
    to: '150'
    color: red
  - from: '151'
    to: '225'
    color: yellow
  - from: '226'
    to: '400'
    color: blue
  - from: '401'
    to: '550'
2 Likes

Can someone please put a latest solution? I am using the BMW connected apps and using the HA integration and will it to register automatically the data somewhere on HA.

Hi @123, I am trying to achieve the same thing but using an Aqara vibration sensor. So glad to see someone else had the same thought. But mine doesn’t seem to be sensitive enough to notice the jolt from the oil furnace starting, I tried different locations and nada.

I’m wondering where you placed yours? It’s probably a more modern furnace, mine was put in 1963. I use about 1800L / year on heating and warm water, and I want more data. Has your sensor been reliable over time?

I recently placed an Aqara temp / humidity sensor on top of it and the temp varies between 29ish C and 30ish C, but the range seems to be going lower as it gets colder outside, so not sure I’ll be able to use a threshold helper on this one.

I put a current sensor on the furnace AC power. When the oil burner runs it draws more than 1 amp and use that as a signal it is running. My nozzle burns 0.86 gph. Since I have data from all thermostats I’m able to prorate that 0.86gph into the different zones.