[SOLVED] Calculating Remaining Propane In a Tank

I’m look at this product which I believe does allow local connections via their API, but it is not inexpensive: http://www.tankutility.com/residential-propane-tank-monitor/

Maybe it would be a good idea to get some kind of meter and measure consumption? See here - https://community.openhab.org/t/new-binding-wireless-m-bus-techem-heat-cost-allocators. We are currently working on it and we will be able to plug wireless devices (battery powered). An obvious side effect which is necessary first - is modification of installation. But if you have a pressure meter on the tank - then you could try to read pressure and calculate remaining capacity of gas (with very low but still some accuracy).

Cheers,
Lukasz

Did you declare the variable emailSent?

I did not. I added:

var Boolean emailSent = true

now i get this:

[ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule 'Propane Remaining': Could not cast NULL to java.lang.Number; line 9, column 34, length 32

Does that mean its seeing a NULL value? Because my propane counter reset of the day an has not run. So right now usage for today is zero.

Set it with the rest api
And try again

Thanks for the tip. I have looked at Tankutility and while it appears to be a good product that does what I need, the API they offer just reads from their server.
Because of my past experiences I prefer to retain local control. While Openhab developers were able to change the binding for MyQ after they broke the binding and Insteon reverted the changes they made, Revolve was completely abandoned. I don’t want to put myself in that position again.

oh man, now you set me on the path to figure out the rest api. i was able to create this:

curl -X PUT --header "Content-Type: application/json" --header "Accept: application/json" -d "{
  \"value\": \"string\",
  \"config\": {}
}" "http://xx.x.xx.xxx:8080/rest/items/Propane_DailyUsage/metadata/30"

i tried it in the command line on the openhab server. seemed to not choke at least. but it didn’t change the value. something else i should be doing with it?

Create a setpoint in the sitemap and set it to any value

You’re going to want a means like the setpoint anyway, to manually adjust your tank level e.g. after a tanker visit

Unfortunate that TankUtility seems to have removed their local API. I’m pretty sure they had it in the past, but I don’t see it in their current documentation. I’ll have to rethink this before I purchase one. It does look fairly easy to use though.

Things started working last night as it ran just little (really needed some relief from this cold for us, its been brutal). Problem is, its counting down way fast! I didn’t have any debug on it so not sure what its doing but this morning I have -495 gallons in the tank!

Here is what I have in the latest code. I am not persisting any of this yet so not sure if that is an issue or not.

var Boolean emailSent = true

// Rule to calculate remaining propane in tank
 rule "Propane Remaining"
when   
    //Time cron  0 59 23 1/1 * ? *
	Time cron "0 * * * * ?" //for debug
then   
    PropaneRemaining.postUpdate((PropaneRemaining.state as Number) - (Propane_DailyUsage.state as Number))
    if(PropaneRemaining.state < 40) {
        sendNotification("mymail@gmail.com", "Propane is Low")
		sendMail("mymail@gmail.com", "Propane", "Propane is Low")
		emailSent=false
  }		
	else {
		emailSent=true
	}
end

Bumping this back up. Still not sure why its not calculating correctly.

The problem is with the daily usage. It must be too high
Add a log for the value before the calculation

Isn’t that running the daily rule on an hourly basis (for testing)?

1 Like

Well spotted young man!!
@boilermanc

The rule runs every hour and therefore you have taken out 24 times the amount
Change your cron string back

It is running every Minute with “0 * * * * ?”…

1 Like

Now we are getting somewhere…
I think everybody was half asleep yesterday

I would suggest to create some debug logging within this rule. there you can see how often it is running and which value is calculated…

e.g. just add the following line at the beginning of your rule (after “then”):
logInfo("propane.remaining", "Propane remaining (before):"+PropaneRemaining.state )
logInfo("propane.remaining", "Propane daily usage:"+Propane_DailyUsage.state )

and this one after the calculation:
logInfo("propane.remaining", "Propane remaining (after):"+PropaneRemaining.state )

With this Information you can check if it is calculated the right way, even when the calculation time is in the middle of the night…

oh my gosh, that cracks me up. of course. thanks for all the great feedback.

I am out of town until Friday but will pop the code in then and see what happens. wow, thanks!

Winner winner chicken dinner! Adding the logging really helped (note to self) and thanks @imhofa . Looks like its working correctly now so I set the cron job to only run once a day and was able to set the amount of propane through the dashboard!

here is the latest and greatest:

 // Rule to calculate remaining propane in tank
 
//var propane_quantity_start PropaneRemaining = 297
        
var Boolean emailSent = true
//Time cron "0 * * * * ?" //for debug
// Rule to calculate remaining propane in tank
 rule "Propane Remaining"
when   
    
	Time cron  "0 59 23 1/1 * ? *"
	
then   
	logInfo("propane.remaining", "Propane remaining (before):"+PropaneRemaining.state )
	logInfo("propane.remaining", "Propane daily usage:"+Propane_DailyUsage.state )
	PropaneRemaining.postUpdate((PropaneRemaining.state as Number) - (Propane_DailyUsage.state as Number))
	logInfo("propane.remaining", "Propane remaining (after):"+PropaneRemaining.state )
	if(PropaneRemaining.state < 40) {
        sendNotification("mymail@gmail.com", "Propane is Low")
		sendMail("mymail@gmail.com", "Propane", "Propane is Low")
		emailSent=false
  }		
	else {
		emailSent=true
	}
end

sitemap:

Setpoint item=PropaneRemaining minValue=0 maxValue=300 step=5

love it! off to the next project and as usual, thanks so much for everyones help! we got some dang cold weather coming so will be great to be able to track this over the next few days!