Need help with Oil Tank Script

Moderator: leecollings

Post Reply
Darkgano
Posts: 1
Joined: Monday 02 October 2017 7:15
Target OS: Windows
Domoticz version:
Contact:

Need help with Oil Tank Script

Post by Darkgano »

Hello to everyone, I write from Germany.

I found the Oil Tank script on the wiki Page and I want to use it. First of all this is new to me.

I got an ESPEasy with a connected Ultrasonic Sensor. It´s name is Wasserstand with the IDX 11.
I can see the height in centimeters. But for now I have several Problems.

First of all it shows me the Value in a wrong way. It shows me the Air, because the Ultrasonic Sensor looks from up to down.
I read the Oiltank script several time, but the syntax is not clear to me.
There is an Temp option which I wont need.

I tried a little bit, but it didnt work.

Code: Select all

------------------------------------------------------------------------------
--
-- Copyright © 2015 David Woodhouse <[email protected]> and released under
-- the GNU General Public License, v2 or later.
--
--
-- Domoticz lua script to convert ultrasonic tank monitor readings into
-- percentage and volume virtual sensors for fuel tanks.
--
-- Takes input from distance sensor measuring the air above the fluid, and
-- converts to percentage and volume using the dimensions of the tank as
-- configured below.
--
-- Optionally, to prevent fluctuation as the fluid expands/contracts with
-- temperature, can convert the output values to report what the percentage
-- and volume *would* be at a fixed temperature.
--
------------------------------------------------------------------------------
--
-- Input sensors don't *have* to be virtual; mine are because they're filled in
-- by an external script running rtl_433 and receiving Watchman Sonic transmissions
--
-- Add tank temperature sensor:
-- 'http://localhost:8080/json.htm?type=createvirtualsensor&idx=1&sensortype=80'
-- Add depth sensor:
-- 'http://localhost:8080/json.htm?type=createvirtualsensor&idx=1&sensortype=13'
--
------------------------------------------------------------------------------
-- Output sensors are virtual, fed solely by this script
--
-- Add percentage sensor:
-- 'http://localhost:8080/json.htm?type=createvirtualsensor&idx=1&sensortype=2'
--
-- Add tank volume:
-- 'http://localhost:8080/json.htm?type=createvirtualsensor&idx=1&sensortype=113'
-- 'http://localhost:8080/json.htm?type=setused&idx=5&name=Oil&switchtype=2&used=true'
--
------------------------------------------------------------------------------
--
-- Update depth:
-- 'http://localhost:8080/json.htm?type=command&param=udevice&idx=3&nvalue=0&svalue=59'
--
------------------------------------------------------------------------------


-- Input devices: Temperature and air gap above fluid in tank
tank_temp_sensor = 'Oil tank temp'
depth_sensor = 'Wassertank'

-- Output devices: Percentage full, volume.
pct_sensor = 'Oil tank'
pct_sensor_id = 12
volume_sensor = 'Oil'
volume_sensor_id = 13

-- To adjust for fluid expansion
-- Report volume/percentage as they would be at 10°C
canon_temp = -10
-- Kerosene
expansion_coeff = 1.00099

-- Tank dimensions
tank_height = 180
tank_area = 90 * 400

-----------------------------------------------------------------------------------
commandArray = {}

if (devicechanged[depth_sensor] or devicechanged[tank_temp_sensor]) then
   -- Use otherdevices_svalues[] because devicechanged[foo_Utility] is not
   -- present when the value is zero
   depth = otherdevices_svalues[depth_sensor]

   -- Calculate percentage and volume
   pct = (tank_height - depth) / tank_height * 100
   volume = (tank_height - depth) * tank_area / 1000

   -- Adjust for fluid expansion
   tank_temp = otherdevices_svalues[tank_temp_sensor]
   if (tank_temp ~= nil) then
      temp_delta = tank_temp - canon_temp
      scale = math.pow(expansion_coeff, temp_delta)
      pct = pct * scale
      volume = volume * scale
   end

-- print(string.format("depth now %f; percentage %f %% volume %f l", depth, pct, volume))

   commandArray[1] = {['UpdateDevice'] = pct_sensor_id .. "|0|" .. pct}
   commandArray[2] = {['UpdateDevice'] = volume_sensor_id .. "|0|" .. volume}
end

return commandArray
I saved this file with lua extension unter scripts\lua on Windows. But nothing happens, no error or such a thing.
D3LTA
Posts: 24
Joined: Monday 15 July 2013 2:37
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8153
Location: Twente
Contact:

Re: Need help with Oil Tank Script

Post by D3LTA »

did you save it as script_time_"nameofscript".lua ?

this will make it fire every 1 minute.
zicht
Posts: 272
Joined: Sunday 11 May 2014 11:09
Target OS: Windows
Domoticz version: 2023.1+
Location: NL
Contact:

Re: Need help with Oil Tank Script

Post by zicht »

Put a couple of print() commands in your script so you can see if the script runs at all (output in the log)
You can also print the triggers to check them out.

good luck debugging
Rpi & Win x64. Using : cam's,RFXCom, LaCrosse, RFY, HuE, google, standard Lua, Tasker, Waze traveltime, NLAlert&grip2+,curtains, vacuum, audioreceiver, smart-heating&cooling + many more (= automate all repetitive simple tasks)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest