Measure water tank volume with flow sensor

Post Reply
olleman
Posts: 57
Joined: Thursday 01 January 2015 19:56
Target OS: Linux
Domoticz version:
Contact:

Measure water tank volume with flow sensor

Post by olleman » Monday 18 June 2018 9:21

Hi!

I'm looking into a nice project for my boat where I'd like to monitor the volume in my water tank that holds 100l. Ideally I would like to present this as "how many litres are left in the tank" and I would also need someway to "fill" the tank virtually. Is this possible in domoticz or can anyone recommend anything else?

Edit Using an incremental counter would be a way to go but I need a way to reset it every time I "fill" the tank. I can't find any way to reset an incremental counter. Is it even doable, perhaps with LUA?

I will be sending the data from a 8266 device.

,Olle

SweetPants
Posts: 2293
Joined: Friday 12 July 2013 21:24
Target OS: Linux
Domoticz version: V4.10069
Location: The Netherlands
Contact:

Re: Measure water tank volume with flow sensor

Post by SweetPants » Monday 18 June 2018 16:05

How do you measure the water level in the tank?

If you measure it 'actively' there is no need to reset a counter
Using the HC-SR04 can give you the information, but it is not waterproof.
Ubuntu 16.04.5 LTS, Intel NUC, MySensors 2.3.0-alpha, Pro Mini 3.3/8M RFM69(HW), ESP8266 (SDK2.2.0), Sonoff, RFLink, RFXcom, MQTT, NodeRed, Domoticz Beta (from source)

olleman
Posts: 57
Joined: Thursday 01 January 2015 19:56
Target OS: Linux
Domoticz version:
Contact:

Re: Measure water tank volume with flow sensor

Post by olleman » Monday 18 June 2018 16:20

SweetPants wrote:
Monday 18 June 2018 16:05
How do you measure the water level in the tank?

If you measure it 'actively' there is no need to reset a counter
Using the HC-SR04 can give you the information, but it is not waterproof.

olleman
Posts: 57
Joined: Thursday 01 January 2015 19:56
Target OS: Linux
Domoticz version:
Contact:

Re: Measure water tank volume with flow sensor

Post by olleman » Monday 18 June 2018 21:28

SweetPants wrote:
Monday 18 June 2018 16:05
How do you measure the water level in the tank?

If you measure it 'actively' there is no need to reset a counter
Using the HC-SR04 can give you the information, but it is not waterproof.
I will meassure it by subtracting the value reported from the water flow sensor from a utillity sensor, or at least, that's what I'm aiming for.

SweetPants
Posts: 2293
Joined: Friday 12 July 2013 21:24
Target OS: Linux
Domoticz version: V4.10069
Location: The Netherlands
Contact:

Re: Measure water tank volume with flow sensor

Post by SweetPants » Monday 18 June 2018 21:34

olleman wrote:
Monday 18 June 2018 21:28
SweetPants wrote:
Monday 18 June 2018 16:05
How do you measure the water level in the tank?

If you measure it 'actively' there is no need to reset a counter
Using the HC-SR04 can give you the information, but it is not waterproof.
I will meassure it by subtracting the value reported from the water flow sensor from a utillity sensor, or at least, that's what I'm aiming for.
But then you still don't know when the water tank is full, only by manual update. You can do that with a dummy push button and using persistent data and dzVentz
Ubuntu 16.04.5 LTS, Intel NUC, MySensors 2.3.0-alpha, Pro Mini 3.3/8M RFM69(HW), ESP8266 (SDK2.2.0), Sonoff, RFLink, RFXcom, MQTT, NodeRed, Domoticz Beta (from source)

olleman
Posts: 57
Joined: Thursday 01 January 2015 19:56
Target OS: Linux
Domoticz version:
Contact:

Re: Measure water tank volume with flow sensor

Post by olleman » Tuesday 19 June 2018 12:01

SweetPants wrote:
Monday 18 June 2018 21:34
olleman wrote:
Monday 18 June 2018 21:28
SweetPants wrote:
Monday 18 June 2018 16:05
How do you measure the water level in the tank?

If you measure it 'actively' there is no need to reset a counter
Using the HC-SR04 can give you the information, but it is not waterproof.
I will meassure it by subtracting the value reported from the water flow sensor from a utillity sensor, or at least, that's what I'm aiming for.
But then you still don't know when the water tank is full, only by manual update. You can do that with a dummy push button and using persistent data and dzVentz
Sounds exactly like what I want but I have no idea howto move along with persistent data and events. Some start up help would be much appreciated:)

SweetPants
Posts: 2293
Joined: Friday 12 July 2013 21:24
Target OS: Linux
Domoticz version: V4.10069
Location: The Netherlands
Contact:

Re: Measure water tank volume with flow sensor

Post by SweetPants » Tuesday 19 June 2018 14:58

Take a look at the dzVentz wiki. https://www.domoticz.com/wiki/DzVents:_ ... _scripting it explains the use of persistent data.
Ubuntu 16.04.5 LTS, Intel NUC, MySensors 2.3.0-alpha, Pro Mini 3.3/8M RFM69(HW), ESP8266 (SDK2.2.0), Sonoff, RFLink, RFXcom, MQTT, NodeRed, Domoticz Beta (from source)

olleman
Posts: 57
Joined: Thursday 01 January 2015 19:56
Target OS: Linux
Domoticz version:
Contact:

Re: Measure water tank volume with flow sensor

Post by olleman » Wednesday 20 June 2018 7:23

Thankyou, I had a look and I'm afraid that's way out of my league to do on my own. Would anyone be interested in getting me started?

olleman
Posts: 57
Joined: Thursday 01 January 2015 19:56
Target OS: Linux
Domoticz version:
Contact:

Re: Measure water tank volume with flow sensor

Post by olleman » Thursday 21 June 2018 11:27

I've done some more research into this and I assume that this would be a way to do it (bare in mind, I have never scripted or worked with Lua before).

1. Store every reading in volume from flow sensor (the sensor wull actually report a volume counted for a specified amount of time) in a variable with a historic data table.
2. Make calculations of the sum of each value in the table and when it reaches, for example 25 litres. Set a dummy sensor with percentage to 75% To indicate that the tank now is 75% full.
3. Repeat step 2 but with 50l/50%, 75l/25% and 100l/0% (since my tank holds roughly 100l)
4. When virtual switch "filled my water tank" is switched on (will automaticly switch off again after 3 seconds). Erase all data in the table, set dummy percentage sensor to 100% and start from step 1 again.

Is this what you had in mind? I really don't know how to put all this together though...

olleman
Posts: 57
Joined: Thursday 01 January 2015 19:56
Target OS: Linux
Domoticz version:
Contact:

Re: Measure water tank volume with flow sensor

Post by olleman » Sunday 24 June 2018 8:27

After A LOT of trial and error I think I've come up with something that actually works. The code is most likely real uggly but it seems to be working. Tought I would share it.
Spoiler: show
return {
active = true,
on = {
devices = {'WaterUsage', 'Filled Watertank'}
},

data = {
vatten = { history = true, maxItems = 10000 }
},
execute = function(domoticz, sensor)
-- Lägg till WaterUsage om den varit > 0
if domoticz.devices('WaterUsage').WhActual > 0 then
domoticz.data.vatten.add(sensor.WhActual)
end
if domoticz.devices('Filled Watertank').state == 'On' then
domoticz.data.vatten.reset(sensor.WhActual)
domoticz.devices('Vattentank').updatePercentage(100)
end
-- sum
local sum = domoticz.data.vatten.sum()



--Ändra vattentankens fyllnadsgrad i % beroende på summan i historiken för WaterUsageen
if (sum > 5) and (sum < 15) then
domoticz.devices('Vattentank').updatePercentage(90)
elseif (sum > 15) and (sum < 25) then
domoticz.devices('Vattentank').updatePercentage(80)
elseif (sum > 25) and (sum < 35) then
domoticz.devices('Vattentank').updatePercentage(70)
elseif (sum > 35) and (sum < 45) then
domoticz.devices('Vattentank').updatePercentage(60)
elseif (sum > 45) and (sum < 55) then
domoticz.devices('Vattentank').updatePercentage(50)
elseif (sum > 55) and (sum < 65) then
domoticz.devices('Vattentank').updatePercentage(40)
elseif (sum > 65) and (sum < 75) then
domoticz.devices('Vattentank').updatePercentage(30)
elseif (sum > 75) and (sum < 85) then
domoticz.devices('Vattentank').updatePercentage(20)
elseif (sum > 85) and (sum < 90) then
domoticz.devices('Vattentank').updatePercentage(10)
elseif (sum >= 90) and (sum <= 90.99) then
domoticz.devices('Vattentank').updatePercentage(9)
elseif (sum >= 91) and (sum <= 91.99) then
domoticz.devices('Vattentank').updatePercentage(8)
elseif (sum >= 92) and (sum <= 92.99) then
domoticz.devices('Vattentank').updatePercentage(7)
elseif (sum >= 93) and (sum <= 93.99) then
domoticz.devices('Vattentank').updatePercentage(6)
elseif (sum >= 94) and (sum <= 94.99) then
domoticz.devices('Vattentank').updatePercentage(5)
elseif (sum >= 95) and (sum <= 95.99) then
domoticz.devices('Vattentank').updatePercentage(4)
elseif (sum >= 96) and (sum <= 96.99) then
domoticz.devices('Vattentank').updatePercentage(3)
elseif (sum >= 97) and (sum <= 97.99) then
domoticz.devices('Vattentank').updatePercentage(2)
elseif (sum >= 98) and (sum <= 98.99) then
domoticz.devices('Vattentank').updatePercentage(1)
elseif (sum >= 99) then
domoticz.devices('Vattentank').updatePercentage(0)




end

end
}

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest