Water tank instant volume



  • Dear all,

    I'm really glad to read that the Mysensors 2.0 now include by default the attachment of local sensors on gateways.
    Then after one year in standby, i've started again my project to finish it.

    I'm using an Arduino Uno + Eth Wizenet 5100 and a distance sensor HC-SR04 => Domoticz as controller.

    I want to measure the instant volume in liters of my water tank and not a consumption.

    Actually I can see properly the value sent to domoticz from the sensors attached to my ethernet gateway.

    My question is regarding the type: what type shall I use to send and read simply the instant value in liters in domoticz (not as counter).
    I've found someone who did exactly what i would, but it's done with json! (see the image link below for the oil volume).
    https://www.domoticz.com/wiki/images/0/06/Oil.png

    He write that the Volume sensor is (RFXMeter type 113, subtype 2).
    I've found the pdf manual of mysensors but I only see the S_WATER with V_VOLUME type (this give me a water counter in domoticz and not an instant reading).

    How can I adapt a mysensor type (S_VOLUME_INSTANT by exemple) by my self?

    I give you my sketch to measure and convert the distance in liters and percent for my tank if it could help someone else :-).

    Tank you in advance for your help :-).

    // Enable debug prints to serial monitor
    #define MY_DEBUG 
    
    // Enable and select radio type attached
    //#define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    
    // Enable gateway ethernet module type 
    #define MY_GATEWAY_W5100
    
    // W5100 Ethernet module SPI enable (optional if using a shield/module that manages SPI_EN signal)
    //#define MY_W5100_SPI_EN 4  
    
    // Enable Soft SPI for NRF radio (note different radio wiring is required)
    // The W5100 ethernet module seems to have a hard time co-operate with 
    // radio on the same spi bus.
    #if !defined(MY_W5100_SPI_EN) && !defined(ARDUINO_ARCH_SAMD)
      #define MY_SOFTSPI
      #define MY_SOFT_SPI_SCK_PIN 14
      #define MY_SOFT_SPI_MISO_PIN 16
      #define MY_SOFT_SPI_MOSI_PIN 15
    #endif  
    
    // When W5100 is connected we have to move CE/CSN pins for NRF radio
    #ifndef MY_RF24_CE_PIN 
      #define MY_RF24_CE_PIN 5
    #endif
    #ifndef MY_RF24_CS_PIN 
      #define MY_RF24_CS_PIN 6
    #endif
    
    // Enable to UDP          
    //#define MY_USE_UDP
    
    #define MY_IP_ADDRESS 192,168,1,113   // If this is disabled, DHCP is used to retrieve address
    // Renewal period if using DHCP
    //#define MY_IP_RENEWAL_INTERVAL 60000
    // The port to keep open on node server mode / or port to contact in client mode
    #define MY_PORT 5003      
    
    // Controller ip address. Enables client mode (default is "server" mode). 
    // Also enable this if MY_USE_UDP is used and you want sensor data sent somewhere. 
    //#define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 254   
     
    // The MAC address can be anything you want but should be unique on your network.
    // Newer boards have a MAC address printed on the underside of the PCB, which you can (optionally) use.
    // Note that most of the Ardunio examples use  "DEAD BEEF FEED" for the MAC address.
    #define MY_MAC_ADDRESS 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
    
    // Flash leds on rx/tx/err
    #define MY_LEDS_BLINKING_FEATURE
    // Set blinking period
    #define MY_DEFAULT_LED_BLINK_PERIOD 300
    
    // Enable inclusion mode
    //#define MY_INCLUSION_MODE_FEATURE
    // Enable Inclusion mode button on gateway
    //#define MY_INCLUSION_BUTTON_FEATURE
    // Set inclusion mode duration (in seconds)
    //#define MY_INCLUSION_MODE_DURATION 60 
    // Digital pin used for inclusion mode button
    //#define MY_INCLUSION_MODE_BUTTON_PIN  3 
    
    // Uncomment to override default HW configurations
    //#define MY_DEFAULT_ERR_LED_PIN 7  // Error led pin
    //#define MY_DEFAULT_RX_LED_PIN  8  // Receive led pin
    //#define MY_DEFAULT_TX_LED_PIN  9  // the PCB, on board LED
    
    #include <SPI.h>
    
    #if defined(MY_USE_UDP)
      #include <EthernetUdp.h>
    #endif
    #include <Ethernet.h>
    #include <MySensors.h>
    #include <NewPing.h>
    
    #define CHILD_ID 1
    //constant for the sonar HC-SR04 sensor
    #define TRIGGER_PIN  3
    #define ECHO_PIN     2
    #define MAX_DISTANCE 350 //distance max measured
    
    //constant to calculate the volume of the tank
    #define high_water_level 200 //tank depth from the lowest point to the max water level
    #define distance_sensor 30 //distance in cm between the max water level and the sensor
    #define tank_volume 10000 //tank volume when it is fitted to the max water level
    unsigned long SLEEP_TIME = 5000; // Sleep time between reads (in milliseconds)
    
    NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
    MyMessage msg(CHILD_ID, V_VOLUME);
    int lastDist;
    bool metric = true;
    
    void setup()  
    { //present(255, 18);
      //metric = getConfig().isMetric;
    }
    
    void presentation() {
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo("Capteur Citerne", "1.0");
    
      // Register all sensors to gw (they will be created as child devices)
      present(CHILD_ID, S_WATER);
    }
    
    void loop()      
    {     
      Serial.print("Niveau d'eau ");
      Serial.print(tank_level("liters"));
      Serial.println("L");
    
    /*  if (dist != lastDist) {
          send(msg.set(dist));
          lastDist = dist;
      }
    */
      send(msg.set(tank_level("liters")));
      sleep(SLEEP_TIME);
    }
    
    //function to measure and convert the tank volume
    int tank_level(String unit)
    {
      int level_liters = 0,level_percent = 0, echo_us = 0, echo_cm = 0, water_level_cm = 0;
      echo_us = sonar.ping_median(); //return the median time of 5measures between the ping and the echo in microseconds
      echo_cm = echo_us / US_ROUNDTRIP_CM; //convert the echo time to distance in cm.
      water_level_cm = high_water_level - (echo_cm - distance_sensor);
      level_liters = water_level_cm * (tank_volume / high_water_level);
      level_percent = (water_level_cm * 100) / high_water_level;
      if (unit == "liters")
      {
        return level_liters;
      }
      else if (unit == "percent")
      {
        return level_percent;
      }
      else
      {
        return 0;
      }
    }
    
    

  • Hero Member

    @brix7be I also would be interested in a solution for this. I have a tank level node as well and at the moment I am just using S_INFO and V_TEXT to send the litres and percentage.



  • I think V_LEVEL works in domoticz the way you want. You can change the axis label and icon from UI edit button afterwards.
    You can use are S_DUST are S_VIBRATION as sensor type.. not the most describing ones for water but both are creating a "custom counter" that can be used to present the "current/instant level".

    More info can be found from the source code of domoticz 🙂
    https://github.com/domoticz/domoticz/blob/master/hardware/MySensorsBase.cpp#L861

    Perhaps someone could add handling for pair S_WATER and V_LEVEL to MySensorsBase.cpp. Should be easy 😉


  • Hero Member

    Thanks @pjr I will have a look at that.



  • Tank you @pjr and @Boots33 for your ideas and support. I'll try it as soon as I can :-). I'ill keep you informed.



  • @pjr, I've tested with S_DUST and V_LEVEL and it works :-). Tanks.
    The UI edit button is included to the domoticz frontend or it is in backend(to change the icon and the axis label)?

    You're right, it could be wonderful if someone better than me on mysensors could add it or tell us how to add a V_LEVEL attribute to the S_WATER element.

    Have a nice afternoon :-).



  • From domoticz web ui you can do that:
    0_1477638199242_domo_ui_change_axis.png



  • @brix7be said:

    The UI edit button is included to the domoticz frontend or it is in backend(to change the icon and the axis label)?

    Here you can read how to add custom icons in Domoticz
    http://www.domoticz.com/wiki/Custom_icons_for_webinterface



  • It would be nice to see how you solved the location of the sensor and the electronics.
    I may have a project at work to build exactly like this.



  • Hi,
    I had a similar setup, the Ultrasonic sensor did not last long. I used to measure the water level in overhead tank. Within a month the transducers were all rusted and the ultrasonic sensor died. I had to take everything out. I am looking for some waterproof sensors like the ones used in car park assist.

    In case you have a better solution, please do share.


  • Hero Member

    @Suresh-Mali The one I have used is waterproof, although so far it has only been in place for testing purposes I think it will last ok. If you do a search on ebay for "waterproof ultrasonic sensor" you should get some to look at. the one I have used is similar to this



  • Hello everyone,

    Sorry for my delayed answer, i'm a bit busy at work for the moment, and my baby is sick this week.

    @pjr : Thanks for you screenshot. In my version of domoticz(the last one running on w7 and soon on ubuntu server) , when i click on edit i'm only able to change the name and not the axis label like your's. An idea(something to activate) ?

    @flopp : I've placed the ultrasonic sensor with an arduino uno and an ethernet stack under the tank cover (in a little electrical box). I'm going to connect it with a utp cable, for the length possibility(2pairs for the ethernet and 2wires for the power supply). For the connection schematics you'll find all you need on the distance sensor node and ethernet gateway on the site. Ask us for info.
    @Boots33 : thanks for the your waterproof sensor link. I'll certainly change for it.

    Thank you all again for your support.
    Have a nice evenning.


  • Hero Member

    @pjr Have just tried the S_DUST/V_LEVEL solution and it works perfectly. In fact I think that combination will be good for a few of my other sensors like my lightning detector as well . Thank you for your input.

    Screen shot , you can now see that tank level both in litres and also in percentage are displayed as desired. 🙂

    0_1479013844073_water.jpg



  • @pjr Tanks a lot for your advice regarding our tank level Axis label and Icon in Domoticz.
    Since I'm using the linux version of domoticz I can change these parameters!
    Thanks again for your support.


Log in to reply
 

Suggested Topics

  • 5
  • 3
  • 2
  • 4
  • 2
  • 1

58
Online

11.4k
Users

11.1k
Topics

112.6k
Posts