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¶m=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